stop();
onEnterFrame = function(){
if(Key.isDown(32)){//if the space bar is pressed
var bulletID:Number = Math.random(); //create a variable that we'll use at the bullet's id
//then attach a bullet to the stage
_root.attachMovie('mcBullet', 'Bullet'+bulletID,_root.getNextHighestDepth());
//setting the coordinates of the bullet to be the same as the main character
_root['Bullet'+bulletID]._x = mcMain._x + mcMain._width/2 - _root['Bullet'+bulletID]._width/2;
_root['Bullet'+bulletID]._y = mcMain._y;
_root['Bullet'+bulletID].onEnterFrame = function(){
//giving the bullet some actions
this._y -= 10; //moving the bullet
if(this._y < -1 * this._height){//if the bullet goes off stage
//then destroy it
this.removeMovieClip();
}
}
}
}
var mainSpeed:Number = 6;//how fast the main guy can move
//ENEMY TIMING VARIABLES
//how much time before another enemy is made
var enemyTime:Number = 0;
//how much time needed to make an enemy
//it should be more than the shooting rate
//or else killing all of the enemies would
//be impossible :o/>
var enemyLimit:Number = 16;
onEnterFrame = function(){
// this controls the mcMain
//this function will run every frame (needed for moving the character
if(Key.isDown(37) || Key.isDown(65)){ //if the "A" key or Left Arrow Key is Down
ship._x -= mainSpeed;//then the move the guy left
}
if (Key.isDown(38) || Key.isDown(87)){//if the "W" key or Up Arrow Key is Down
ship._y -= mainSpeed; //then move the guy up
}
if(Key.isDown(39) || Key.isDown(68)){//if the "D" key or Right Arrow Key is Down
ship._x += mainSpeed; //then move the guy to the right
}
if(Key.isDown(40) || Key.isDown(83)){//if the "S" key or Down Arrow Key is Down
ship._y += mainSpeed; //then move the guy down
}
enemyTime ++;//incrementing time for enemy
if(enemyTime == enemyLimit){//if enough time has elapsed
var enID:Number = Math.random(); //create a variable that we'll use at the enemy's id
_root.attachMovie('mcEnemy','en'+ enID,_root.getNextHighestDepth());//then add the enemy
//setting it's coordinates
_root['en'+enID]._x = int(Math.random()*Stage.width);//randomly within the boundaries
_root['en'+enID]._y = -50; //sets this offstage at first
_root['en'+enID].onEnterFrame = function(){//then give it some functions
this._y += 5;
}
enemyTime = 0;//reset the time
}
}
Everything works (moving the character with the keys and having the enemies fall down the screen) until I type in the bullet code.

New Topic/Question
Reply



MultiQuote



|