rulator
04-17-2009, 01:49 AM
Hi,
I'm making this game as a schoolexam and I'm almost there..but I need a "Try again" button. But I can't get it to work, you can try yourself here:
http://www-ia.hiof.no/~olavv/v09/flash/kanonspill1.swf (http://www-ia.hiof.no/%7Eolavv/v09/flash/kanonspill1.swf)
Just hold the mouse down for some seconds and release. When it stops your score gets up with a try again button that says "Prøv igjen".
I have some code for it, but I can't get it to work.
My game is all in 1 frame.
Here is the code i got, the try again button is at the end "btnRetry" "Retry"
boks.visible=false;
splash.visible=false;
btnRetry.visible=false;
function flytt(evt:MouseEvent)
{
var vinkel:Number = Math.atan2(stage.mouseY-lop.y,stage.mouseX-lop.x);
lop.rotation = (vinkel/Math.PI)*180;
figur.rotation=lop.rotation+90;
evt.updateAfterEvent();
}
stage.addEventListener(MouseEvent.MOUSE_MOVE,flytt );
function bevegelse(evt:Event)
{
figur.rotation+=0.45;
if(figur.y>lop.y)
{
stage.removeEventListener(Event.ENTER_FRAME,bevege lse);
}
}
var avstand:Number=0;
function flyttFigur(evt:Event)
{
avstand+=Math.round(figur.dx)*0.020;
trace(avstand);
txtTeller.text = avstand.toFixed(0);
if(figur.x<350)
{
figur.x+=figur.dx;
}
else
{
bakgrunn.x-=figur.dx;
if(bakgrunn.x<-bakgrunn.width+stage.stageWidth)
bakgrunn.x=-160;
lop.x-=figur.dx;
}
if(figur.y < stage.stageHeight-60)
{
figur.y+=figur.dy;
}
figur.dy+=0.09;
if(figur.dx>0.05)
{
figur.dx-=0.05;
}
else
{
figur.dx=0;
}
if(figur.dx==0)
{
txtGratulerer.text="Gratulerer, du kom:";
txtGratulerer.visible=true;
txtResultat.text=""+int(txtTeller.text);
txtResultat.visible=true;
txtMeter.text="Meter";
txtMeter.visible=true;
btnRetry.visible=true;
boks.visible=true;
}
if(figur.dx<0.5)
{
figur.visible=false;
figur.dx=0;
figur.dy=0;
splash.visible=true;
splash.x=figur.x;
splash.y=figur.y;
}
}
var startTid:int;
function fyr(evt:MouseEvent)
{
stage.addEventListener(Event.ENTER_FRAME,flyttFigu r);
var hastighet:int = (getTimer()-startTid)/250;
figur.dx= Math.cos((lop.rotation/360)*Math.PI*2)*hastighet;
figur.dy= Math.sin((lop.rotation/360)*Math.PI*2)*hastighet;
stage.removeEventListener(MouseEvent.MOUSE_MOVE,fl ytt);
stage.addEventListener(Event.ENTER_FRAME,bevegelse );
stage.removeEventListener(MouseEvent.MOUSE_UP,fyr) ;
}
function startTidtaking(evt:MouseEvent)
{
startTid=getTimer();
}
stage.addEventListener(MouseEvent.MOUSE_DOWN,start Tidtaking);
stage.addEventListener(MouseEvent.MOUSE_UP,fyr);
function retry(evt:MouseEvent)
{
avstand=0;
figur.x=lop.x;
figur.dx=lop.x;
figur.y=lop.y;
figur.dy=lop.y;
boks.visible=false;
splash.visible=false;
btnRetry.visible=false;
txtGratulerer.visible=false;
txtResultat.visible=false;
txtMeter.visible=false;
}
btnRetry.addEventListener(MouseEvent.CLICK,retry);
I'm making this game as a schoolexam and I'm almost there..but I need a "Try again" button. But I can't get it to work, you can try yourself here:
http://www-ia.hiof.no/~olavv/v09/flash/kanonspill1.swf (http://www-ia.hiof.no/%7Eolavv/v09/flash/kanonspill1.swf)
Just hold the mouse down for some seconds and release. When it stops your score gets up with a try again button that says "Prøv igjen".
I have some code for it, but I can't get it to work.
My game is all in 1 frame.
Here is the code i got, the try again button is at the end "btnRetry" "Retry"
boks.visible=false;
splash.visible=false;
btnRetry.visible=false;
function flytt(evt:MouseEvent)
{
var vinkel:Number = Math.atan2(stage.mouseY-lop.y,stage.mouseX-lop.x);
lop.rotation = (vinkel/Math.PI)*180;
figur.rotation=lop.rotation+90;
evt.updateAfterEvent();
}
stage.addEventListener(MouseEvent.MOUSE_MOVE,flytt );
function bevegelse(evt:Event)
{
figur.rotation+=0.45;
if(figur.y>lop.y)
{
stage.removeEventListener(Event.ENTER_FRAME,bevege lse);
}
}
var avstand:Number=0;
function flyttFigur(evt:Event)
{
avstand+=Math.round(figur.dx)*0.020;
trace(avstand);
txtTeller.text = avstand.toFixed(0);
if(figur.x<350)
{
figur.x+=figur.dx;
}
else
{
bakgrunn.x-=figur.dx;
if(bakgrunn.x<-bakgrunn.width+stage.stageWidth)
bakgrunn.x=-160;
lop.x-=figur.dx;
}
if(figur.y < stage.stageHeight-60)
{
figur.y+=figur.dy;
}
figur.dy+=0.09;
if(figur.dx>0.05)
{
figur.dx-=0.05;
}
else
{
figur.dx=0;
}
if(figur.dx==0)
{
txtGratulerer.text="Gratulerer, du kom:";
txtGratulerer.visible=true;
txtResultat.text=""+int(txtTeller.text);
txtResultat.visible=true;
txtMeter.text="Meter";
txtMeter.visible=true;
btnRetry.visible=true;
boks.visible=true;
}
if(figur.dx<0.5)
{
figur.visible=false;
figur.dx=0;
figur.dy=0;
splash.visible=true;
splash.x=figur.x;
splash.y=figur.y;
}
}
var startTid:int;
function fyr(evt:MouseEvent)
{
stage.addEventListener(Event.ENTER_FRAME,flyttFigu r);
var hastighet:int = (getTimer()-startTid)/250;
figur.dx= Math.cos((lop.rotation/360)*Math.PI*2)*hastighet;
figur.dy= Math.sin((lop.rotation/360)*Math.PI*2)*hastighet;
stage.removeEventListener(MouseEvent.MOUSE_MOVE,fl ytt);
stage.addEventListener(Event.ENTER_FRAME,bevegelse );
stage.removeEventListener(MouseEvent.MOUSE_UP,fyr) ;
}
function startTidtaking(evt:MouseEvent)
{
startTid=getTimer();
}
stage.addEventListener(MouseEvent.MOUSE_DOWN,start Tidtaking);
stage.addEventListener(MouseEvent.MOUSE_UP,fyr);
function retry(evt:MouseEvent)
{
avstand=0;
figur.x=lop.x;
figur.dx=lop.x;
figur.y=lop.y;
figur.dy=lop.y;
boks.visible=false;
splash.visible=false;
btnRetry.visible=false;
txtGratulerer.visible=false;
txtResultat.visible=false;
txtMeter.visible=false;
}
btnRetry.addEventListener(MouseEvent.CLICK,retry);