First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Monkey boy

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
(10 being the highest)
» Author
british flash guy
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

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

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.