If you have been trying to create your own "Pong" style game, then you will want one side of the screen to cause the activity to lose a life, rather than bounce back an element. If you have followed the previous advice, you may have added the following code to a transparent sun element;
_root.car._x +=_root.h_velocity;
_root.car._y +=_root.v_velocity;
if (_root.car._x > 610 ) { _root.h_velocity = -_root.h_velocity; _root.car._x = 590;}
if (_root.car._x < 30 ) { _root.h_velocity = -_root.h_velocity; _root.car._x = 50;}
if (_root.car._y > 450 ) { _root.v_velocity = -_root.v_velocity; _root.car._y = 430;}
if (_root.car._y < 30 ) {_root.v_velocity = -_root.v_velocity; _root.car._y = 50;}
You need to decide which wall will not return the element, and alter that line. For example, if you wished to make the left side of the screen the area in which to prevent the element from reaching because it would result in losing a life, you would need to alter the line saying
if (_root.car._x < 30 ) { _root.h_velocity = -_root.h_velocity; _root.car._x = 50;}
(because this line has the condition x < 30 (ie 30 pixels from the left edge). Rather than tell the activity to bounce the ball back ( the { _root.h_velocity = -_root.h_velocity; _root.car._x = 50;} part) you need to indicate that a life should be lost and so replace the code between the { and } with
_root.looseLife(); _root.car._x = 200; _root.car._y = 200;
making the whole line of code for the left edge of the screen look like this;
if (_root.car._x < 30 ) {_root.looseLife(); _root.car._x = 200; _root.car._y = 200;}
This code removes a life from the total available, and also restarts a new life in the position given with the x and y coordinates (in this case, 200 pixles across the screen and 200 down).


Recent Comments