예제 #1
0
        private void UpdatePlayerShots(GameTime gameTime)
        {
            // if we are allowed to fire, add a shot to the list
            if (_player != null && InputManager.ControlState.Fire && gameTime.TotalGameTime.TotalMilliseconds - _lastTime > 500)
            {
                // create a new shot over the ship
                PlayerShot ps = new PlayerShot();
                ps.Position = new Vector2((_player.Position.X + _player.Width / 2.0f) - ps.Width / 2.0f, _player.Position.Y - ps.Height);
                _playerShots.Add(ps);
                _lastTime = gameTime.TotalGameTime.TotalMilliseconds;
                AudioManager.PlayCue(AudioManager.Cue.PlayerShot);
            }

            // enumerate the player shots on the screen
            for (int i = 0; i < _playerShots.Count; i++)
            {
                PlayerShot playerShot = _playerShots[i];

                playerShot.Update(gameTime);

                // if it's off the top of the screen, remove it from the list
                if (playerShot.Position.Y + playerShot.Height < 0)
                {
                    _playerShots.RemoveAt(i);
                }
            }
        }
예제 #2
0
    public void Run()
    {
        const int      NUM_ENEMIES = 4;
        ConsoleKeyInfo userkey;

        Spaceship        ship = new Spaceship();
        MovingBackground back = new MovingBackground();
        Scoreboard       sb   = new Scoreboard();

        Enemy[] enemies = new Enemy[NUM_ENEMIES];
        enemies[0] = new EnemyLevel1();
        enemies[1] = new EnemyLevel2();
        enemies[2] = new EnemyLevel3();
        enemies[3] = new EnemyLevel4();
        Mothership ms    = new Mothership();
        PlayerShot shot1 = new PlayerShot(20, 10);
        EnemyShot  shot2 = new EnemyShot(15, 1);

        while (true)
        {
            // Update elements position and appearance
            back.Update();
            ms.Update();
            ship.Update();
            foreach (Enemy e in enemies)
            {
                e.Update();
            }
            shot1.Update();
            shot2.Update();

            // Screen update
            Console.Clear();
            back.Draw();
            sb.Draw();
            ms.Draw();
            ship.Draw();
            foreach (Enemy e in enemies)
            {
                e.Draw();
            }
            shot1.Draw();
            shot2.Draw();

            // Get user input
            userkey = Console.ReadKey(true);
            switch (userkey.Key)
            {
            case ConsoleKey.A: ship.MoveLeft(); break;

            case ConsoleKey.D: ship.MoveRight(); break;

            case ConsoleKey.Escape: return;
            }
        }
    }
예제 #3
0
        private void UpdatePlayerShots(GameTime gameTime)
        {
            // enumerate the player shots on the screen
            for (int i = 0; i < _playerShots.Count; i++)
            {
                PlayerShot playerShot = _playerShots[i];

                playerShot.Update(gameTime);

                // if it's off the top of the screen, remove it from the list
                if (playerShot.Position.Y + playerShot.Height < 0)
                {
                    _playerShots.RemoveAt(i);
                }
            }
        }