View Full Version : setting a time limit on game?
ScottSonnenberg
March 21st, 2004, 07:08 PM
I am making a simple shooting game and have a couple questions. I have all ready done some tutorials and have a basic game done.
1. How do I set a time limit / count down timer?
2. I have done the tut on sitepoint.com, and the problem is each targets show up once, you make your way through the game by taking them out, then its over. I want to know how to make target show up for a couple seconds then be gone. For example, a guy will peek out from behind a crate stand there for 2 seconds, the duck back down.
So basically I want to do a game that last for about a minute. There are four places that guys can jump out from. They peek out for about 2 or 3 seconds then duck back behind. While they are visible, you can shoot them by using the mouse.
I know that this game has been made a million times, but I am new to making flash games and fiqure it is a good place to start.
Thank You
REEF·
March 21st, 2004, 08:06 PM
#1 -
var gameTimer = 60;
function countDown () {
gameTimer--;
if (gameTimer <= 0) {
gotoAndPlay ("youLost");
}
setInterval (countDown, 1000);
#2 - Are you using an actionscript code to make them stay/leave or are you using movieclips? If AS, let me see the code. If the targets are movieclips, just extend the frames that they stay.
Be a little more specific and post your current code.
- Sharif :)
ScottSonnenberg
March 21st, 2004, 10:24 PM
Thank you for the countdown script.
Here is the MC AS directly copy and pasted from the tut on this site
http://www.sitepoint.com/article/shoot-em-up-game-flash-mx/4
The way this game works is that there are three targets. They appear in a random order. Each is destroyed once, then the game is over. When they appear, the targets stay untill they are clicked on. I want to have the MC / targets appear then dissapear in random order for 60 seconds.
onClipEvent(mouseDown) {
hitsNeeded = 5; //hits needed to destroy target—this
//can be any number you want
//CHANGE target1.hitTest, target1Hits and activeTarget to read target2 //or target3 for other targets and target1 to read 2 or 3 as in the //array we set up.
if(_root.target1.hitTest(_root._xmouse, _root._ymouse, true) && (_root.target1Hits<hitsNeeded) && (_root.activeTarget == \\"target1\\")) {
//OK From the top on this one:
//Using the AS hitTest() method
//If the specified MC is clicked on and
//if the hits needed on this MC have not
//reached the maximum and
//*if* it is the active target (activeTarget
//CHANGE target1Hits to read target2Hits or target3Hits for other //targets
_root.target1Hits++; //increase MC hits variable by 1
_root.directHits++; //increase direct hits variable
_root.hits.text = _root.directHits+\\" of \\"+hitsNeeded+\\" needed.\\"; //display current hits for target in a text
//field on the main stage
highScore = _root.highScore;
highScore = highScore + 10; //increase high score by //however many points you //want for a hit.
_root.info.text = highScore;
_root.highScore = highScore; //update the variable on
//the main stage
//CHANGE target1Hits to target2Hits or target3Hits for other //targets
if(_root.target1Hits == hitsNeeded) { //if hits needed total
//is reached
_root.directHits = 0; //reset direct hits counter for future
//targets
//CHANGE to target2Image or target3Image for other targets
setProperty(_root.target1Image, _visible, false);
//hide target
//CHANGE to target2d or target3d for other targets
setProperty(_root.target1d, _visible, true);
//Show the target destroyed image
//Check if array is now empty
//If so, endgame
n = _root.targets.length;
if(n == 0) {
_root.gotoAndPlay(2);
}
//If it wasn't empty…
//generate a random target
n = _root.targets.length //get the current array
//length
ran = random(n); //get random number location to
//select from array
target = _root.targets[ran]; //create target variable
_root.activeTarget = target; //set active target
setProperty(\\"_root.\\"+target+\\"Image\\", _visible, true);
//show target
_root.targets.splice(ran, 1); //remove the random
//element from array
//so that target cannot
//be picked again in
//this game
_root.hits.text = \\"target destroyed!\\"; //update the
//text field
}
}
} {
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.