Demo Effect:
Click here to download the source file
Shooting game The main application of the code
1. Mouse follow StartDrag (this, true); used to make a standard device.
2. Layer-level control swapdepths ();
3. Collision Detection HitTest (_root.gun.hit)
4. Dynamic loading of the enemy: _root.attachmovie ();
5. Dynamic text box to make a display score
Production process:
1. Prepare a sight MC, containing the animation of firing
2. The enemy MC One, contains the enemy shot animation, in the library will be the enemy MC connection ID named "Man"
3. Dynamic text box writing code : first frame of the main timeline as:
------The main time axis code----------------
Hide the mouse
Mouse.hide ();
Initial set score of 0
scores = 0; This variable must correspond to the variable name of the fractional text box
Encapsulate the code, create a new function "Copyman"
function Copyman () {
Copy the MC in the Library ID "man" to the main scene, named "Man" +_root.i, layer level is _ROOT.I
Note: _ROOT.I does not set the initial value, so the default is none.
_root.i++, it's _root.i+1.
_root.attachmovie ("Mans", "Man" +_root.i, _root.i++);
Set the location of the new MC
Place the newly copied MC on the x axis of 0-550, and the Y axis is 0-400 of the random coordinates.
_root["man" +_root.i]._x = random (550);
_root["man" +_root.i]._y = random (400);
}
Execute new function
Copyman ();
then drag the target MC to the stage instance named "Gun" to write as on its MC:----------the code of MC--------------
Onclipevent (enterframe) {
Implement mouse to follow, and set the mouse to this MC registration point
StartDrag (this, true);
}
Onclipevent (MouseDown) {
When the mouse is pressed, run to this MC 3rd frame (Fire animation) execution
gotoAndPlay (3);
}
Onclipevent (load) {
Set the secondary star level of 9999, the larger the number of higher levels, lest the star was covered by the enemy
This.swapdepths (9999);
} This MC inside has a fire animation in the Fire animation This section plus an invisible MC, the instance named "hit"
Making enemy MC Interior
Inside the enemy MC, the first frame is not shot when the screen, in this frame and then add a stealth MC, plus as://Collision Detection
Onclipevent (enterframe) {
If detected in the Star MC in the hit contact on the previous level to jump to the 5th frame (was 毖) execution.
if (HitTest (_root.gun.hit)) {
_parent.gotoandplay (5);
}
}
After 5 frames for the shot after the death of the animation, in the last frame plus as://score plus 100
_root.scores + 100;
Functions that run Copyman copy enemies
_root.copyman ();
Remove this MC
Removemovieclip (this);