Do your enemy MC in Flash MX2004, then in the Links dialog box, write "Baddie" in the Identification Text box, and write "Enemy" in the AS2 class text box. Now write down the following script in your FLA's interactive panel, connect the enemy MC into the scene and put them in an EnemyArray array: (Translator Note: It seems that AS2 Array is the same as AS1 (there is also JavaScript), what is it can be put, it is quite like this.)
// ------ Connect to the Enemy array --------- // for (VAR J = 0; J <3; J ) {AttachMovie ("Baddie", "Baddie" J, 200 J); ENARRAY [J] = _root ["Baddie" J]; ENARRAY [J] ._ x = 50 * J; ENARRAY [J] ._ y = 100;}
This is something written in our Enemy class: Class Enemy Extends moviClip {// Write the code of the implementation here} // ------- Enemy class end
Moving the Enemy class is not, what we need? How to come to some variables. Let's go back to the previous class table to see what we can design in the document. Ok, we need speed, so I put it. Go in, and we need a way to move, and some things I have forgotten in the design, a reset () method that causes the enemy to remove the left side of the scene or when they are stabbed back to the right side of the scene We can set the initial speed in the constructor, which is what I have done so far:
Class Enemy Extends MovieClip {// Declaration Property Private Var Speed: Number; / / ======= Constructor Function Enemy () {Speed = 20;} / / ===== Mobile Function Movenemy () {i (_X <= - 30) {// Reset ();} else {_x - = speed;}} // ======} / ====== 50; _y = math.random () * 380 10; speted = math.random () * 10 10;}
} // ----- The Enemy class ends through compilation test it. Ah! Make up the effectiveness. The enemy machine starts to start with 10-20 pixels / frames in the X direction. Oh, then we will put us The machine puts it in the GAME class, so put the following code in the Game class. /// // //-mobile enemy function movebaddies () {for (var i = 0; i <3; i ) {EnemyArray [ i] .Movenemy ();}} and once again confirm that you have a MovebAddies method in your Enterframe loop in your Flash file, which makes your code in your Action panel neat and clean.
// Cycle _Root.MoveShip (); mygame.movesers (); mygame.movesel (); mygame.movelasers (); mygame.movebaddies (); MYGAME.MOVEBADDIES (); MYGAME.MOVEBADDIES ();} Collision detection I don't know how I will implement it, Perhaps it is in the game class. And do some cycles ...
// In the GAME class // collision detection function collision () {for (var j = 0; j <6; j ) {for (var k = 0; k <3; k ) {if (Laserarray [J]. Hittest ("Enemya") {trace ("Enemy Hit, NO." K);}}}} and put the method here into the Enterframe event in our FLA file: // loop: _root. Oneterframe = function () {MyGame.checkKey (); mygame.moveship (); mygame.movelaser (); mygame.movebaddies (); mygame.collision ();} Manufacturing explosion effect, when the bullet hits the enemy plane We want to see the explosion (that is of course). Make an explosion MC in your Flash MX 2004 file. I just gathered some images of smoke and fog in each frame, and in the last plus a blank frame, there is a STOP (). I called this MC called "splode_mc" and called "splode" in the link dialog. So in the magnetic collision method, I should connect to the splode MC, reset the enemy machine, then we Plus the score.
// In the GAME class // collision detection function collision () {for (var j = 0; j <6; j ) {for (var k = 0; k <3; k ) {if (Laserarray [J]. Hittest (EnemyArray [k])) {// Explosion effect _root.attachmovie ("splode", "splode", 301); // makes the explosion act on the enemy plane _root.splode._x = EnemyArray [k] ._ x _Root.splode._y = EnemyArray [k] ._ y; // Reset the enemy machine on the right side of the scene EnemyArray [k] .ReSet (); Break;}}}}
The enemy machine of collision detection touches the spaceship. Now let us examine the enemy machine me and the collision between our spaceship. I repeatedly used SPLOE_MC, changed its color and X, Y direction stretching value, and we can also add a sound to the judgment of each hit. But I still give it to you.
// Collision detection Function Collision () {for (var j = 0; j <6; j ) {for (var k = 0; k <3; k ) {// Check bullet hit enemy machine IF (Laserarray [J ] .hittest (EnemyArray [K])) {// // Explosion Effect_Root.attachmovie ("splode", "splode", 301); // makes explosion acts on enemy machine position _Root.splode._x = EnemyArray [ K] ._ x; _root.splode._y = EnemyArray [k] ._ y; // Reset the enemy plane to the right side of the scene EnemyArray [k] .ReSet ();} // end if // Check the enemy hit Spacecraft IF (EnemyArray [k] .hittest (ship)) {_root.attachmovie ("splode", "splode", 301); // makes explosion conforms to the coordinate of the aircraft _Root.splode._x = Ship._x; _root.splode ._y = ship._y; // change color var my_color: color = new color (_root.splode); my_color.setrGB (0xff0000); // change the size _Root.splode._xscale = 400;} }}} Score and the life value: What is left? The score is worthy of life. I may do some text boxes, change their Text attributes when changing. So do two text boxes in our Flash MX 2004 file, named Score_TXT and LIVES_TXT, then add two variables, score and live to the game class, and initialize them in our constructor.
// In the GAME class // Declared Variable VAR Score: Number; Var Lives: Number; / / ==== Constructor =========================================================================================================== : Array, _bullarray: array) {Ship = _ship; EnemyArray = _Narray; LaseraRray = _bullarray; // Initialization Bullet and health score = 0; lives = 10;} Now let us set Score and Lives variables to TextFields
// In the GAME class // collision detection function collision () {for (var j = 0; j <6; j ) {for (var k = 0; k <3; k ) {// Check bullet hit the enemy Machine IF (Laserarray [J])) {// increase fraction value and present it score = 10; _root.score_txt.text = "score:" score; // explosion effect _Root.attachmovie ("splode", "splode", 301); // makes the explosion in the position of the enemy machine _root.splode._x = EnemyArray [k] ._ x; _root.splode._y = EnemyArray [k] ._ y; // Reset the enemy plane to the right side of the scene EnemyArray [K] .ReSet ();} // end if // Check the enemy hit the spacecraft IF (EnemyArray [k] .hittest (ship)) {// Reset the enemy machine , Reduce health // display health EnemyArray [k] .ReSet (); lives - = 1; _root.lives_txt.text = "limited" lives; _root.attachmovie ("splode", "splode", 301 ); // makes the explosion conform to the coordinates of the aircraft _Root.splode._x = ship._x; _root.splode._y = ship._y; // change color var my_color: color = new color (_root.splode); my_color.setrgb (0xff0000); // Change the size _Root.splode._xscale = _root.splode._yscale = 400;}}}} I have to re-investigate enemy machine when hitting the spaceship in the code, because of the collision Continue a few frames, so the number of life will continue to decrease. Comment on the EnemyArray [K]. Reese You will see the continued reduction in the number of life. What is done above is a fairly simple process: 1 collision detection. 2 increase or decrease in variable values. 3 Present a variable value. This is a synthetic jumping in terms of technology, I think, I will put it there, let us digest. Next, we will do a method for checking the score to check the score and the number of life, if so, end the game.
But what is it, let us lose. The following precautions are the same as the first part ... next to the third part, where we will organize a method of rendering the score and make a horizontal movement background.
Sleal continuation ...