Due to the length of this tutorial(like wtf),I will be splitting it into 2 separate parts,just be aware of that.
Ok,well I wanted to make a helicopter game for a while,and the codes I tried to make all didn't work until I found out th KeyCode '1' is the Left Click on mouse,which allowed me to make a helicopter game script,and I shall share it with all you good folk.Yay :D
So here we go...
First of all,I want to post an EXAMPLE.I only have 2 blocks,and they aren't that great,and no,the helicopter is not something I made,it's just a Google image.
Now I want to post the scripts and where they will be put into.First,make a second layer,name it ActionScript or whatever you want,and then make 2 empty KeyFrames on each layer.In the first ActionScript Keyframe,post this code...
stop();
_root.dist2.selectable = false;
onMouseDown = function () {
gotoAndStop(2);
};
_root.dist2 = _root.dist;
In the second ActionScript KeyFrame,post this code...
stop();
dist = 0;
_root.dist.selectable = false;
onEnterFrame = function () {
_root.dist++;
};
Ok now in frame 1,write some text that says 'Click to Play'.Then make a dynamic text box and type 'dist2' into the Var box(it's down in the properties section).You can also add the helicopter or something without actions in it to decorate the frame a bit like in the Helicopter game(the really good version).
Ok,now go to the second frame again and make a helicopter MovieClip if you haven't already,and place it somewhere on the Left side of the stage.Add this code to the Helicopter...
onClipEvent (load) {
var grav:Number = 5;
var spe:Number = 0;
}
onClipEvent (enterFrame) {
this._y += grav;
if (Key.isDown(1)) {
_rotation = -5;
this._y -= spe;
grav--;
spe++;
} else {
_rotation = 10;
spe--;
grav++;
}
if (this._y<0) {
_root.gotoAndStop(1);
removeMovieClip(_root.block2);
}
if (this._y>400) {
_root.gotoAndStop(1);
removeMovieClip(_root.block2);
}
if (this.hitTest(_root.block)) {
_root.gotoAndStop(1);
removeMovieClip(_root.block2);
removeMovieClip(_root.block3);
}
if (this.hitTest(_root.block1)) {
_root.gotoAndStop(1);
removeMovieClip(_root.block2);
removeMovieClip(_root.block3);
}
}
Also,make another dynamic text box in the second KeyFrame and make the Var 'dist'.It make be a good idea to make a couple of rectangles at the top and bottom of the stage so the person knows there are boundaries.Now,make 1 block MovieClip and add this code to it....
onClipEvent (load) {
var spe2:Number = 10;
i = 2;
}
onClipEvent (enterFrame) {
this._x -= spe2;
if (this._x<0) {
_root.block._y = random(Stage.height);
duplicateMovieClip(_root.block, "block2"+i, i);
_root["block2"+i]._x -= spe2;
_root["block2"+i]._height = random(90);
this._x = 573.4;
}
}
Make sure the instance name in this MovieClip is 'block',otherwise it won't work.Now make a second Block MovieClip and add this code to it....
onClipEvent (load) {
var spe3:Number = 6;
i = 2;
}
onClipEvent (enterFrame) {
this._x -= spe3;
if (this._x<0) {
_root.block._y = random(Stage.height);
duplicateMovieClip(_root.block1, "block3"+i, i);
_root["block3"+i]._x -= spe3;
_root["block3"+i]._height = random(90);
this._x = 638.3;
}
}
Be sure that the instance name of this block is 'block1'.
Now,if you want to be cool,you would learn about these scripts so you can code one like it yourself :D