Exemplo n.º 1
0
    /// <summary>
    /// Instantiates projectiles
    /// </summary>
    /// <param name="fromPosition">Position, where projectiles start flying from</param>
    /// <param name="shootDirection">Direction in which to shoot projectiles</param>
    public void Shoot(Vector3 fromPosition, Vector3 shootDirection)
    {
        if (_shootingTimePassed > shootTreshold)
        {
            _shootingTimePassed = 0;

            // We use LookAt to instantiate projetiles on the right place. Projectiles should be comprised from 2 parts: center point and GameObject
            // which rotates around its center. GameObject is on the surface of the planet.
            // We also need -1 for projectiles to appear not on the other side of the planet.
            projectileTemplate.transform.LookAt(fromPosition * -1, fromPosition * -1 + shootDirection);

            // Let's create a bullet and add it to the pool.
            var bullet = new Bullet(Instantiate(projectileTemplate), projectileSpeed);
            bulletManager.Add(bullet);
            SoundManager.Instance.PlayShootingSound();
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            _fire_bullet_time += gameTime.ElapsedGameTime.TotalMilliseconds;
            int Highscore = 0;

            var ks = Keyboard.GetState();
            var ms = Mouse.GetState();

hack:
            switch (_state)
            {
            case CGameState.MainScreen:
                var ret = _mainscreen.Update(ms);
                if (ret.HasValue && (ret.Value == CGameState.Quit || ret.Value == CGameState.StartGame || ret.Value == CGameState.CreditsScreen))
                {
                    _state = ret.Value;
                    goto hack;
                }
                break;

            case CGameState.CreditsScreen:
                if (_creditsScreen == null)
                {
                    LoadCreditsScreen();
                }

                ret = _creditsScreen.Update(ms);
                if (ret.HasValue && ret.Value == CGameState.MainScreen)
                {
                    _state = ret.Value;
                    goto hack;
                }
                break;

            case CGameState.StartGame:
                LoadGame();
                break;

            case CGameState.Playing:
                if (ms.LeftButton == ButtonState.Pressed && _fire_bullet_time > 180)
                {
                    _bullet_manager.Add(_player.GetPosition(), _player.GetDirection());
                    _fire_bullet_time = 0;
                }

                _player.Update(ks, ms);
                _background_manager.Update(_wave_manager.WaveCount, _wave_manager.Highscore);
                _bullet_manager.Update();
                _bullet_hits_enemy.Update();
                _portal_manager.Update();
                _energy_storage_manager.Update();
                _powerup_manager.Update(gameTime, ref _player, ref _energy_storage_manager);
                _enemy_managers.Values
                .ToList()
                .ForEach(x => x.Update(ref Highscore, gameTime));
                _wave_manager.Update(gameTime, ref Highscore);
                //game over
                if (_energy_storage_manager._energy_storages.Count == 0)
                {
                    _state = CGameState.Gameover;
                    goto hack;
                }
                break;

            case CGameState.Gameover:
                if (_gameoverscreen == null)
                {
                    LoadGameOver(_wave_manager.Highscore);
                }
                ret = _gameoverscreen.Update(ms);
                if (ret.HasValue && ret.Value == CGameState.StartGame)
                {
                    _state = ret.Value;
                    goto hack;
                }
                else if (ret.HasValue && ret.Value == CGameState.Quit)
                {
                    _state = ret.Value;
                    goto hack;
                }
                break;

            case CGameState.Quit:
                Exit();
                break;
            }

            if (ks.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            base.Update(gameTime);
        }