Search tutorials
Put a static text on the stage saying: How many laps? or anything similar to that. Then create an Input text on the stage with a variable name of Number. Lastly on this frame put another static text saying Next or Enter. Press F8 and make it a button with the code:
on(press){
_root.gotoAndStop("2")
}
on(keyPress""){
_root.gotoAndStop("2")
}
This basically says when the mouse is pressed/the enter key is pushed it goes to the next frame. Next add another frame. In this frame Make a car for you and a car for your opponent(they are both movie clips). A hint is to make your car a square or rectangle because otherwise parts of the movieclip will it the wall and bounce off when they aren't actually part of your car(name the car myCar and the opponent enemy). In your car put this code:
onClipEvent (enterFrame) {
// make the car go forward
if (Key.isDown(Key.UP)) {
speed += 1;
}
// make the car go backwards
if (Key.isDown(Key.DOWN)) {
speed -= 1;
}
// tells the car to slow down after the speed of 20
if (Math.abs(speed)>20) {
speed *= .7;
}
// you can change the rotation of the car to your desire
if (Key.isDown(Key.LEFT)) {
_rotation -= 15;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 15;
}
// here is where the hittest is for the boundary
speed *= .98;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.land.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.6;
}
if (this.hitTest(_root.wall1)) {
speed *= -.7;
}
}
Copy that last if test for every wall movie clip you have on the stage. Next go into the opponent movie clip and animate it going around the track at an even pace. Next draw the track you want to race in. The track must only consist of straight lines. Make each straight line a seperate movie clip making each of their instances names wall1, wall2, wall3 etc depending on how many walls you have.
Make two Dynamic text boxes called Laps and Laps1. Next make a finish line and two other invisible lines anywhere on the track(name the two lines L1 and L2. The finish line can remain nameless). In the finish line put the code:
onClipEvent(enterFrame){
if (this.hitTest(_root.MyCar) and _root.LastLine=="1"){
_root.Laps++;
_root.LastLine="2";
}
}
onClipEvent(enterFrame){
if (this.hitTest(_root.enemy)){
_root.Laps1++;
}
}
Now make a white flag in the middle of the track above the finish line called flag. Go into it and animate it waving back and forth. in the flag put in the code:
onClipEvent(enterFrame){
if(_root.Laps==_root.Number-1){
this._visible=true;
}
}
onClipEvent(enterFrame){
if(_root.Laps1==_root.Number-1){
this._visible=true;
}
}
onClipEvent(enterFrame){
if(_root.Laps==_root.Number){
_root.laps= _root.Laps+ " = your laps";
_root.laps1= _root.Laps1+ " = computers laps ";
_root.gotoAndStop("3")
}
}
onClipEvent(enterFrame){
if(_root.Laps1==_root.Number){
_root.laps= _root.Laps+ " = your laps";
_root.laps1= _root.Laps1+ " = computers laps ";
_root.gotoAndStop("4")
}
}
Now in this frames code put the following:
_global.LastLine="";
Laps=0;
Laps1=0;
setProperty("flag", _visible, false);
stop();
Now make 2 new frames. In frame 3 put a static text box saying You won. put two dynamic text boxes called laps and laps1(make sure these are in lower case and the other ones earlier were in capital letters). In frame 4 do the same(static and 2 dynamics) but the static text box says You lost.
Thats it if you completed this tutorial please email me at gravitationally_challenged99@hotmail.com and tell me if you liked it or not.
| » Level Intermediate |
|
Added: 2005-01-06 Rating: 3 Votes: 39 |
| » Author |
| gravitationally_challenged99@hotmail.com |
| » Download |
| Download the files used in this tutorial. |
| Download (0 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!