// Override firing protected override void Fire(Unit target) { int offset = (int)(imprecision * Distance(target) / range); if (missilesReady > 0 && missileTimer > missileInterval && (volleyReady || !volleyMode)) { if (tubeLeft) { projectiles.Add(new Shell(world, new Vector2(center.X - 3, center.Y - 2), target, dmg, pSpeed, imprecision, sDmg, sRange, pAcceleration, homing)); world.CreateAnimation("explosion2", new Vector2(center.X - 3, center.Y - 2), 0.25f, 0, 16.0f); } else { projectiles.Add(new Shell(world, new Vector2(center.X + 3, center.Y - 2), target, dmg, pSpeed, imprecision, sDmg, sRange, pAcceleration, homing)); world.CreateAnimation("explosion1", new Vector2(center.X + 3, center.Y - 2), 0.25f, 0, 16.0f); } tubeLeft = !tubeLeft; // swap tubes for next that is fired firingTimer -= firingRate; // subtracts a missile from storage missilesReady--; missileTimer = 0; // reset missile timer so the next launch is delayed slightly if (playSound) world.PlaySound(fireSound, center); if (missilesReady == 0) volleyReady = false; // the entire volley has been fired } }
protected override void Fire(Unit target) { projectiles.Add(new Bullet(world, center, target, dmg, pSpeed, imprecision)); firingTimer = 0; if (fireSound != null && playSound) world.PlaySound(fireSound, center); }
int width, height; // width & height of projectile #endregion Fields #region Constructors // Constructor public Projectile(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision) { this.world = world; this.target = target; this.position = position; this.dmg = dmg; this.speed = speed; this.imprecision = imprecision; this.texProjectile = world.texArrow; }
public Arrow(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision) : base(world, position, target, dmg, speed, imprecision) { texProjectile = world.texArrow; hitAnimation = "red puff"; missAnimation = "dirt puff"; SetupProjectile(); CalculateMovement(); }
protected override void Fire(Unit target) { if (sTimer > sInterval) { sTimer = 0; if (playSound) world.PlaySound(fireSound, center); } projectiles.Add(new Flame(world, new Vector2(center.X, center.Y - 2), target, dmg, pSpeed, imprecision, sDmg, sRange, pAcceleration)); firingTimer = 0; }
public GammaRay(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision) : base(world, position, target, dmg, speed, imprecision) { origin = position; //texProjectile = world.texRay; additive = false; scale = 0.4f; dType = "energy"; color = new Color(0, 0, 0, 0); CalculateMovement(); SetupProjectile(); }
public Bullet(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision) : base(world, position, target, dmg, speed, imprecision) { texProjectile = world.texBullet; missAnimation = "dirt puff"; hitAnimation = "red puff"; additive = true; scale = 0.4f; dType = "pierce"; color = new Color(255, 150, 150, 255); CalculateMovement(); SetupProjectile(); }
public Pulse(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision) : base(world, position, target, dmg, speed, imprecision) { texProjectile = world.texBullet; missAnimation = "redCircle"; hitAnimation = "pulseHit"; dType = "energy"; acceleration = 0; additive = true; scale = 0.7f; color = new Color(255, 60, 60, 255); CalculateMovement(); SetupProjectile(); }
public Concussion(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision, int netSize, float slowEffect, int duration) : base(world, position, target, dmg, speed, imprecision) { texProjectile = world.texConcussion; missAnimation = "concussion"; hitAnimation = "concussion"; splash = true; dType = "energy"; this.netSize = netSize; this.slowEffect = slowEffect; this.duration = duration; CalculateMovement(); SetupProjectile(); }
public Flame(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision, int sDmg, int sRange, float acceleration) : base(world, position, target, dmg, speed, imprecision) { texProjectile = world.texFire; hitAnimation = "explosion3"; missAnimation = hitAnimation; dType = "burn"; splash = true; this.sDmg = sDmg; this.sRange = sRange; this.homing = homing; this.acceleration = acceleration; SetupProjectile(); CalculateMovement(); }
protected override void Fire(Unit target) { int offset = (int)(imprecision * Distance(target) / range); if (missilesReady > 0 && missileTimer > missileInterval && (volleyReady || !volleyMode)) { world.CreateAnimation("redCircle", new Vector2(center.X, center.Y), 0.6f, 0, 15.0f); world.CreateAnimation("redCircle", new Vector2(center.X, center.Y), 0.6f, 0, 15.0f); projectiles.Add(new Pulse(world, new Vector2(center.X, center.Y), target, dmg, pSpeed, imprecision)); firingTimer -= firingRate; // subtracts a missile from storage missilesReady--; missileTimer = 0; // reset missile timer so the next launch is delayed slightly if (playSound) world.PlaySound(fireSound, center); if (missilesReady == 0) volleyReady = false; // the entire volley has been fired } }
// Override firing protected override void Fire(Unit target) { // The mg tower alternates its firing between two points and creates a flash effect as well if (barrelLeft) { world.CreateAnimation("lightCircle", new Vector2(center.X - 5, center.Y - 3), 0.6f, 0, 15.0f); projectiles.Add(new Bullet(world, new Vector2(center.X - 5, center.Y), target, dmg, pSpeed, imprecision)); //world.CreateAnimation("flash", new Vector2(center.X - 5, center.Y - 3), 0.5f, 0, 15.0f); } else { world.CreateAnimation("lightCircle", new Vector2(center.X + 5, center.Y - 3), 0.6f, 0, 15.0f); projectiles.Add(new Bullet(world, new Vector2(center.X + 5, center.Y), target, dmg, pSpeed, imprecision)); //world.CreateAnimation("flash", new Vector2(center.X + 5, center.Y - 3), 0.5f, 0, 15.0f); } if (playSound) world.PlaySound(fireSound, center); barrelLeft = !barrelLeft; // other barrel for next shot firingTimer = 0; }
public Shell(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision, int sDmg, int sRange, float acceleration, Boolean homing) : base(world, position, target, dmg, speed, imprecision) { texProjectile = world.texRocket; hitAnimation = "explosion1"; hitSound = "RndExplosion"; missAnimation = hitAnimation; dType = "explosive"; maxSpeed = 15; splash = true; this.sDmg = sDmg; this.sRange = sRange; this.homing = homing; this.acceleration = acceleration; SetupProjectile(); CalculateMovement(); }
// Gets the distance between target and tower's center protected float Distance(Unit target) { // Standard distance formula return (target.Center - center).Length(); }
// Fire a new projectile at target and reset firing timer protected virtual void Fire(Unit target) { // Very simple firing method that should be overridden by a more // unique method for new towers. Firing consists of adding // projectiles with specific targets and then reloading projectiles.Add(new Arrow(world, center, target, dmg, pSpeed, imprecision)); // Setting the firing timer to 0 requires the tower to have to wait // until it can fire again (reload) firingTimer -= firingRate; if (fireSound != null && playSound) world.PlaySound(fireSound, center); }
protected override void Fire(Unit target) { if (firingTimer >= firingRate) { if (playSound) world.PlaySound(fireSound, center); target.Damage(dmg + dmgBonus, "energy"); world.CreateAnimation("beamHit", target.Center, 0.25f, 0, 10f); world.CreateAnimation("lightCircle", target.Center, 0.25f, 0, 10f); firingTimer = 0f; dmgBonus += dmg; } }
public override void undoEffect(Unit unit) { }
public override void applyEffects(Unit unit) { unit.Damage(burnDmg,"burn"); }
// Handles the entire process of creating unit waves and bosses private void UpdateWaves() { spawnTimer += (float)time.ElapsedGameTime.TotalMilliseconds; if (bossUnit!= null && bossEvent && bossUnit.Dead) { bossEvent = false; //game.music.EndBossEvent(); } // Time for a new wave if (spawnTimer > spawnInterval) { int spawn = spawnRand.Next(spawns.Length); // Move through the unit type sequence unitType++; if (unitType == 5) unitType = 1; // Add the new wave waves.Add(new Wave(game, unitType, spawns[spawn], spawnSize, tile, unitInterval)); game.status.Wave += 1; spawnTimer = 0f; // Add a boss if its time to if (game.status.Wave % numberOfWavesPerStage == 0) { bossEvent = true; bossUnit = new Unit(game, spawns[spawn], Vector2.Zero, Vector2.Zero, 0.5f, 1, texUnit, texUnitDead, game.status.Wave * 2, game.status.Wave * 1000); bossUnit.Scale = 0.6f; bossUnit.Color = Color.MediumOrchid; enemyUnits.Add(bossUnit); //game.music.TriggerBossEvent(); game.status.Created++; } } // Remove old waves and update current ones for (int i = 0; i < waves.Count; i++) { waves[i].Update(time); if (waves[i].Finished) { waves.RemoveAt(i); i--; } } }
// Checks to see which targets are in splash range of the projectile protected Boolean IsInSRange(Unit target) { if ((Math.Sqrt(Math.Pow(target.Position.X - position.X, 2) + Math.Pow(target.Position.Y - position.Y, 2))) < sRange) return true; return false; }
protected override void Fire(Unit target) { projectiles.Add(new Concussion(world, pOrigin, AcquireClosestTarget(), dmg, pSpeed, imprecision, sRange, slowEffect, duration)); firingTimer = 0; }
public override void applyEffects(Unit unit) { unit.Speed = unit.DSpeed * (1 - slowEffect); }
public override void undoEffect(Unit unit) { unit.Speed = unit.DSpeed; }
public abstract void undoEffect(Unit unit);
protected override void Fire(Unit target) { addEffect(); }
public abstract void applyEffects(Unit unit);
// Update the tower and its projectiles public virtual void Update(GameTime gameTime) { ArrayList keysToRemove = applyEffects(gameTime); removeEffect(keysToRemove); // Increments the firing timer until tower can fire Reload(gameTime); // If ready to fire... if (firingTimer >= firingRate && targetCheckTimer >= targetCheckInterval) { // Update target if current one is dead or out of range if (target == null || target.Dead || Distance(target) > range) { target = CheckForTargets(); if (target == null) targetCheckTimer = 0; } else { Fire(target); // If there is a valid target, fire at it } } else { targetCheckTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; } UpdateProjectiles(); // update projectiles }