Something like this:

Now it's time to give'em actions. For the one in the top, type this:
onClipEvent (enterFrame) {
if (_root.ball.hitTest(this)) {
_root.ball.yspeed *= -1;
}
}
for the one in the bottom:
onClipEvent (enterFrame) {
if (_root.ball.hitTest(this)) {
_root.ball.yspeed *= -1;
}
}
for the left one :
onClipEvent (enterFrame) {
if (_root.ball.hitTest(this)) {
_root.ball.xspeed *= -1;
}
}
and for the right one :
onClipEvent (enterFrame) {
if (_root.ball.hitTest(this)) {
_root.ball.xspeed *= -1;
}
}
Now next thing you wanna do is select all of them and convert them to a movieclip. Now give these actions to the movieclip you just created:
onClipEvent (load) {
_root.blocks++;
strenght = 1;
}
onClipEvent (enterFrame) {
gotoAndPlay(strenght);
if (_root.ball.hitTest(this)) {
strenght -= 1;
if (strenght == 0) {
_root.blocks -= 1;
unloadMovie(this);
}
}
}
Ok, so let me explain. The Strenght variable is the number of times that the ball is gonna have to hit the block until it is gone. in this case, it's one. It also tells the block to go to and play the frame that matches the strenght. So inside this movieclip it would be a good idea to make a new layer and draw a new block for each frame. I think 5 are enough. Give all them the stop action, and we are done with the blocks.
Now let's change the bar's code. You should replace what you have there with:
onClipEvent (enterFrame) {
_x = _root._xmouse;
if (_root.blocks == 0) {
_root.nextFrame();
}
if (_root.lives == 0) {
_root.gotoAndStop("gameover");
}
}
It says that if there are no blocks on the stage, it will play the next frame. And if you run out of lives, it will play the frame labeled "gameover".
Now replace the codes in the ball for these :
onClipEvent (load) {
function restart():Void {
_y = _root.bar._y-20;
_x = _root.bar._x-30;
xspeed = random(20)+5;
yspeed = random(20)+5;
}
restart();
}
onClipEvent (enterFrame) {
_x += xspeed;
_y -= yspeed;
if (_x>=400) {
xspeed *= -1;
}
if (_x<=0) {
xspeed *= -1;
}
if (_y<=0) {
yspeed *= -1;
}
if (_root.bar.hitTest(this)) {
yspeed *= -1;
xspeed += _root.difficulty;
yspeed += _root.difficulty;
}
if (_y>=600) {
_root.lives -= 1;
restart();
}
}
what we did is adding a difficulty to the game. Don't TEST it yet ! On next post we will set it up !!
0 comments:
Post a Comment