private string weaponName = "Iron shell"; // used to storage the tank's weapon /// <summary> /// Fire a specified weapon from the tank /// </summary> /// <param name="weapon">Weapon selected</param> /// <param name="playerTank">The tank firing</param> /// <param name="currentGame">The current battle</param> public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float tankX; // used to storage the firing position of a tank float tankY; GenericPlayer firingPlayer; //used to storage owner of tank int damage, explosionRadius, earthDestruction; // get the current position of tank tankX = playerTank.GetX(); tankY = playerTank.Y(); // find the centre of tank by add half the width and height tankX = tankX + TankModel.WIDTH / 2; tankY = tankY + TankModel.HEIGHT / 2; // get the firing player of tank firingPlayer = playerTank.GetPlayerNumber(); // create new explosion Explosion basicExplosion; //set power of weapon damage = 100; // damage done by bullet explosionRadius = 4; //size of explosion earthDestruction = 4; //damage to area around explosion basicExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create new bullet Bullet basicBullet; basicBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.01f, //gravity basicExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(basicBullet); }
/// <summary> /// Fire a specified weapon from the tank /// </summary> /// <param name="weapon">Weapon selected</param> /// <param name="playerTank">The tank firing</param> /// <param name="currentGame">The current battle</param> public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float tankX; // used to storage the firing position of a tank float tankY; GenericPlayer firingPlayer; //used to storage owner of tank int damage, explosionRadius, earthDestruction; Random unaccurateShot = new Random(); // used to make the missles fly off course a bit // get the current position of tank tankX = playerTank.GetX(); tankY = playerTank.Y(); // find the centre of tank by add half the width and height tankX = tankX + TankModel.WIDTH / 2; tankY = tankY + TankModel.HEIGHT / 2; // get the firing player of tank firingPlayer = playerTank.GetPlayerNumber(); //set power of weapon damage = 80; // damage done by bullet explosionRadius = 4; //size of explosion earthDestruction = 4; //damage to area around explosion //check which sort of shot to fire; if ((WeaponChoice)weapon == WeaponChoice.IronShell) { //fire a normal shot //create a explosion for the shot Explosion basicExplosion; basicExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create new bullet Bullet basicBullet; basicBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.01f, //gravity basicExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(basicBullet); } if ((WeaponChoice)weapon == WeaponChoice.PierceShot) { //fire a shot which will pierce the first thing it hits and cause a second explosion //fire a piecre shot with a weaker strength int weakerStr = 60; int makePercentageOfOrginial = 100; //create a explosion for the shot Explosion pierceExplosion; pierceExplosion = new Explosion((damage * weakerStr) / makePercentageOfOrginial, (explosionRadius * weakerStr) / makePercentageOfOrginial, (earthDestruction * weakerStr) / makePercentageOfOrginial ); //create new bullet PierceBullet pierceBullet; pierceBullet = new PierceBullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.01f, //gravity pierceExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(pierceBullet); } }
/// <summary> /// Fire a specified weapon from the tank /// </summary> /// <param name="weapon">Weapon selected</param> /// <param name="playerTank">The tank firing</param> /// <param name="currentGame">The current battle</param> public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float tankX; // used to storage the firing position of a tank float tankY; GenericPlayer firingPlayer; //used to storage owner of tank int damage, explosionRadius, earthDestruction; Random unaccurateShot = new Random(); // used to make the missles fly off course a bit // get the current position of tank tankX = playerTank.GetX(); tankY = playerTank.Y(); // find the centre of tank by add half the width and height tankX = tankX + TankModel.WIDTH / 2; tankY = tankY + TankModel.HEIGHT / 2; // get the firing player of tank firingPlayer = playerTank.GetPlayerNumber(); //set power of weapon damage = 5; // damage done by bullet explosionRadius = 10; //size of explosion earthDestruction = 10; //damage to area around explosion //check which sort of shot to fire if ((WeaponChoice)weapon == WeaponChoice.BigBang) { //create a explosion for the bullet Explosion firstExplosion; firstExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create a bullet for the shot Bullet firstBullet; firstBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.03f, firstExplosion, playerTank.GetPlayerNumber() ); //add the bullet to the battle environment currentGame.AddEffect(firstBullet); } if ((WeaponChoice)weapon == WeaponChoice.SmallBangs) { //this weapon choice fires multiple 1-3 smaller bullets Random shotsFired = new Random(); int numberOfShots = shotsFired.Next(1, 4); //create a explosion for the bullet Explosion firstExplosion; //create a weaker shot than a normal shot int makeWeaker = 60; int makePertcentageOfOrginalValue = 100; firstExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue, (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue, (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue) ; //create a bullet for the shot Bullet firstBullet; firstBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.01f, firstExplosion, playerTank.GetPlayerNumber() ); //add the bullet to the battle environment currentGame.AddEffect(firstBullet); if (numberOfShots > 1) { //fire a second shot //create a explosion for the bullet Explosion secondExplosion; secondExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue, (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue, (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue) ; //create a bullet for the shot Bullet secondBullet; secondBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.015f, secondExplosion, playerTank.GetPlayerNumber() ); //add the bullet to the battle environment currentGame.AddEffect(secondBullet); } if (numberOfShots > 2) { //fire a third shot //create a explosion for the bullet Explosion thirdExplosion; thirdExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue, (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue, (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue) ; //create a bullet for the shot Bullet thirdBullet; thirdBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.02f, thirdExplosion, playerTank.GetPlayerNumber() ); //add the bullet to the battle environment currentGame.AddEffect(thirdBullet); } } }
/// <summary> /// Fire a specified weapon from the tank /// </summary> /// <param name="weapon">Weapon selected</param> /// <param name="playerTank">The tank firing</param> /// <param name="currentGame">The current battle</param> public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float tankX; // used to storage the firing position of a tank float tankY; GenericPlayer firingPlayer; //used to storage owner of tank int damage, explosionRadius, earthDestruction; Random unaccurateShot = new Random(); // used to make the missles fly off course a bit // get the current position of tank tankX = playerTank.GetX(); tankY = playerTank.Y(); // find the centre of tank by add half the width and height tankX = tankX + TankModel.WIDTH / 2; tankY = tankY + TankModel.HEIGHT / 2; // get the firing player of tank firingPlayer = playerTank.GetPlayerNumber(); //set power of weapon damage = 50; // damage done by bullet explosionRadius = 3; //size of explosion earthDestruction = 2; //damage to area around explosion //check which sort of shot to fire if ((WeaponChoice)weapon == WeaponChoice.DoubleTap) { // fire two to semi accurate missiles // create explosions for missiles Explosion firstExplosion; Explosion secondExplosion; firstExplosion = new Explosion(damage, explosionRadius, earthDestruction); secondExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create new missile bullets Bullet firstMissile; Bullet secondMissile; firstMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-2, 3)), playerTank.GetPower() + (unaccurateShot.Next(-3, 4)), 0.01f, //gravity firstExplosion, firingPlayer) ; secondMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-2, 3)), playerTank.GetPower() + (unaccurateShot.Next(-3, 4)), 0.01f, //gravity secondExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(firstMissile); currentGame.AddEffect(secondMissile); } if ((WeaponChoice)weapon == WeaponChoice.Barrage) { // fire four missiles but they are very inaccurate shots //create explosions Explosion firstExplosion; Explosion secondExplosion; Explosion thridExplosion; Explosion fourthExplosion; firstExplosion = new Explosion(damage, explosionRadius, earthDestruction); secondExplosion = new Explosion(damage, explosionRadius, earthDestruction); thridExplosion = new Explosion(damage, explosionRadius, earthDestruction); fourthExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create new missile bullets Bullet firstMissile; Bullet secondMissile; Bullet thridMissile; Bullet fourthMissile; firstMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)), playerTank.GetPower() + (unaccurateShot.Next(-4, 9)), 0.01f, //gravity firstExplosion, firingPlayer) ; secondMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)), playerTank.GetPower() + (unaccurateShot.Next(-4, 9)), 0.01f, //gravity secondExplosion, firingPlayer) ; thridMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)), playerTank.GetPower() + (unaccurateShot.Next(-4, 9)), 0.01f, //gravity thridExplosion, firingPlayer) ; fourthMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)), playerTank.GetPower() + (unaccurateShot.Next(-4, 9)), 0.01f, //gravity fourthExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(firstMissile); currentGame.AddEffect(secondMissile); currentGame.AddEffect(thridMissile); currentGame.AddEffect(fourthMissile); } }