Kizzi
09-25-2009, 06:55 PM
(this is all class-based)
I have made a 2D scrolling shooter, following the kongregate Shootorials until recently when I decided to start adding my own stuff. The problem I am having is I am adding a "Rocket", which is a powerup that gives you piercing bullets. My basic solution was to simply copy the "Missile" class and remove the "this.removeMovieClip()" bit when it hits something. However, when it hits a miniboss or a boss, instead of reducing their health once, it does it once per frame, which means that they are too powerful. I am unsure of how to make them only hit minibosses / bosses once.
Note: The _root.ship.enemies is an array. Every time an enemy is spawned, the ship class adds the enemy to it. The takeDamage function is different depending on the type of enemy: With normal enemies that die instantly, it just calls the explode() function, which simply kills the enemy. In minibosses and bosses it lowers their health and adds a small explosion. Also, I have the "getting powerups" bit sorted and it works for the other 3 powerups.
Code for the Rocket class:
class Rocket extends MovieClip{
var speed = 20;
function onEnterFrame(){
_x += speed;
for(var i in _root.ship.enemies){
if(this.hitTest(_root.ship.enemies[i])){
_root.ship.enemies[i].takeDamage();
}
}
if (_x>600){this.removeMovieClip()}
}
}
Code for the takeDamage() function on the boss class:
function takeDamage(){
health -= _root.ship.bossDamage * 2;
_root.enemyHealthMeter.enemyBar._xscale = health;
var explosion = _root.attachMovie( "Explosion" , "Explosion" + _root.getNextHighestDepth(), _root.getNextHighestDepth() );
explosion._x = _x;
explosion._y = _y;
if(health < 1){
explode();
}
}
PS. If you need any more info then just ask.
I have made a 2D scrolling shooter, following the kongregate Shootorials until recently when I decided to start adding my own stuff. The problem I am having is I am adding a "Rocket", which is a powerup that gives you piercing bullets. My basic solution was to simply copy the "Missile" class and remove the "this.removeMovieClip()" bit when it hits something. However, when it hits a miniboss or a boss, instead of reducing their health once, it does it once per frame, which means that they are too powerful. I am unsure of how to make them only hit minibosses / bosses once.
Note: The _root.ship.enemies is an array. Every time an enemy is spawned, the ship class adds the enemy to it. The takeDamage function is different depending on the type of enemy: With normal enemies that die instantly, it just calls the explode() function, which simply kills the enemy. In minibosses and bosses it lowers their health and adds a small explosion. Also, I have the "getting powerups" bit sorted and it works for the other 3 powerups.
Code for the Rocket class:
class Rocket extends MovieClip{
var speed = 20;
function onEnterFrame(){
_x += speed;
for(var i in _root.ship.enemies){
if(this.hitTest(_root.ship.enemies[i])){
_root.ship.enemies[i].takeDamage();
}
}
if (_x>600){this.removeMovieClip()}
}
}
Code for the takeDamage() function on the boss class:
function takeDamage(){
health -= _root.ship.bossDamage * 2;
_root.enemyHealthMeter.enemyBar._xscale = health;
var explosion = _root.attachMovie( "Explosion" , "Explosion" + _root.getNextHighestDepth(), _root.getNextHighestDepth() );
explosion._x = _x;
explosion._y = _y;
if(health < 1){
explode();
}
}
PS. If you need any more info then just ask.