示例#1
0
        /// <param name="spawnDelay">In ms. Used to easily allow infantry to gradually move out of a ship.</param>
        /// <param name="ship">The ship this infantry is/will be spawned from (used only if spawnDelay is not 0).</param>
        public Infantryman(Game game, int spawnDelay = 0, Ship ship = null)
            : base(game, null)
        {
            Model = new CircleShape(4, 12);
            if (Game.GraphicsMode == Game.GRAPHICSMODE_NORMAL)
            {
                Model.FillColor = new Color((byte)Utils.RandomInt(0, 255), (byte)Utils.RandomInt(0, 255), (byte)Utils.RandomInt(0, 255));
                Model.OutlineColor = new Color(0, 0, 0);
                Model.OutlineThickness = 3;
            }
            else if (Game.GraphicsMode == Game.GRAPHICSMODE_BLUEPRINT)
            {
                Model.FillColor = new Color(0, 0, 0, 0);
                Model.OutlineColor = new Color(255, 255, 255);
                Model.OutlineThickness = 2;
            }
            AddChild(Model);
            Origin = new Vector2f(Model.Radius, Model.Radius);

            Collision = Model;

            HealthMax = 4000;
            Health = HealthMax;

            //SpeedMax = 100.0f;
            //Acc = 400.0f;
            SpeedMax = 10.0f + Math.Min(0.1f * Game.AIManager.Difficulty, 10.0f);
            Acc = 80.0f;
            Friction = 1000.0f;

            if (spawnDelay == 0)
            {
                SetAI(new InfantrymanAI(Game));
            }
            else
            {
                CanTakeDamage = false;
                Visible = false;
                if (ship == null)
                    return;
                Ship = ship;
                SpawnDelayTimer = new Timer(spawnDelay);
                SpawnDelayTimer.AutoReset = false;
                SpawnDelayTimer.Elapsed += OnSpawn;
                SpawnDelayTimer.Start();
            }
        }
示例#2
0
        private void SpawnOverTimeTimerHandler(Object source = null, ElapsedEventArgs e = null)
        {
            if (Game.Player == null)
            {
                StopSpawnEnemiesOverTime();
                return;
            }
            if (Game.Player.HasPowerup(Powerup.FREEZE_TIME))
                return;

            // Spawn enemy
            Character enemy;
            switch (SpawnOverTimeType)
            {
                case TYPE_SHIP:
                {
                    enemy = new Ship(Game);
                    int angle = Utils.RandomInt(0, 359);
                    Vector2f intersectPoint = Utils.RaycastAgainstBounds(Game.Bounds, Game.Center, Utils.GetPointInDirection(Game.Center, angle, Game.Size.X));
                    enemy.SetPosition(Utils.GetPointInDirection(intersectPoint, angle, 200));
                    break;
                }
                default:
                {
                    enemy = new Infantryman(Game);
                    enemy.SetPosition(Utils.GetPointInDirection(Game.Island.Position, Utils.RandomInt(0, 359), Game.Island.Radius - 5));
                    break;
                }
            }

            enemy.Death += OnEnemyDeath;
            EnemyCount++;
            Game.Layer_Objects.AddChild(enemy);

            SpawnOverTimeCount++;

            if (SpawnOverTimeCount >= SpawnOverTimeAmount)
            {
                // Finish spawning enemies over time
                StopSpawnEnemiesOverTime();
            }
        }
示例#3
0
        // Enemy Spawning
        public object SpawnEnemy(uint type, Vector2f position)
        {
            Character enemy;
            switch (type)
            {
                case TYPE_SHIP: enemy = new Ship(Game); break;
                case TYPE_ROWBOAT: enemy = new Rowboat(Game); break;
                default: enemy = new Infantryman(Game); break;
            }

            enemy.Position = position;

            enemy.Death += OnEnemyDeath;
            EnemyCount++;
            Game.Layer_Objects.AddChild(enemy);

            return enemy;
        }
示例#4
0
        public void OnShipReachedBeach(Ship ship)
        {
            const float gapX = 4;

            for (int i = 0; i < ship.AmountOfInfantry; i++)
            {
                Infantryman enemy = new Infantryman(Game, Utils.RandomInt(0, 5000), ship);
                enemy.SetPosition(Utils.GetPointInDirection(
                    Game.Island.Position,
                    (float)Utils.GetAngle(Game.Island.Position, ship.Position) - ((ship.AmountOfInfantry / 2) * gapX) + (i * gapX),
                    Game.Island.Radius - 5)
                    );

                enemy.Death += OnEnemyDeath;
                EnemyCount++;
                Game.Layer_Objects.AddChild(enemy);
            }
        }
示例#5
0
        private void OnSpawn(Object source, ElapsedEventArgs e)
        {
            SpawnDelayTimer.Stop();
            SpawnDelayTimer = null;

            if (Ship != null && !Ship.IsDead())
            {
                // Spawn
                Ship.RemoveInfantryman();
                CanTakeDamage = true;
                Visible = true;
                SetAI(new InfantrymanAI(Game));
            }
            else
            {
                if (Parent != null)
                    Parent.RemoveChild(this);
                Game.AIManager.EnemyRemoved(this, false);
            }

            Ship = null;
        }