Intro.
every body must have played the first two games in the GTA series. this tutorial is designed to help you to create a replicer version of this in Flash. this will include the movement, getting in and out of vehicles and enemies. so let's get started.
Step 1. Creating the map
The first thing you need to do is to create the map for your game and convert it into a movieclip. Then you will need to add this code to the actions
- onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_rotation += 15;
}
if (Key.isDown(Key.RIGHT)) {
_rotation -= 15;
}
}
I will explain the need for this code later. now convert that movie clip into another movieclip so that you have a movie clip inside a movieclip. name the instance of this movieclip to "map". for now we will leave this as the player needs to be created so that the final code for the map will work.
Step 2. Creating
Now create a new layer. and in this layer draw the main charecter for the game and convert that into a movie clip. give the movieclip the instance name "player". then put this code into the actions.
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_rotation -= 15;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 15;
}
}
All this code will do is make the player turn around which is all we want it to do.
Step 3. Creating the movement
you may have noticed that when you play gta the map and player start to zoom out when you get to a certain speed. this will be covered in the final part of this tutorial. Go back to the "map" MC and enter this code into the actions.
onClipEvent (load) {
speed = 0;
}
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 30
if (Math.abs(speed)>30) {
speed *= .7;
}
// you can change the rotation of the car to your desire
if (Key.isDown(Key.LEFT)) {
_rotation -= 15;
_root.player._rotation -= 15;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 15;
_root.player._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;
}
// zoom out/in
if ((Key.isDown(Key.UP)) && (_root.player._yscale>=75) && (_root.player._xscale>=75) && (_root.map.speed>=
20)) {
_root.player._yscale -= 5;
_root.player._xscale -= 5;
} else if ((_root.player._yscale<= 100) && (_root.player._xscale<=
100) && (_root.map.speed<=15)) {
_root.player._yscale += 5;
_root.player._xscale += 5;
}
}
If you test the movie you may find that the car looks as if it's driving backwards. this problem is very easy to sort out. first right click on you "map" MC and click "edit in place" then select the MC inside and flip it 180 degrees. now go back to the main stage select the "map" MC and spin that round 180 degrees as well. don't worry you will see how it helps when you test the movie again.
that is all for this tutorial. if you have trouble with anything don't hesitate to e-mail me. the next tutorial will be creatin other vehicles for your player to get in and out of.
| » Level Intermediate |
|
Added: 2005-09-14 Rating: 6 Votes: 27 |
| » Author |
| british flash guy |
| » 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!