In this tutorial you will learn how to make a complete character movement which will include rotation and hit test for your flash games characters. You will also learn how to put scoring.
Click here to view the sample.
Just take the few steps below.
Step 1
Save the images below into your computer because we will make use of it, as the example.
image 1
image 2
image 3
Create a new flash document and then insert two more layers then rename them as follows:

car1 layer being the first followed by car2 layer finally actions layer.
Step 3
Import your image 1 to the car1 layer. Then set the position to this:
x-65.2
y-201.1
Click on it and Press F8 to convert it to a symbol. Select Movie Clip as the behavior, registration point center and then click ok.

Give the instance name “car_mc”. (this can be found on the property bar of the movie clip).

Now select your car_mc, press F9 and add this script to it.
//(c) otodeluxe 2010
onClipEvent(load){
speed=0;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
speed += 0.2;
}
//this is where the car will bounce back when it hits car2
if(this.hitTest(_root.car2_mc)){
this._x=0;
}
if(Key.isDown(Key.DOWN))
{
speed += -0.2;
}
if (Math.abs(speed)>10){
speed *= .7;
}
if(Key.isDown(Key.LEFT)){
_rotation -= 12;
}
if(Key.isDown(Key.RIGHT)){
_rotation += 12;
}
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;
}
}
Step 4
Import “image2” into the car 2 layer and set it to this position.
x- 336.7
y-89.5
Convert it to a movie clip symbol with registration point center and then click ok.
Give it the instance name of “car2_mc”.
Open the action script panel of the movie clip and copy in these
onClipEvent (enterFrame) {
if (this.hitTest(_root.car_mc)){
//the below code will go and stop at the frame 2 of the car 2 layer when the other car hits it
_root.car2_mc.gotoAndStop(2);
//this will increase the value of the hits dynamic text by 1
_root.hits++;
//this is very useful, it will return to frame 1 when nothing happens
}else{
_root.car2_mc.gotoAndStop(1);
}
}

Don’t worry about the grey text it is the explanation I made.
After typing in this codes.
Double click on your car2 movie clip and then press F6 on frame 2 and then import “image3” into frame 2 of the car2 movie clip and place it in this position.

Click on frame 1 of the car2 movie clip and type in the stop action to it, so that it won’t play all the frames.
Stop();
Step 5
After you might have completed all these. Lets make the scoring!
Take the Text tool (A) and draw a dynamic text area and give it the following properties.

Make the label “0” and Note the var (variable) “hits”.
Make another text but choose static text instead of dynamic text.
Then make the label Hits.
See final screenshot below.

Now that’s all about the tutorial.
Test your movie by pressing Ctrl + Enter.
Remember to drop your comments if you have any difficulty in doing this.


