Game Development Community

Boss health

by DeVry Instructors (#0020) · in Torque Game Builder · 10/13/2008 (3:27 pm) · 0 replies

Hello I recently have received a copy of TGB and my friend was kind enough for her to let me use her account to post on the help form. Could anyone please help me develop a boss enemy file to to take 30 hits before exploding please help this is the code I have. I know that the enemy explodes on contact with a missile, I don't know how to issue a count value. Here is the code I have currently. My next question would be how do you set an enemy path.


//This function takes the initial postion of enemy object
function BossEnemyShip::onLevelLoaded(%this, %scenegraph)
{
   // Save the initial X value so we can use it when we respawn this ship
   %this.startX = %this.getPositionX();

   // Missile speed
   %this.missileSpeed = -500;
   
   // Spawn this ship 
   %this.scenegraph = %scenegraph; // Make sure the scenegraph is available for the fireMissile() function
   %this.spawn();
}


//This fuction sets the spawn point of enemy object at random
function BossEnemyShip::spawn(%this)


{
   //When enemy spawns fires one missle
   %this.fireMissile();
   // Set the minimum and maximum Y positions to be the
   // world limits, accounting for the size of the ship
   %this.minY = getword(%this.getWorldLimit(), 2) + (%this.getHeight() / 2);
   %this.maxY = getword(%this.getWorldLimit(), 4) - (%this.getHeight() / 2);
   
   // Set the speed limits
   %this.minSpeed = -50;
   %this.maxSpeed = -100;
   
   // Set the speed and position of this ship
   %this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
   %this.setPositionX(%this.minY, %this.maxY);
   %this.setPositionY(%this.startX);   
   //When enemy spawns fires one missle
   %this.fireMissile();
}

//This fuction recal the enemy ship once it pass the world limit and set it back at the spawn point
/*function BossEnemyShip::onWorldLimit(%this, %mode, %limit)
{
    // When the ship hits the left side of the world limits, then respawn the ship
    if (%limit $= "left") {
       %this.spawn();
    }
}*/
//Enables enemy to shoot missles
function BossEnemyShip::fireMissile(%this)
{
   %this.bossenemyMissile = new t2dStaticSprite()
   {
      scenegraph = %this.scenegraph;
      class = BossEnemyMissile;
      missileSpeed = %this.missileSpeed;
      bossEnemy = %this;
   };
   
   %this.bossenemyMissile.fire();
}


//Enemy ship explode on collison with missle
function BossEnemyShip::explode(%this)
{
   %explosion = new t2dParticleEffect() 
   {
      scenegraph = %this.scenegraph; 
    
   };
   
   %explosion.loadEffect("~/data/particles/big_explosion.eff");
   %explosion.setEffectLifeMode("KILL", 1);

   %this.scenegraph.incScore();
    
   %explosion.setPosition(%this.getPosition());
   %explosion.playEffect();

   %this.spawn();
}