Showing posts with label IDAT102. Show all posts
Showing posts with label IDAT102. Show all posts

Monday, 19 April 2010

Processing Sketch - Evaluating

Overall I must say that I am mostly pleased with my sketch. Despite me not having the skill set to write the code for some things I wanted to implement I still managed to get a half decent looking processing sketch.

I am most pleased that I managed to get it to read the XML and then put the data into floats for me to use because this was a part I thought I would struggle with but once I found the correct code this was not that difficult. Another bit I am pleased with is that the balls bounce around all over the stage as originally I struggled to get them to do anything but bounce from the left to the right.

Things I am not too happy about is that I was not able to get the balls to bounce off eachother, it seems that collision detection is more than a bitch in processing than in flash! Also I was a bit upset, but not overly, that I was not able to use XML data to determine how many balls appeared on stage. This was purely because I had no idea what code to write that would achieve this. However I think 8 balls are more than enough for this sketch. Also some may say that its a little bland looking which I can understand as I am not too happy about the white background but there is little I could do really because white truely is the best colour to display things.

So to summarise, I am happy with this because despite enjoying processing I did find some parts difficult and also was not able to get some parts of my idea to work. But overall I am pleased with my sketch and I believe that it is far more interesting to look at than the ArchOS feed!

Sunday, 18 April 2010

Processing Sketch - Final Touches

Now that I had the code that would get the data I wanted and the code for the balls I had to do was setup the draw function and create the balls. Unfortunately I could not work out a way to get the balls to bounce off one another and neither could I find out how to use a number to generate objects randomly so I had to create the balls manually as such:

ball1 = new Ball(LT1_Hum);
ball2 = new Ball(LT1_Temp);
ball3 = new Ball(LT2_Hum);
ball4 = new Ball(LT2_Temp);
ball5 = new Ball(LT3_Hum);
ball6 = new Ball(LT3_Temp);
ball7 = new Ball(AtriumA3rd_Temp);
ball8 = new Ball(AtriumA5th_Temp);


And once that was done I entered the float name into the brackets and if you remember from an earlier post the number in the brackets would be the radius.

And here is my draw function that displays the balls:

void draw() {
background(255);
ball1.move();
ball2.move();
ball3.move();
ball4.move();
ball5.move();
ball6.move();
ball7.move();
ball8.move();
ball1.display();
ball2.display();
ball3.display();
ball4.display();
ball5.display();
ball6.display();
ball7.display();
ball8.display();
}


That is it, that is how my processing sketch was made. I will evaluate it properly at some point in the future.

Friday, 16 April 2010

Processing Sketch - Getting The Data

Now that my balls were practically finished I thought I would get onto writing the code that would collect the data I was going to use.

First of all I setup the floats that I was going to use:

float outsidetemperature;
float windspeed;
float windvane;
float humidity;
float LT1_Hum;
float LT1_Temp;
float LT2_Hum;
float LT2_Temp;
float LT3_Hum;
float LT3_Temp;
float AtriumA3rd_Temp;
float AtriumA5th_Temp;


I will state later on why I chose these particular bits of data.

Then I wrote these lines of code to get the numbers that I wanted.

outsidetemperature = float(description[21].getContent());
windspeed = float(description[37].getContent());
windvane = float(description[36].getContent());
humidity = float(description[20].getContent());
LT1_Hum = float(description[14].getContent());
LT1_Temp = float(description[15].getContent());
LT2_Hum = float(description[16].getContent());
LT2_Temp = float(description[17].getContent());
LT3_Hum = float(description[18].getContent());
LT3_Temp = float(description[19].getContent());
AtriumA3rd_Temp = float(description[23].getContent());
AtriumA5th_Temp = float(description[24].getContent());


I worked out that the XML feed was sort of like an array and thus by entering a number between the square brackets I could select what data I wanted using getContent. Now these were stored into the variables all I would have to do is type the float name and that number would be used.

Processing Sketch - The Bouncing Balls

Now that I have written the code that will read the XML I thought I would make a start on the balls which will appear in my sketch. I opened up a brand new tab and wrote the code to get the balls to bounce off the walls. I decided to leave the complicated collision detection stuff until later.

class Ball {

float r; //this is the circle's radius
float x,y;
float xspeed,yspeed;
color c;

Ball(float tempR) {
r = tempR;
x = random(width);
y = random(height);
xspeed = random( -5,5);
yspeed = random( -5,5);
}

void move() {
x += xspeed;
y += yspeed;

if (x > width || x < 0) {
xspeed *= - 1;
}

if (y > height || y < 0) {
yspeed *= - 1;

void display() {
stroke(0);
fill(c);
ellipse(x,y,r*2,r*2);
c = color(100,50);//using a basic grey colour for now


This code creates the Ball class and it sets it speed and colour (for now, later I will look to making these data from the XML feed). I have also set up for the ball to bounce of the sides of the stage.

Thursday, 15 April 2010

Processing Sketch - The Start

I have chosen to go with the bouncing balls idea and have just started work on it today. First off I have written my code that will read the XML data I will need and the setup.

import processing.xml.*;

XMLElement xml;
XMLElement[] title;
XMLElement[] pubDate;
XMLElement[] description;

void setup()
{
size(500,500);
background(255);
smooth();
frameRate(60);
String url = "http://arch-os.scce.plymouth.ac.uk/bms_data.rss";
XMLElement xml = new XMLElement(this, url);
title = xml.getChildren("channel/item/title");
pubDate = xml.getChildren("channel/item/pubDate");
description = xml.getChildren("channel/item/description");


And thats all for today folks. In the next view posts I will describe the process in making my sketch.

Processing Sketch - First Thoughts

Ah processing I was actually enjoying it during the sessions but now theres an assignment I think may begin to hate it. As always with assignments I go through the initial ideas stage. However it seems that I am stuck for ideas with this one. Currently I've only got these 2 ideas:

Bouncing Balls: I will have balls bouncing off the sides of the stage and off eachother changing colour and/or size based on the XML data. I will also hopefully be able to use some data to determine how many balls appear on the stage at one time.

Falling Objects: There will be objects falling from the top of the stage and falling through the bottom. Again I would use the data to change the colour/size and also determin how many objects appear.

I will post again soon stating which idea I have chosen or if I come up with a better one! (highly unlikely)

Monday, 1 February 2010

Flash Game: The Mentions

As I did with the website assignment this is the post where I do all the mentions and thankings.

First of all thanks to Chris Saunders for teaching me Actionscript and giving me examples of code I used in my final game.

Thanks also to Jon again for helping me out in times of difficulty.

Another small mention to Simon for once again being up at the same time as me and its also his birthday today.

And finally gotta mention itunes for playing music when I needed it most. You'll be surprised how useful Blur's Song 2 coming on through the shuffle can motivate you to work.

Flash Game: The Evaluation

So my game is finished but of course like every project it is always good to evaluate it.

Overall I am very pleased with the final outcome of my flash game as I have never touched actionscript to create a game from scratch before. I am most pleased with the way I have managed to get the car to move like a real car as this was rather difficult and I did have to look at a few examples to help me on my way. I am also pleased with getting my outside element with the time working as this proved to be tricky whilst attempting it also. Finally I am pleased with most of collision detection code such as going off the track as this was a vital part of my game.

However, with most things, there are parts I was not so happy with. As I said just the sentence before I was happy with most of my collision detection. I was less happy with my "mud patches" and "barrels". First of all I wanted my mud to be funny shaped and barrels to be round however using the hitTestObject code this was not possible as they were treated as rectangles anyway so I ended up just making them rectangles. Also sometimes the car is effected by collision detection despite it not being near the object so I am less happy with this. The other thing I was not so happy about, yet not so bothered about, is the shape of my car. It is just a rounded rectangle as my drawing skills are not very good at all. I would have prefered if each end of the car was easy to spot. However I am not all that bothered about it because as soon as the user presses a button they know which end is which.

So things I would improve if I had more time/had to do this type of game again. As mentioned in my research post I would have liked to have a random block spawning feature so thet track changes each time. Although time did not allow this it is something I would like to add in the future if I develop this game further. Also my idea of having the track darker with floodlights did not really happen as I was short of time and skill to get it working properly.
Other improvements include going into deeper detail with collision detection to see if I could get it working perfectly without a hitch. I would have the car bounce off the barrels better than just making the speed = the opposite direction. I would also edit my car so that each end was easily detectable. Another improvement I would make would be to have a better way to stop people cheating by reversing over the line. My current way is OK but not the best as it is probably possible to get a quicker time by turning around. However after much testing this takes a lot of practice so i'm hoping users would just go around the honest way to have a better game experience. Especially as this is the casual gamer playing this game anyway.

To quote David Beckham, at the end of the day, I am very pleased with my flash game. The positives, for me, out-weigh the negatives and improvements. Therefore I see this project as a success and must admit I think I have achieved the aim I set myself. This was to have the game have a sort of addictive quality to it and just playing it by myself I believe I was addicted (before I got the best score anyone can possibly get, I am the creater afterall!) and I think others will feel the same. I can only hope people have as much fun playing it as I did making it, for the most part anyway!

Flash Game: Sounds and that annoying outside element!

So as the title says I will discussing my sounds and how I got them working. I decided that my sounds HAD to be car and driving based and what 2 better sounds could I get than Jessica by the Allman Brothers (or as its better known the Top Gear theme) and The Chain by Fleetwood Mac (or as its better known the formula 1 theme - not sure if its the old or current but oh well).
So after gaining these mp3 files I set about coding getting them to play.

var snd:Sound = new Sound();
snd.load(new URLRequest("TheChainSample.mp3"));
var channel:SoundChannel = new SoundChannel();

channel = snd.play();

function playGame(event:MouseEvent){
gotoAndPlay(3);
channel.stop();
}


The code you can see is from my intro frame. It calls the sound file (snd.load) and then places it into the var channel. I then tell the channel to play but stop once the user clicks the play button. The reason being that I want a new sound to play during the game itself.

var snd2:Sound = new Sound();
snd2.load(new URLRequest("JessicaSample.mp3"));
var channel2:SoundChannel = new SoundChannel();

channel2 = snd2.play();

channel2.stop();


This is the code used on my actual game frame. Once again I call the file (snd2.load) and place it into a var (this time channel2) and I then tell it to play (snd2.play). I had to add the 2's on the end of snd and channel otherwise it would play the sound from the intro screen again. The stop code you saw previously in this post. I tell the sound to stop once the player returns to the splash screen.


Now I will go onto the external element part of the brief that we had to include. I decided to keep it simple and to change the background depending on what hour of the day it was. If it was an odd number the background of my track would be brown however if it was an even number the background would remain green. I did it as so:

var currentDate:Date = new Date();
trace(currentDate.getHours());

I called the current date and used it to get the current hour of the day.

I then created a function and within it typed:
function changeBackground(evt:Event):void
{
if ((currentDate.getHours() == 1)||(currentDate.getHours() == 3)||(currentDate.getHours() == 5)||(currentDate.getHours() == 7)||(currentDate.getHours() == 9)||(currentDate.getHours() == 11)||(currentDate.getHours() == 13)||(currentDate.getHours() == 15)||(currentDate.getHours() == 17)||(currentDate.getHours() == 19)||(currentDate.getHours() == 21)||(currentDate.getHours() == 23)){
mc_newBG.x = 400;
mc_newBG.y = 400;
mc_newinsideBG.x = 76.40
mc_newinsideBG.y = 90.95
}
}

Unfortunately the block quote ruins the lay out. Basically I created two off screen brown objects and moved them inscreen whenever the current hour was 1,3,5,7,9,11,13,15,17,19,21 or 23. The inside of the track was difficult to do. I had to set the registration to the top left corner, grabbed the co-ordinates of my inside track rectangle and then set the brown rectangle to move into the exact same space.

And that my friends is my flash game finished! All thats left for you to do is to go and play it which you can do so HERE. Goodbye for now.

Flash Game: Collision Detection is back :( but intro screens yay!

Yes thats right ugly collision detection is back however because I tamed it before this time it was pretty straight forward! As I mentioned earlier I created obstacles on my course so to get them working it was time to delve into actionscript again.

Here is a sample of the code I used for my barrels:

if (mc_car.hitTestObject(mc_barrel1)){
speed = -2
}


and here is a sample for my "mud patches"

if (mc_car.hitTestObject(mc_mudpatch1)){
speed = speed/1.5
}


As you can see the mud patches work very much the same as the offtrack rectangles by giving the car a significant speed reduction. The barrels work differently. I made the speed - 2 which makes the car go in reverse to give the impression that it has rebounded back off a barral.

I also used some more collision detection to stop people simple reversing over the finishing line and winning. I drew a small line and assigned this code to it:

if (mc_car.hitTestObject(mc_stopcheats)){
speed = 2
}


Basically if they pressed reverse as soon as they hit the line the speed would change to 2 which would send them forwards to once again give that bounce effect. Of course whats to stop them turning around and doing it? Well ive worked out it would actually be quicker for them to complete the lap rather then do that so it all works out well!

Right! Now that the game was actually finished (bar a major part of the brief which I will go into in a later post) I could add finishing touches such as intro screens.
To create these i simply just added new frames before my main game frame. I decided I wanted an intro screen and a screen that I used for instructions.

Below are screenshots of the 2 screens I created:





On these I used small amounts of actionscript. This was purely so I could get buttons to work the way I wanted. Aswell as a small part of sound that I will go into later. Below are the bits of code I used:

btn_play.addEventListener(MouseEvent.MOUSE_UP,playGame);
btn_instructions.addEventListener(MouseEvent.MOUSE_UP,instructions);

function playGame(event:MouseEvent){
gotoAndPlay(3);
channel.stop();
}
function instructions(event:MouseEvent){
gotoAndPlay(2);
}


The bits above are from my intro screen. They add mouse click events so that my buttons work. The gotoAndPlay bits take the user to the frame that I want them to go to. The instructions screen is very much the same minus the code for the button to take them to the instructions obviously!

Right that is collision detection part 2 and the intro screens explained please tune into the next post for more write up of my flash game!

Flash Game: The Timer and The Finishing Line

So the timer. The thing which my game style circles around because it times how fast people complete the track. Below is the code I used to get it working:

var myTimer:Timer = new Timer(1000);

myTimer.start();
function laptime(event:TimerEvent):void
{
timerTxt.text = String(myTimer.currentCount);
}


I would use other lines of code to stop and reset it at a later date.

Now onto the finish line. The idea for this was that the user would complete the track and then the finishing stages of the game would occur. This means that collision detection needed to come back again so that when the car hit the finishing line all of these finishing stages would occur. I will let the code I used do the talking here and I will explain after:

function finishline(evt:Event):void
{
if (mc_car.hitTestObject(mc_finishline)){
mctheEnd.x = 139;
mctheEnd.y = 138;
mctheEnd.text = "Congratulations your Lap Time was: \n" + myTimer.currentCount + " seconds";
mc_lighten.x = 200;
mc_lighten.y = 200;
mc_lighten.alpha = 0.95;
myTimer.stop();
btn_playagain.x = 273;
btn_playagain.y = 270;
mc_car.visible = false;
channel2.stop();
}
}


So the first thing I wanted was for some text to appear. To do this I created a text box off screen and then once the car hit the point it would be moved on screen. I created a dynamic text box. This would also allow me to state what text would appear which is the next line of my code. I got it to show the current point on my timer along with a congratulations message.
The next part of my code is mc_lighten. This was a white box that I again had off screen and moved on screen. The purpose of this was to lighten (hence the name) the game in the background so that the message would be easier to read. The change the opacity of this white box i used the .alpha code and set it to 0.95 opacity.
The next line is pretty much self explanatory even to those who do not understand actionscript! I basically stop the timer so that it doesn't continue going up and that the final time can be displayed in my message as mentioned above.
I then created a play again button and again moved that on screen from offscreen this is so the user can play the course again to try and beat their score.
Next I decided I would change the car's visibilty to 0 so that the user wouldn't be able to tell that they can move the car once they've finished the track. This was not really needed but I felt the need to do it anyway.
The final bit of code is to stop a sound playing which I will mention in a later post.

And so thats it for the timer and the finishing line. The next post will be all about how I got my obstacles working and the splash screens I created to go with the game.

Flash Game: Collision Detection, what a bastard!

Yes the title states my feelings towards collision detection because it claimed about 20 hours of my life (only a slight exaggeration). I originally had it detecting a sort of wall around my track but I realised after ages that this would not work. So I set about lining my track with reectangles around the outside and using these few lines of code within my collision function over and over:

if (mc_car.hitTestObject(mc_topboundary)){
speed = speed/1.5
}


And here is an image showing my rectangles I used (they're the objects with blue outlines):



And now if my car went over the edge of the track it would be hit with a severe speed penalty and would not be able to travel anywhere any fast. This was mainly to stop cheats driving down the middle of my track.

Next I will describe perhaps the 2nd most important part of my game, the timer!

The beginnings of my flash game

So onto the beginning of my flash game. First of all I had to draw what I was going to need which would be a track and definitely a car. I also drew some obstacles that I would code later on aswell as a dynamic text box to become my timer. All of these were given their own layer. E.g. obstacles, timer, car, track etc.



Now that it was all drawn I could begin coding so I created my Actionscript layer. I decided that first I would code my car, however it wouldn't be easy as I wanted it to move exactly like a car rather then a dot along a road.
This proved to be incredibly tricky needing lots of vars and functions howwever I finally got it to work with gradual acceleration, stearing and reversing. This is my proudest achievement in actionscript to date. Below are all the vars I used for this part of my code:
var speed = 0;
var acceleration = 0.2;
var maxSpeed = 10;
var maxReverse = -5
var carRotation
var leftPressed
var rightPressed
var upPressed
var downPressed
var friction = 0.85
var rotationSpeed = 12


I decided it would be easier to create vars stating that a button is pressed and then creating a function using that var then to just simply have the key code scripting. Below is an example of what I did:

if ( event.keyCode == 37){
leftPressed = true;
}

if (leftPressed){
mc_car.rotation -= carRotation;
}


Thats all for now my next post will be about me conquering collision detection.

Friday, 29 January 2010

Flash Game Ideas

So ideas then. In my last post I decided something short and sweet was best for the casual gamer but that I also wanted to attempt to make it addictive. I also have to keep to the brief set so it must include a timer or score system and must be influenced by an outside source. The final thing I had to consider was how far my limited flash knowledge could take me.

I first decided that I would use the time of day as my outside data and that the background would change in my game if it was after and before a certain time of day.

My first idea was to make a maze type game where the user would have to guide a circle through a maze. However I decided against this because i figured it would not be that fun to play over and over and also I thought many of my fellow students would do something similar.

The next idea I came up with was one to do with football because EVERYONE loves football! So I first decided a keep ups game however realised that would become too difficult for me to do and so left that asside for a outside of uni project to work on at a later date. Next I thought penalty shootout however again my limited flash skills canceled this out and thus because another out of uni project that i'd like to do. Also i'm english so penalty shootouts are not my speciality.

My final idea, of which I am now going with, is a car game. I will make a simple track of which a car will go around. I will use a timer so the aim of the game is for the user to get around the track as quick as possible. I thought this would become very addictive as the user would think "oh I can beat that time surely!" and thus play again and again. I also knew that my flash skills could make this work. I will have a hit detection so that the user can't cheat. I would like to add an extra element of randomly spawning blocks so the track is different each time however this will be done last as i'm unsure if I could get that to work. My outside element, as stated before, will be the time of day. After say 6.30pm my track will be darker and have floodlights on, hopefully!

So here goes in making my flash game! (I've actually already started it but I want these blog posts to look like they have been done with at least a few days gap.)

Flash Game Research

Yes there has been a slight issue with blog posts recently but I hope to rectify this over the next few days as i document my flash game making which should've started earlier.

I will start off with my research which was actually just playing flash games, best research i've EVER done. So I set off around the many many flash game websites that exist looking for what type of games were best for the casual gamer types.

My Results and Conclusion: I discovered the best type of game for the casual gamer is one that they can just dip in and out of. Something short and sweet. However because its over so quickly they can become addicted to it and hopefully come back to it over and over again. This is what i hope to achieve with my flash game.

Friday, 20 November 2009

Website Part VI: Star Wars had 6 episodes, so can I!

But this is not just a random post so I can copy star wars. This is the post where I do all the mentions and thankings.

First of all thanks to Chris Saunders for teaching CSS, Javascript, other HTML and helping with the corners.

Thanks also to Jon Redwood for helping me out a fair bit.

Cannot forget to mention how useful these websites were:
http://validator.w3.org/
http://jigsaw.w3.org/css-validator/

A small mention to Simon for being up with me as we were both finishing off.

And finally a mention to Radio 1 for being the background noise to me tying up all of the loose ends.

Website Part V: The Evaluation and Other Stuff

Well this the summary post. If you look HERE you will see my original design and if you click HERE you will see the final version. As you can see there are not many differences but I am going to outline those few differences and explaint them. The final website is a much darker green than my simple design. This is because I thought the green I used for the design was too bright for my liking. The other reason for the change is because, well, I sort of forgot what green I had originaly used but I now do prefer the green I went with.
As you can see I scrapped the "title of the page the user is on" thing going underneath the banner. This was because I figured it would be more practical to just use a title on the page to display this rather then big letters underneath a banner. Finally the curves on my corners are a lot bigger than those on the design, thats because I was able to get better curves when I got to the final website. Below is the CSS I used to create my curved corners.

#topbar {
background-image:url(banner.gif);
width: 100%;
height: 150px;
background-repeat: no-repeat;
}
#footer {
background-image:url(bottombar.gif);
width: 100%;
height: 50px;
background-repeat: no-repeat;
text-align:center;
font-size:12px;
}


Now I will go onto the rest of my CSS. For the final website I used several CSS files instead of just one. I did this because I found it was easier to style each page that way especially as the contact page is so different to the other two. The reason I did seperate ones for the index and about page is simple. In the CSS file I used "auto" and when it came to the height on the index, because there was not a lot of content, it would shorten it to a very short length. I did not want a short height for my index and I wanted it to be slightly similar to the other two, longer pages. Therefore I just duplicated my CSS file and made the small change.

Right next would be the javascript. In This Post you can see the code for my form validation. I am very proud I got this to work because validation is important and alert windows make this easier. My code works by looking at the fields one by one, starting at the beginning. For example if the "Name" box was empty an alert message would appear. If it was filled then the validation would jump down to the "Email" box to check if that is filled. If that is filled then it would then check to see if the Email Address entered is valid. It does this by checking for an @ sign beyond the first character and then a . beyond the second character. If that is all good then it finally jumps down to the "Message" box and if that is filled then the form will be submitted.
However that is not the only javascript I used on my website. There is another bit.

function leaveConfirm() {
if (confirm("Clicking this link will direct you away from my website. \n\nDo you still wish to continue to my blog?")) {
window.location.href = "http://tomsaundersmpt.blogspot.com/";
}
return false;
}


This makes a pop up box appear asking the user if they are sure they want to visit my blog. This works after the user has clicked the blog button and that is when the alert appears. If the user clicks OK then they proceed to my blog however, if they click Cancel, the process will be cancelled and the user will be returned to the page they were just on. Thats about it for javascript, now onto what I think about the website.

Well to say I am proud is an understatement. This is my very first website that is officially on the internet! I am very happy to see it there. First all I believe that the best designs of things are those that are kept simple and I believe my website is as simple as it gets. It is a single coloured rounded rectangle with a few links, text and images on. I would have definitely liked to make it a bit more colourful and have more going on but I am happy with the simplicity of the design, as the saying goes, I believe it is "Simple yet Effective". I am also proud of my buttons I created allowing people to link up with me on Social Networking Sites. These were done simply in Photoshop with logos gotten off the internet. Usually I would not be proud of simple buttons but this is because I made them myself. I am of course proud of my Javascript, it took ages to complete but it all works a charm now. I love the fact I got my curved corners eventually. They took a lot of time but they are done and make the site look better than it would with square ones, I think so anyway. And finally I am pleased that my CSS turned out ok and everything works.
Of course there are some things I am not so happy with and if I had left more time I would have certainly implemented on my website. I would have liked to have made a more complicated form with more than three fields but I am content with it for now. I would have liked to done something more with more images like create a small gallary that uses Javascript. Finally I also would have liked to have added more content and to make the current content a little less predictable and standard.

However at the end of the day I am very proud with what I have achieved, hope everyone likes it. All thats left to do at the end of this monster post is post a link and advertise!

CLICK HERE

Enjoy!

Website Part IV: Well how about that, its done

Yes thats right the website is finished, completed, done and dusted. Today I polished off the content of my blog and then went through the validator websites. Everything passes with flying colours, however the only colour that matters is the green of the validator saying all is good. To show that my site passes all of this I have used the code provided to put the buttons onto my website. I wanted to put them into the footer but for some reason that was not liked so to save time and hassle I smacked them straight into the home page. This turns out to be a good thing because everyone will see them instantly as they arrive at my webpage. I am so glad to have this all finished, all the heartache of looking at the Firefox Error Console and seeing errors was worth it in the end.

Now to just do a final write-up-esque post on my blog which you will see above this one shortly.

Wednesday, 18 November 2009

Website Part III: The Taming of the Javascript

So today was a very very happy day. I continued with javascript and after a lot of persistance it all worked. Here it is below.

function validate_form(){
if (document.contactform.name.value == "" ){
alert ( "Please enter your Name." );
return validate_name = false;
}else{
validate_name = true;
}
if (document.contactform.email.value == ""){
alert ( "Please enter your Email Address.");
return validate_email=false;
}else{
validate_email=true;
}
if ((document.contactform.email.value.indexOf(".") > 2) && (document.contactform.email.value.indexOf("@") > 0)){
validate_validemail=true;
}else{
alert ( "Please enter a valid Email Address." );
return validate_validemail=false;
}
if (document.contactform.message.value == "" ){
alert ( "Please enter your Message." );
return validate_message = false;
}else{
validate_message = true;
}
}


This is only my validation javascript. All of these but 1 controls whether the box is empty or not and if it is a small alert box appears telling them to fill it in. The only different bit of code is the email validation one which can tell whether the email address is valid or not. It checks to see if there is an @ sign within the email and if there is a . (because there should be like.co.uk or .com). This will then hopefully make sure the email address I recieve is at least valid and possibly real (I do understand that fake email addresses can be typed in but to code that is currently out of my skill set).

Well thats all I achieved today but hopefully you understand that this is a very very big thing and it took me 6+ hours to get to work. But it now does and I am every so happy. Time for bed cheerio!

Website Part II: It has all began

I actually made a start on my website a long time ago but I am still yet to get used to this "blog everytime you do something" thing. But tonight I figured I really should blog what I have done so far and what I have achieved recently.
So a couple of weeks ago I made the basic backbone of my website. I created a menu system with mouseovers and sorted out the main colour scheme for my website. If you check the first website related post you will see my original design and I pretty much stuck to that for this first part. I also attempted curved corners but I failed pretty badly. Since, at the time of writing, I am yet to upload what I have done recently you can still see the very first steps my website has taken on the URL Here.
So on to what I have done recently. After some advice from Chris I managed to tame curved corners and they now feature on my website which pleased me greatly as I really do hate square corners, they're too sharp.
I also implemented an idea that I came up with recently which was to use javascript to make an alert box appear when someone clicked on my blog link. This alert box would warn the user that they are moving away from my webpage. This is mainly so that the user knows it is going to happen and they can stop it if they want to rather then being taken straight to the blog without any clue what is going to happen.
I also made a start on my form validation which I must say did not start well but I am hoping I will be finally completing this very soon.
The future plans for my website are to obviously put content onto it. I would also like to implement a sort of gallery for images rather then just plastering them all over a page. I do want to add some facebook stuff too however this will most likely be the most basic available because I struggled with the more complicated stuff in the practical.

Anyway time for bed, the next post will most likely be a progress update on how tomorrows work goes. Heres hoping it's all good :).