Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help me with my code! Vertical Shooter Game.

New Here ,
Jul 21, 2013 Jul 21, 2013

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

TOPICS
ActionScript
504
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 21, 2013 Jul 21, 2013
LATEST

The first thing you'll need to do is to clean up how the code looks in your posting so that it is more legible.  Then, reduce how much you show to only the code relevant to the problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines