private void MoveTank(IGameTank gameTank, TankUpdate tankUpdate, Tank tank) { var gameState = _game.GameState; if (tankUpdate.MovementTarget != null) { gameTank.MovementTarget = tankUpdate.MovementTarget; var V = new Vector(tankUpdate.MovementTarget.X - tank.X, tankUpdate.MovementTarget.Y - tank.Y); var angle = Math.Atan2(V.Y, V.X); var speed = Math.Min(tank.Speed, Math.Sqrt(V.X * V.X + V.Y * V.Y)); var xMovement = speed * Math.Cos(angle); var yMovement = speed * Math.Sin(angle); if (_game.IsTankInBounds(tank, tank.X + xMovement, tank.Y, gameState)) { ((Location)tank.Location).X += xMovement; } else { V.X /= 2; } if (_game.IsTankInBounds(tank, tank.X, tank.Y + yMovement, gameState)) { ((Location)tank.Location).Y += yMovement; } else { V.Y /= 2; } } }
private void DoTankAttack(IGameTank gameTank, TankUpdate tankUpdate, Tank tank) { gameTank.ShotTarget = tankUpdate.ShotTarget; gameTank.Shooting = false; if (gameTank.Heat <= 0 && gameTank.ShotTarget != null) { try { var bullet = (Bullet) tankUpdate.Bullet; gameTank.Shooting = true; gameTank.Shots++; gameTank.Bullet = bullet; gameTank.Heat += bullet.GetReloadTime((int)Game.GetDistance(tank.Center.X, tank.Center.Y, tankUpdate.ShotTarget.X, tankUpdate.ShotTarget.Y)); List<Monster> foesInRange = _game.GetFoesInRange(tankUpdate.ShotTarget.X, tankUpdate.ShotTarget.Y, bullet.SplashRange); ApplyDamage(gameTank, bullet, foesInRange); ApplyFreeze(gameTank, bullet, foesInRange); } catch { //They made a bad bullet, bad tank! } } else { gameTank.Heat = Math.Max(gameTank.Heat - 1, 0); } }
public GameTank(Tank tank, string owner) { Tank = tank; Owner = owner; Location = (Location)tank.Location; }