Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 108516

Help me with my code! Vertical Shooter Game.

$
0
0

Okay so I am making a Vertical Shooter Game and I want to have 2 Weapons a Smaller Blue Bullet and a larger Green Bullet. When I shoot with the green bullet the enemies dont die but with the blue bullet the enemies do. Here is a chunk of the code for the blue and green bullet hitting enemies.

enemyTime ++;//incrementing time for enemy
if(enemyTime == enemyLimit){//if enough time has elapsed
_root.attachMovie('mcEnemy', 'en'+enemyTotal,_root.getNextHighestDepth());//then add the enemy
//setting it's coordinates
_root['en'+enemyTotal]._x = int(Math.random()*Stage.width);//randomly within the boundaries
_root['en'+enemyTotal]._y = -50; //sets this offstage at first
_root['en'+enemyTotal].onEnterFrame = function(){//then give it some functions
this._y += 5;
enemyTime ++;//incrementing time for enemy
if(enemyTime == enemyLimit){//if enough time has elapsed
_root.attachMovie('mcEnemy2', 'en'+enemyTotal,_root.getNextHighestDepth());//then add the enemy
//setting it's coordinates
_root['en'+enemyTotal]._x = int(Math.random()*Stage.width);//randomly within the boundaries
_root['en'+enemyTotal]._y = -50; //sets this offstage at first
_root['en'+enemyTotal].onEnterFrame = function(){//then give it some functions
this._y += 5;
//run a loop checking if it's touching any bullets
for(var cBullet:String in _root.bulletHolder){
//if it's touching the bullet
//we have to use coordinates because hit testing doesn't seem to work
if(this._y >= _root.bulletHolder[cBullet]._y-30 && this._y <= _root.bulletHolder[cBullet]._y){
if(this._x <= _root.bulletHolder[cBullet]._x+5 && this._x >= _root.bulletHolder[cBullet]._x -35){
//then destroy this guy
this.removeMovieClip();
//and destroy the bullet
_root.bulletHolder[cBullet].removeMovieClip();
//up the score
_root.score += 5;
}
}
}
//hit testing with the user
if(this.hitTest(_root.mcMain)){
//set the game to be over and go to lose screen
gameOver = true;
gotoAndStop('lose');
//and remove main
mcMain.removeMovieClip();
}
//checking if the game is over or it's off the stage
if(gameOver || this._y > 450){
//destroy this guy if the game is over
this.removeMovieClip();
}

 

}
enemyTime = 0;//reset the time
enemyTotal ++; //add 1 more to the amount of enemies total
}
//updating the score text field
txtScore.text = 'Score:  '+score;
//run a loop checking if it's touching any bullets
for(var cBullet:String in _root.bulletHolder){
//if it's touching the bullet
//we have to use coordinates because hit testing doesn't seem to work
if(this._y >= _root.bulletHolder[cBullet]._y-30 && this._y <= _root.bulletHolder[cBullet]._y){
if(this._x <= _root.bulletHolder[cBullet]._x+5 && this._x >= _root.bulletHolder[cBullet]._x -35){
//then destroy this guy
this.removeMovieClip();
//and destroy the bullet
_root.bulletHolder[cBullet].removeMovieClip();
//up the score
_root.score += 5;
}
}
}
//hit testing with the user
if(this.hitTest(_root.mcMain)){
//set the game to be over and go to lose screen
gameOver = true;
gotoAndStop('lose');
//and remove main
mcMain.removeMovieClip();
}
//checking if the game is over or it's off the stage
if(gameOver || this._y > 450){
//destroy this guy if the game is over
this.removeMovieClip();
}

 

}
enemyTime = 0;//reset the time
enemyTotal ++; //add 1 more to the amount of enemies total
}
//updating the score text field
txtScore.text = 'Score:  '+score;
//running a 2nd loop checking if it's touching any bullets
for(var cBullet2:String in _root.bulletHolder2){
//if it's touching the bullet
//we have to use coordinates because hit testing doesn't seem to work
if(this._y >= _root.bulletHolder2[cBullet2]._y-30 && this._y <= _root.bulletHolder2[cBullet2]._y){
if(this._x <= _root.bulletHolder2[cBullet2]._x+5 && this._x >= _root.bulletHolder2[cBullet2]._x -35){
//then destroy this guy
this.removeMovieClip();
//and destroy the bullet
_root.bulletHolder2[cBullet2].removeMovieClip();
//up the score
_root.score += 5;
}
}
}
//hit testing with the user
if(this.hitTest(_root.mcMain)){
//set the game to be over and go to lose screen
gameOver = true;
gotoAndStop('lose');
//and remove main
mcMain.removeMovieClip();
}
//checking if the game is over or it's off the stage
if(gameOver || this._y > 450){
//destroy this guy if the game is over
this.removeMovieClip();
}

 

}
enemyTime = 0;//reset the time
enemyTotal ++; //add 1 more to the amount of enemies total
}
//updating the score text field
txtScore.text = 'Score:  '+score;
//run a loop checking if it's touching any bullets
for(var cBullet2:String in _root.bulletHolder2){
//if it's touching the bullet
//we have to use coordinates because hit testing doesn't seem to work
if(this._y >= _root.bulletHolder2[cBullet2]._y-30 && this._y <= _root.bulletHolder2[cBullet2]._y){
if(this._x <= _root.bulletHolder2[cBullet2]._x+5 && this._x >= _root.bulletHolder2[cBullet2]._x -35){
//then destroy this guy
this.removeMovieClip();
//and destroy the bullet
_root.bulletHolder2[cBullet2].removeMovieClip();
//up the score
_root.score += 5;
}
}
}
//hit testing with the user
if(this.hitTest(_root.mcMain)){
//set the game to be over and go to lose screen
gameOver = true;
gotoAndStop('lose');
//and remove main
mcMain.removeMovieClip();
}
//checking if the game is over or it's off the stage
if(gameOver || this._y > 450){
//destroy this guy if the game is over
this.removeMovieClip();
}
}
enemyTime = 0;//reset the time
enemyTotal ++; //add 1 more to the amount of enemies total

}

//updating the score text field
txtScore.text = 'Score:  '+score;

Please help I would really appreciate it


Viewing all articles
Browse latest Browse all 108516

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>