Example:
Click on the example above, and use the Mouse to control the Ship.
Add the following code to Scene_1.
|
onLoad () {
lives='2'; scr='0'; // Set ball speeds and directions ballspeedx = 5; ballspeedy = 10; } onEnterFrame() { // Collision Tests if (ball.hittest(left) || ball.hittest(right)) { ballspeedx *= -1; } if (ball.hittest(bottom) || ball.hittest(top) || ball.hittest(user_pal) || ball.hittest(brick) || ball.hittest(brick2)|| ball.hittest(top_pal)) { ballspeedy *= -1; } // Update stats if (ball.hittest(top)) { ball._y = 20; } if (ball.hittest(bottom)) { lives=lives-1; ball._y = 140; } if (ball.hittest(brick)) { scr=scr +++10; ball.brick_y=15*x; brick.gotoAndStop("dead"); } if (ball.hittest(brick2)) { scr=scr +++10; ball.brick2_y=15*x; brick2.gotoAndStop("dead"); } //LOOSER if (lives == "0") { nextSceneAndPlay(); } // Ball Movement ball._X += ballspeedx; ball._Y += ballspeedy; } onFrame (2) { stop(); } |
You will need the following items for the code to work.
Four boundary shapes named Top,Right, Bottom and left
Two sprites with rectangles inside named, brick and brick2.
A circle named ball and a rectangle named user_pal, And finally two dynamic text boxes one named score marked as target with the variable name of scr.
And the other named life marked as target and with a variable mane of lives.





