bibi822
10-20-2009, 05:33 AM
How can I add edit so that when the number of lives reaches 0, it will go to frame 6 for a "Game Over" screen. I thought it's
if(numberOfLives<=0) //if the user runs out of lives
{
gotoAndStop('gameover'); //go to gameover frame
}
This is the whole code
var howFarToMoveTheX:Number = 18; //this sets the x speed
var howFarToMoveTheY:Number = 18; //this sets the y speed
var numberOfLives:Number = 3;
lives.text = String(numberOfLives);
//ball function begins here
circle_ball.addEventListener(Event.ENTER_FRAME, moveBall);
function moveBall(event:Event):void
{
circle_ball.x += howFarToMoveTheX;
if (circle_ball.x >= 535) //sets the ball to the right at 550 on the x coordinates
{
howFarToMoveTheX = -howFarToMoveTheX; //you can write -7 or -howFarToMove
//trace(34343);
}
if (circle_ball.x <= 0)
{
howFarToMoveTheX = -howFarToMoveTheX;
}
// the y coordinates begin here which makes the ball move vertically
circle_ball.y += howFarToMoveTheY;
if (circle_ball.y >= 400)
{
//howFarToMoveTheY = -howFarToMoveTheY;
//LOSE A LIFE, and reset ball position
circle_ball.x = 274.50;
circle_ball.y = 164.55;
numberOfLives--;
lives.text = String(numberOfLives);
}
if (circle_ball.y <= 0)
{
howFarToMoveTheY = -howFarToMoveTheY;
}
if (circle_ball.hitTestObject(paddle_square)) //ball and paddle interaction
{
howFarToMoveTheY = -howFarToMoveTheY;
}
if(numberOfLives<=0) //if the user runs out of lives
{
gotoAndStop('gameover'); //go to gameover frame
}
}
//paddle function begins here
stage.addEventListener(MouseEvent.MOUSE_MOVE, movePaddle);
function movePaddle(event:MouseEvent):void
{
paddle_square.x = mouseX; //move the mouse on the x coordinates
Mouse.hide(); //hide the mouse arrow
}
if(numberOfLives<=0) //if the user runs out of lives
{
gotoAndStop('gameover'); //go to gameover frame
}
This is the whole code
var howFarToMoveTheX:Number = 18; //this sets the x speed
var howFarToMoveTheY:Number = 18; //this sets the y speed
var numberOfLives:Number = 3;
lives.text = String(numberOfLives);
//ball function begins here
circle_ball.addEventListener(Event.ENTER_FRAME, moveBall);
function moveBall(event:Event):void
{
circle_ball.x += howFarToMoveTheX;
if (circle_ball.x >= 535) //sets the ball to the right at 550 on the x coordinates
{
howFarToMoveTheX = -howFarToMoveTheX; //you can write -7 or -howFarToMove
//trace(34343);
}
if (circle_ball.x <= 0)
{
howFarToMoveTheX = -howFarToMoveTheX;
}
// the y coordinates begin here which makes the ball move vertically
circle_ball.y += howFarToMoveTheY;
if (circle_ball.y >= 400)
{
//howFarToMoveTheY = -howFarToMoveTheY;
//LOSE A LIFE, and reset ball position
circle_ball.x = 274.50;
circle_ball.y = 164.55;
numberOfLives--;
lives.text = String(numberOfLives);
}
if (circle_ball.y <= 0)
{
howFarToMoveTheY = -howFarToMoveTheY;
}
if (circle_ball.hitTestObject(paddle_square)) //ball and paddle interaction
{
howFarToMoveTheY = -howFarToMoveTheY;
}
if(numberOfLives<=0) //if the user runs out of lives
{
gotoAndStop('gameover'); //go to gameover frame
}
}
//paddle function begins here
stage.addEventListener(MouseEvent.MOUSE_MOVE, movePaddle);
function movePaddle(event:MouseEvent):void
{
paddle_square.x = mouseX; //move the mouse on the x coordinates
Mouse.hide(); //hide the mouse arrow
}