コード例 #1
0
        private static void ApplyFreeze(IGameTank gameTank, Bullet bullet, List<Monster> foesInRange)
        {
            foreach (var monster in foesInRange)
            {
                monster.Speed *= monster.Health / (double)(bullet.Freeze * 3 + monster.Health);

                gameTank.Freeze += bullet.Freeze;
            }
        }
コード例 #2
0
        private void ApplyDamage(IGameTank gameTank, Bullet bullet, List<Monster> foesInRange)
        {
            foreach (var monster in foesInRange)
            {
                monster.Health -= bullet.Damage;
                if (monster.OnHitAbility != null)
                {
                    monster.OnHitAbility.Invoke(_game.GameState, bullet.Damage);
                }
                gameTank.Damage += bullet.Damage;
                gameTank.MaxDamageDealt = Math.Max(bullet.Damage, gameTank.MaxDamageDealt);

                if (monster.Health <= 0)
                {
                    KilledMonster(gameTank, monster);
                }
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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;
                }
            }
        }
コード例 #5
0
        private void KilledMonster(IGameTank gameTank, Monster monster)
        {
            var gameState = _game.GameState;

            if (monster.OnDeathAbility != null)
            {
                monster.OnDeathAbility.Invoke(gameState);
            }

            gameState.Foes.Remove(monster);
            if (!gameState.Lost)
            {
                gameTank.Killed++;
                if (monster is BossMonster)
                {
                    gameTank.BossesKilled++;
                }
            }
        }