Пример #1
0
 public void SetState(string a_name, GameState a_state)
 {
     _avaliableStates[a_name] = a_state;
 }
Пример #2
0
        //**********************************************************************
        //****************************** UPDATE ********************************
        //**********************************************************************
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Check: Is the game not running?
            if (currentState != GameState.RunningGame)
                UpdateSplashScreen();
            else
            {
                // THINGS TO DO WHILE GAME IS RUNNING
                k = Keyboard.GetState();
                dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

                // Check: Exit game?
                if (k.IsKeyDown(Keys.Escape)) currentState = GameState.EndScreen;

                // Check: Is player alive?
                if (!thePlayer.IsAlive)
                {
                    finalScore = currentScore;
                    ResetGame();
                }

                // PROJECTILE CONTROLS

                // Firing missiles: delay time between fires
                if (missileCountdown > 0)
                {
                    missileCountdown -= 0.0075f * dt;
                }
                else if (k.IsKeyDown(missileButton) && missileCountdown <= 0)
                {
                    FireMissile();
                    missileCountdown = 50;
                }

                // Dropping bombs: delay time between drops
                if (bombCountdown > 0)
                {
                    bombCountdown -= 0.005f * dt;
                }
                else if (k.IsKeyDown(bombButton) && bombCountdown <= 0)
                {
                    DropBomb();
                    bombCountdown = 50;
                }
                // ----------------------------------------------------------------

                // COLLISION HANDLING
                // ----------------------------------------------------------------
                // Missile-> Enemy collision handling
                foreach (PlayerMissile m in PlayerMissiles)
                {
                    // Check if off-screen
                    if (m.posX > borderRightX) m.Die();

                    foreach (Enemy e in Enemies)
                    {
                        // Logic
                        if (m.HitsEnemy(e))
                        {
                            e.Die();
                            m.Die();
                            currentScore += e.pointValue;
                        }
                    }
                    return;
                }

                // BombExplosion-> Enemy collision handling
                foreach (BombExplosion be in BombExplosions)
                {
                    foreach (Enemy e in Enemies)
                    {
                        // Logic
                        if (be.CollideWithEnemy(e))
                        {
                            e.Die();
                            currentScore += e.pointValue * 2 / 3;
                        }
                    }
                    return;
                }

                // Enemy-> Player collision handling
                foreach (Enemy e in Enemies)
                {
                    // Check if off-screen
                    if (e.posX < borderLeftX) e.Die();

                    // Collision with player?
                    if (e.CollideWithPlayer())
                    {
                        e.Die();
                        thePlayer.Damage(20);
                        currentScore += e.pointValue / 5;
                    }
                    return;

                    // Attack logic?
                }

                // EnemyBullet-> Player collision handling
                foreach (EnemyBullet eb in EnemyBullets)
                {
                    // Check if off-screen
                    if (eb.posX < borderLeftX) eb.Die();
                    else if (eb.posX > borderRightX) eb.Die();

                    // Collision with player?
                    if (eb.HitsPlayer(thePlayer))
                    {
                        eb.Die();
                        thePlayer.Damage(10);
                    }
                    return;
                }
                // ----------------------------------------------------------------

                // Enemy generation
                // ----------------------------------------------------------------
                // ----------------------------------------------------------------
            }

            base.Update(gameTime);
        }
Пример #3
0
        private void UpdateSplashScreen()
        {
            KeyboardState keyState = Keyboard.GetState();
            if (keyState.IsKeyDown(Keys.Enter))
            {
                currentState = GameState.RunningGame;

            }
        }
Пример #4
0
        // Reset the game
        public void ResetGame()
        {
            Enemies.Clear();
            EnemyBullets.Clear();
            PlayerMissiles.Clear();
            PlayerBombs.Clear();
            BombExplosions.Clear();

            currentScore = 0;
            thePlayer.Health = 100;
            thePlayer.IsAlive = true;
            thePlayer.Position = playerstart;

            currentState = GameState.EndScreen;
        }