Thursday, 4 October 2012

Button smashing game

This basic game requires you to press a button as fast as you can for 30 seconds.

Once over it goes to an endscreen:

This is done with variables.
 
The blue circle is a movie clip called circle and any boxes where the time or score is is in a dynamic text box.
 
The whole main code looks like this:
 
 
stop(); --- Makes the frame stop on frame 2 after 0
 
var score = 0;
var time = 30; ---This sets the time to 30
circle.onPress = function (){




 score +=1; --- This sets the scor up 1 by each click
}

onEnterFrame = function (){

 if(time <1){ 
  gotoAndStop(2); ---Makes the game go to frame 2 (the 'Times up' screen) once the time hits 0
 }

}
 
 
For the timer there is a square off the screen that is a movie clip. I went into that shape (double click), set a frame to 24 (as its 2 frames per second) and in the coding I set this:
 
 
_root.time -=1
 
 
The _root. makes the coding here go to the main scene (action script). The time -=1 makes the time count down which would pass 0 and go into negatives but with the coding above it goes to frame 2 once past 0.