public Projectile(World world, Vector2 position, Unit target, int dmg, float speed, int imprecision) { this.world = world; this.targetFocused = target; this.position = position; this.damage = dmg; this.currentSpeed = speed; this.imprecision = imprecision; // this.texProjectile = world.texArrow; }
protected override void Fire(Unit target) { projectiles.Add(new Bullet(world, center, target, currentDamage, projectileSpeed, imprecision)); firingTimer = 0; if (fireSound != null && playSound) { // TODO sound here } }
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 = KLinuxDefense.AnimationType.RED_PUFF; missAnimation = KLinuxDefense.AnimationType.DIRT_PUFF; SetupProjectileSize(); CalculateMovement(); }
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 = KLinuxDefense.AnimationType.DIRT_PUFF; hitAnimation = KLinuxDefense.AnimationType.RED_PUFF; additive = true; scale = 0.4f; dType = KLinuxDefense.DamageType.PIERCE; color = new Color(255, 150, 150, 255); CalculateMovement(); SetupProjectileSize(); }
// Handles the entire process of creating unit waves and bosses private void UpdateWaves() { spawnTimer += (float)time.ElapsedGameTime.TotalMilliseconds; if (bossUnit!= null && bossEvent && bossUnit.isDead) { bossEvent = false; // TODO EndBossEvent } // Time for a new wave if (spawnTimer > spawnInterval) { int spawn = spawnRand.Next(spawns.Length); // Move through the unit type sequence unitIterator++; if (unitIterator == unitTypes.Length - 1) { unitIterator = 0; } // Add the new wave waves.Add(new Wave(game, spawns[spawn], unitTypes[unitIterator], 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 StrongUnit(game, spawns[spawn], 0.5f, 1, game.Status.Wave * 2, game.Status.Wave * 1000, Vector2.Zero, Vector2.Zero, texUnit, texUnitDead); bossUnit.Scale = 0.6f; bossUnit.Tint = Color.MediumOrchid; enemyUnits.Add(bossUnit); // TODO 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--); } } }
public override void undoEffect(Unit unit) { unit.Speed = unit.DefaultSpeed; }
public override void applyEffects(Unit unit) { unit.Speed = unit.DefaultSpeed * (1 - slowEffect); }
public abstract void undoEffect(Unit unit);
public abstract void applyEffects(Unit unit);
// Checks to see which targets are in splash range of the projectile protected Boolean IsInSRange(Unit target) { // TODO check that return ((Math.Sqrt (Math.Pow (target.Position.X - position.X, 2) + Math.Pow (target.Position.Y - position.Y, 2) )) < splashRange); }
// 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, currentDamage, projectileSpeed, 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) { // TODO play sound } }
// Gets the distance between target and tower's center protected float Distance(Unit target) { // Standard distance formula return (target.Center - center).Length (); }
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 (targetFocused == null || targetFocused.isDead || Distance (targetFocused) > currentRange) { targetFocused = CheckForTargets (); if (targetFocused == null) { targetCheckTimer = 0; } } else { Fire (targetFocused); // If there is a valid target, fire at it } } else { targetCheckTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; } UpdateProjectiles (); // update projectiles }