PDA

View Full Version : [AS3] ending a game


samHTFC
05-11-2011, 07:36 PM
hey clever people,

really could do with help tonight

i have a game where you have to shoot bottles off a shelf in 20 seconds

when the time runs out the game over screen appears and you can restart the game.

just wondered how i can do a well done screen if all the bottles are shot

here is the file

cs4: www dot mediafire dot com/?r6p9nfz4m42af7e
cs5: www dot mediafire dot com/?7vu5fx2j27u76cr

jooniya
05-11-2011, 07:46 PM
I can't/didn't look at your file, but you can keep track of the number of bottles that have been shot and then if that number is equal to the total number of bottles you can go to a "Well Done!" screen. Basically, when the timer runs out, have an if statement to check and then either go to the well done screen or go to the restart screen.

samHTFC
05-11-2011, 07:57 PM
yeah i reckon id have like 20 if statements, might be an easier way, not end of the world if i cant do it, need to hand in tomorrow though

jooniya
05-11-2011, 08:21 PM
No. you would just have one if-else statement when the timer expires that would look something like this:


if( hitBottlesTotal == 20 )
gotoAndStop('wellDone');
else
gotoAndStop('restart');

poltuda
05-11-2011, 08:32 PM
import flash.events.Event;
stop()
for(var i=1;i<=18;i++){
this["glass"+i].addEventListener(MouseEvent.CLICK,smash);
}
function smash(e:Event): void{
e.target.gotoAndPlay(2);
}

Make your code less....

poltuda

samHTFC
05-11-2011, 08:38 PM
import flash.events.Event;
stop()
for(var i=1;i<=18;i++){
this["glass"+i].addEventListener(MouseEvent.CLICK,smash);
}
function smash(e:Event): void{
e.target.gotoAndPlay(2);
}

Make your code less....

poltuda

thanks poltuda, any idea on how to goto frame 3 when all bottles have been hit?

rocskyline
05-11-2011, 08:45 PM
I was bored and reinvented your game to be more dynamic.

You should always code your games this way, so you don't have to rely on the timeline. CLICK HERE (http://www.mediafire.com/?40nxr4k46q7135b) to download it.

Hope this helps and saves you time.

samHTFC
05-11-2011, 08:47 PM
I was bored and reinvented your game to be more dynamic.

You should always code your games this way, so you don't have to rely on the timeline. to download it.

Hope this helps and saves you time.

thanks, not used to timeline based coding, been using a program called processing, its basically notepad with a compiler. i'll take a look now, mucho gracias

samHTFC
05-11-2011, 08:50 PM
oh man you utter legend, dunno if my teacher will believe ive done this though haha

rocskyline
05-11-2011, 09:14 PM
Don't know if its relevant but I forgot to add countBottles=0; to the doGameLoop function.

poltuda
05-11-2011, 09:27 PM
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;

stop();
var repeat=20;
var arr:Array=new Array();
var myTimer:Timer=new Timer(1000,repeat);
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE , completeHandler);
myTimer.start();
for (var i=1; i<=18; i++) {
this["glass"+i].addEventListener(MouseEvent.CLICK,smash);
}
function smash(e:Event):void {
e.target.gotoAndPlay(2);
arr.push(e.target);
trace(arr.length);
}
function completeHandler(event:TimerEvent):void {
if (arr.length==18) {
count.gotoAndStop("gameOver");
myTimer.stop();
}else{
trace("You Loose");
}
}
function timerHandler(event:TimerEvent):void {
repeat--;
count.gotoAndStop("cnt"+repeat);
trace(repeat);
if (arr.length==18) {
count.gotoAndStop("gameOver");
myTimer.stop();
}
}




poltuda