public void SwitchToGame()
 {
     SetAllTransparent();
     currentState = GameLogic.GameState.Game;
     titleGUICanvas.SetActive(false);
     gameGUICanvas.SetActive(true);
     gameOverGUICanvas.SetActive(false);
     invincibilityLayer.SetActive(false);
 }
 public void SwitchToGameOver(bool newRecord, float lastDistance)
 {
     SetAllTransparent();
     currentState = GameLogic.GameState.GameOver;
     titleGUICanvas.SetActive(false);
     gameGUICanvas.SetActive(false);
     gameOverGUICanvas.SetActive(true);
     invincibilityLayer.SetActive(false);
     if (newRecord) {
         Color oldColor = newRecordText.color;
         newRecordText.color = new Color(oldColor.r,oldColor.g,oldColor.b, 1.0f);
     }
     else {
         Color oldColor = newRecordText.color;
         newRecordText.color = new Color(oldColor.r,oldColor.g,oldColor.b, 0.0f);
     }
     //lastScoreText.text = lastScore.ToString("N0");
     lastDistanceText.text = lastDistance.ToString("0.00");
 }
示例#3
0
 public GameState(GameState gameState)
 {
     //Pilot = gameState.Pilot;
     PlayerPosition = gameState.PlayerPosition;
 }
示例#4
0
 public void SetState(GameState gameState)
 {
     if (!IsFinished) State = gameState;
 }
 public void SwitchToTitle()
 {
     SetAllTransparent();
     currentState = GameLogic.GameState.Title;
     titleGUICanvas.SetActive(true);
     gameGUICanvas.SetActive(false);
     gameOverGUICanvas.SetActive(false);
     invincibilityLayer.SetActive(false);
     //topScoreText.text = HighscoreController.GetTopScore().ToString("N0");
     topDistanceText.text = HighscoreController.GetTopDistance().ToString("0.00");
 }
示例#6
0
 /// <summary>
 /// Az ellenségek és lövedékek mozgatása, törlése, stb
 /// </summary>
 private void Update(GameState nState, double elapsedTime)
 {
     for (int i = enemies.Count - 1; i >= 0; i--)
     {
         if (enemies[i].Health <= 0)
         {
             //akkor kapunk ha lelőttünk egy ellenséget
             _pilot.Money += enemies[i].value;
             Events.Enqueue(new KeyValuePair<GameEventType, GameEventData>(GameEventType.EnemyDestroyed,
                         new GameEventData { time = DateTime.Now, pos = new Vector2((float) enemies[i].PosX,(float) enemies[i].PosY)}));
             enemies.RemoveAt(i);
         } else
         {
             enemies[i].Move(elapsedTime);
             if (enemies[i].PosX < 0)
                 enemies.RemoveAt(i);
         }
         // TODO: ellenőrzés pályán vagyunk-e még
     }
     for (int i = 0; i < bullets.Count; ++i)
     {
         if (!bullets[i].active || bullets[i].PosX>2000)
             bullets.RemoveAt(i);
         else
             bullets[i].Move(elapsedTime);
         // TODO: ellenőrzés pályán vagyunk-e még
     }
     //játékos vége
     if (_pilot.Health <= 0)
     {
         enemies.Clear();
         bullets.Clear();
         Events.Enqueue(new KeyValuePair<GameEventType, GameEventData>(GameEventType.PlayerDead, new GameEventData { time = DateTime.Now }));
         _exiting++;
     }
     //pálya vége
     if (enemies.Count == 0 && _waitForLevelEnd)
     {
         enemies.Clear();
         bullets.Clear();
         _exiting++;
         if (_pilot.level != 10)
         {
             ++_pilot.level;
             Events.Enqueue(new KeyValuePair<GameEventType, GameEventData>(GameEventType.LevelEnd, new GameEventData { time = DateTime.Now }));
         } else
             Events.Enqueue(new KeyValuePair<GameEventType, GameEventData>(GameEventType.PlayerDead, new GameEventData { time = DateTime.Now }));
     }
 }
示例#7
0
        private void GameLoop()
        {
            var lastTime = DateTime.Now;
            while (_exiting == 0)
            {
                var elapsedTime = (DateTime.Now - lastTime).TotalMilliseconds;
                lastTime = DateTime.Now;
                if (!_paused)
                {
                    var dx = (Input.InputPos.X - CurrState.PlayerPosition.X)/1000* elapsedTime;
                    var dy = (Input.InputPos.Y - CurrState.PlayerPosition.Y)/1000* elapsedTime;

                    var nState = new GameState
                        {
                            PlayerPosition =
                                new Vector2((float) (CurrState.PlayerPosition.X + dx), (float) (CurrState.PlayerPosition.Y + dy)),
                        };

                    if (_cooldown > 0) _cooldown -= elapsedTime;
                    else if (Input.FirePressed)
                    {
                        CreateNewBullet();
                        Events.Enqueue(new KeyValuePair<GameEventType, GameEventData>(GameEventType.LaserFired, new GameEventData{ time = DateTime.Now}));
                        _cooldown = 250;
                    }

                    _pilot.SetPosition(_pilot.PosX + dx, _pilot.PosY + dy);

                    /*if (_rnd.Next(0, 100000) == 1 && enemies.Count(enemy => enemy.posX > 1500) < 10)
                    {
                        CreateNewEnemy();
                    }*/
                    if (_mapGen.AbleToCreateNewEnemy(elapsedTime) /*&& enemies.Count(enemy => enemy.posX < 1500) < 4*/ && !_waitForLevelEnd)
                    {
                        CreateNewEnemy(_mapGen.NewEnemyType());
                    }
                    else {
                        if (enemies.Count != 0)
                        { } }
                    Update(nState, elapsedTime);
                    CollisionCheck();

                    CurrState = nState;
                }
            }
            //++_exiting;
        }
示例#8
0
        public void Start()
        {
            enemies = new List<Enemy>();
            bullets = new List<Bullet>();

            _mapGen = new MapGenerator(_pilot.level);
            _mapGen.LevelUp += new EventHandler<EventArgs>(LevelUpHandler);

            _cooldown = 0;
            _rnd = new Random();

            var nState = new GameState {PlayerPosition = new Vector2(5,20)};

            Events = new ConcurrentQueue<KeyValuePair<GameEventType, GameEventData>>();

            CurrState = nState;
            _waitForLevelEnd = false;

            _pilot.SetPosition(Input.InputPos.X, Input.InputPos.Y);

            _gameThread = new Thread(GameLoop);
            _gameThread.IsBackground = true;
            _gameThread.Start();

            _exiting = 0;
        }