Exemplo n.º 1
0
        private void LoadGameObjects()
        {
            var viewport = Engine.Graphics.GraphicsDevice.Viewport;

            _player = new Player(_playerShip)
            {
                Position = new Vector2((viewport.Width / 2) - (_playerShip.Width / 2), viewport.Height - (_playerShip.Height * 1.5f)),
                FireWeapons = PlayerFireWeapons
            };

            for (var i = 0; i < 3; i++)
            {
                _meteors.Add(new Meteor(_meteor)
                {
                    Position =
                        new Vector2((viewport.Width / 4) + ((viewport.Width / 4) * i) - (_meteor.Width / 2), viewport.Height - (_meteor.Height * 2.5f))
                });
            }

            for (var i = 0; i < 8; i++)
            {
                var x = 128 + (i * 128);
                var y = 32;
                var enemy = new Enemy(_enemyShip1)
                {
                    Position = new Vector2(x, y),
                    Group = "Group1",
                    LeftViewportCollision = ViewportCollision,
                    RightViewportCollision = ViewportCollision
                };
                _enemies.Add(enemy);
            }

            for (var i = 0; i < 8; i++)
            {
                var x = 128 + (i * 128);
                var y = 128;
                var enemy = new Enemy(_enemyShip2)
                {
                    Position = new Vector2(x, y),
                    MovementDirection = -1,
                    Group = "Group2",
                    LeftViewportCollision = ViewportCollision,
                    RightViewportCollision = ViewportCollision
                };
                _enemies.Add(enemy);
            }

            for (var i = 0; i < 8; i++)
            {
                var x = 128 + (i * 128);
                var y = 224;
                var enemy = new Enemy(_enemyShip3)
                {
                    Position = new Vector2(x, y),
                    Group = "Group3",
                    LeftViewportCollision = ViewportCollision,
                    RightViewportCollision = ViewportCollision
                };
                _enemies.Add(enemy);
            }

            for (var i = 0; i < 8; i++)
            {
                var x = 128 + (i * 128);
                var y = 320;
                var enemy = new Enemy(_enemyShip4)
                {
                    Position = new Vector2(x, y),
                    MovementDirection = -1,
                    Group = "Group4",
                    LeftViewportCollision = ViewportCollision,
                    RightViewportCollision = ViewportCollision
                };
                _enemies.Add(enemy);
            }
        }
Exemplo n.º 2
0
 private void ViewportCollision(Enemy affectedEnemy)
 {
     var group = _enemies.Where(e => e.Group == affectedEnemy.Group).ToList();
     foreach (var enemy in group)
     {
         if (enemy == affectedEnemy) continue;
         if (enemy.MovementDirection == -1)
         {
             enemy.MovementDirection = 1;
             enemy.Position += new Vector2(0f, enemy.Speed);
         }
         else if (enemy.MovementDirection == 1)
         {
             enemy.MovementDirection = -1;
             enemy.Position += new Vector2(0f, enemy.Speed);
         }
     }
 }
Exemplo n.º 3
0
        private void EnemyBlowUp(Bullet bullet, Enemy enemy)
        {
            bullet.IsAlive = false;
            enemy.IsEnabled = false;
            enemy.IsVisible = false;

            _enemiesKilled++;

            _blowUp.Play();

            if (_enemiesKilled >= _enemies.Count)
            {
                Restart();
            }
        }