PDA

View Full Version : basic game problems, score board, hitTest sounds, and a big one

ninjacore
01-02-2003, 07:58 PM
ok. doing a game for uni. its a remake of the thing where u have to hit boxes with a ball, that u hit with a sliding paddle. all hunky dory so far!

what i really need to know is, how can i tell flash that ALL the BOXES have been hit, and then to move onto a "congradualtions" scene? heres a sample of my script from the beginning,...

if ((ball._x<=5) || (ball._x>495)) {
// trace("x bounce");
xStep = -xStep;
}
if ((ball._y<=5)) {
// trace("y bounce");
yStep = -yStep;
}
if (ball._y>400) {
// trace("restarting");
gotoAndPlay (5);
}
ball._x += xStep;
// trace("moving ball");
ball._y += yStep;
}
}
yStep = -10;
}
if (ball.hitTest(box)) {
sound("Smack");
box._X = 510;
box._y = 450;
yStep = -yStep;
}
if (ball.hitTest(box1)) {
box1._X = 510;
box1._y = 450;
yStep = -yStep;

x = 510 and y = 450 is where the boxes go when they are hit!

also, i need a sound to play when a box is hit!!

Any advice on a score bar would be amazing, but its not essential.

Help is VERY appreciated!!!!!!!!!!!:D :D :D :confused:

jimburton
01-03-2003, 10:44 AM
keep count of the number of bricks on screen in a counter var or array and decrement that when one is removed...when that reaches zero the player has won.

if (ball.hitTest(box)) {
sound("Smack");
box._X = 510;
box._y = 450;
yStep = -yStep;
numBricks--;
if (numBricks == 0) gotoAndStop("congrats");
}

bear in mind that hitTest is method that will slow down your movie once you get lots of them happening onEnterFrame - on slower machines this will make a game like breakout DRAG :( so consider checking whether the ball is in the right area (above/below a certain point) before doing the hitTests on the paddle or brick

jimburton
01-03-2003, 02:03 PM
ninjacore please don't pm me flash questions, post it here and then everyone can read it, comment, benefit etc etc ;)

numBricks = 16;

//( all the info for the ball and paddle is here....)

}
if (ball.hitTest(box)) {
box._X = 510;
box._y = 450;
_root.numBricks--;
yStep = -10;
}
if (ball.hitTest(box1)) {
box1._X = 510;
box1._y = 450;
_root.numBricks--;
yStep = -10;
}
if (ball.hitTest(box2)) {
box2._x = 510;
box2._y = 450;
_root.numBricks--;
yStep = -10;

at the very end i have....

if (numBricks == 0) gotoAndStop(7);

the changes are:

use one '=' to assign a variable - use two to check equality...

myVar--; means myVar = myVar-1; and is a v useful shorthand

gotoAndStop here has a number as the argument, if you put in quotes it thinks its a frame label.

numBricks should only be declared at the beginning of the game, not on every frame...your other code should happen every frame.

good luck with it,

ninjacore
01-03-2003, 02:05 PM
oh yeah, sorry about PMing. i just realised it as soon as i sent it. thansk again!!!!!!!