Hello ! I will start writing a brick game tutorial =] . I will use only actions you already know ok ?
Let's start. Make a new file, 400x600, and change the framerate to 30.
So, first thing we wanna do is a bar, that will follow the mouse. So draw a bar, and place it on the bottom. Add these actions to it:
onClipEvent (enterFrame) {
_x = _root._xmouse;
}
very simple code here. Now we want to make a ball, that will turn when it hits the walls,the top, or the bar, and restart when it hits the bottom.
So draw a ball, and type this on the actions pannel :
onClipEvent (load) {
function restart():Void {
_y = _root.bar._y-20;
_x = 200;
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;
}
if (_y>=600) {
restart();
}
}
that code was long, but simple. The hardest i did was creating a function called restart.
Well, for now that's it. But i will be back with more =]
In the mean time, let's talk about random values. If you want a number variable to be random, type random (); for its value. Inside the parenthesis you can put a value so that this value will be the highest number. For example, random(20) can be any number from 1 to 20. And you can also add to random values. Like, random (20)+5 can be any number from 20 to 25.
Numbers can also be undefined; , and NaN (not a number) , just for the record
Saturday, March 7, 2009
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment