actionscript para disparar un missil desde nuestra nave (juego flash)

Creado a las // comentar

The Missile class is linked to a Missile movie clip in the library that will get attached to stage when the hero ship fires.

class Missile extends MovieClip
//We want to create a varible to keep track of important Missile information.
//We must define it here

//This will store how fast the missile travels
var speed;

//This onLoad function is a built-in function of every movie clip.
//When a missile is first loaded onto stage (it will get attached to the stage from the library) we want to:
function onLoad()
//Set it's speed variable to 20 (we want it to move 20 pixels in the positive x direction (right) at frame rate)
speed = 20;

//Add a shooting sound fx. we create the _root.soundFX sound object in the Ship class

//This onEnterFrame function is a built-in function of every movie clip.
//All the code that we need to continuously execute at 30 frames a second goes inside this function
function onEnterFrame()
//move the missile right 20 pixels (we set it's speed to -20 in the onLoad() function)
_x += speed;

//At frame rate we need to see if this missile is hitting any enemy ship
//All we have to do is iterate through every enemy ship in the hero ship's "enemies" array
for(var i in _root.ship.enemies)
//And see if this missile is hitting the current enemy in the list
if(this.hitTest( _root.ship.enemies[i] ) )
//If so, remove this missile movie clip from the stage
//and fire the takeDamage() function of the enemy being hit.
//The regular EnemyShip class, MiniBoss class, and the Boss class all have a takeDamage() function.


//if this missile reaches the far right end of the stage, remove it.
if(_x > 600)
//Also update the ship's "misses" variable, since it shot a missile that never hit an enemy
_root.ship.misses += 1;

0 comentarios: