Пример #1
0
        public override void OnEnter()
        {
            EnemyShip.ListOfShips.Clear();
            Bullet.ListOfBullets.Clear();
            explosions.Clear();

            Lifes        = 3;
            Points       = 0;
            playerIsDead = false;
            int playerShipYposition = GalagaGame.GAME_HEIGHT - 200;

#if WINDOWS
            game.KeyboardKeysDown   += KeysHoldDown;
            game.KeyboardKeyClicked += KeyClicked;
#elif ANDROID
            playerShipYposition -= 200;
            game.ScreenTapped   += ScreenTapped;
            game.ScreenTouched  += ScreenTouched;
#endif

            playerShip = new PlayerShip(GalagaGame.GAME_WIDTH / 2, playerShipYposition);

            enemyGrid = new EnemyGrid(new Vector2(100, 200));

            SpawnAllEnemies();

            gridMovingTimer = new Timer((t) => {
                enemyGrid.UpdateEnemyGridPosition(game.deltaTime);
                enemyAnimation = (enemyAnimation == 0) ? 1 : 0;
                foreach (RotatingShip s in RotatingShip.ListOfShips)
                {
                    if (s is EnemyShip)
                    {
                        EnemyShip en = (EnemyShip)s;
                        if (en.MovingOnGrid)
                        {
                            en.SetTexture(6 + enemyAnimation);
                        }
                    }
                }
            }, 800, true);

            // shoot automatically every 0.7s in Android version
#if ANDROID
            shootingTimer = new Timer((el) => {
                if (!RotatingShip.ListOfShips.Contains(playerShip))
                {
                    return;
                }

                Bullet b = new Bullet(playerShip.Hitbox.Center.X - 2 * RotatingShip.Scale, playerShip.Position.Y, BulletType.ALLY);
                GameEvent(GameEventEnum.PLAYER_FIRE);
            }, 700, true);
#endif
        }
Пример #2
0
        public void GameEvent(GameEventEnum ev)
        {
            switch (ev)
            {
            case GameEventEnum.ENEMY_DESTROYED:
                destroy_enemy.Play(0.5f, 0, 0);
                Points += 10;
                if (RotatingShip.ListOfShips.Count < 2)
                {
                    SpawnAllEnemies();
                }
                break;

            case GameEventEnum.PLAYER_DESTROYED:
                playerIsDead = true;
                explosion.Play(0.5f, 0, 0);
                Lifes--;
                if (Lifes < 1)
                {
                    GameEvent(GameEventEnum.GAME_OVER);
                }
                else
                {
                    Timer respawn = new Timer((t) => {
                        int playerShipYposition = GalagaGame.GAME_HEIGHT - 200;
#if ANDROID
                        playerShipYposition -= 200;
#endif
                        playerShip   = new PlayerShip(GalagaGame.GAME_WIDTH / 2, playerShipYposition);
                        playerIsDead = false;
                    },
                                              2000, false);
                }
                break;

            case GameEventEnum.PLAYER_FIRE:
                shot.Play(0.5f, 0, 0);
                break;

            case GameEventEnum.GAME_OVER:
                gridMovingTimer.Delete();
                Timer endDelay = new Timer((t) =>
                {
                    ExitGameMode();
                }, 2000, false);

                break;
            }
        }