Example #1
0
        /// <summary>
        ///     Se llama en cada frame.
        ///     Se debe escribir toda la lógica de computo del modelo, así como también verificar entradas del usuario y reacciones
        ///     ante ellas.
        /// </summary>
        protected override void Update(GameTime gameTime)
        {
            // Capturar Input teclado
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.UnloadContent();
                Exit();
            }

            if (State == GameState.Playing)
            {
                UpdateLightPosition((float)gameTime.ElapsedGameTime.TotalSeconds);
                TargetLightCamera.Position = LightPosition;
                TargetLightCamera.BuildView();

                _timeSpan -= gameTime.ElapsedGameTime;
                if (_timeSpan < TimeSpan.Zero || _health < 0)
                {
                    State = GameState.GameOver;
                }


                UpdateCamera();
                MoveSpaceship(gameTime);
                InputController(gameTime);

                movementSpeed = gameTime.ElapsedGameTime.Milliseconds / 500.0f * _gameSpeed;
                MoveForward(ref _spaceshipPosition, _spaceshipRotation, movementSpeed);

                EM.Update(gameTime, centerPosition);

                CollisionType laserCollision = EM.UpdateEnemigoVigilante(_spaceshipPosition, gameTime, movementSpeed, _health);
                if (laserCollision == CollisionType.Laser && !gmode)
                {
                    _health -= 2;
                }

                venusRotation += .005f;

                _laserManager.UpdateLaserAndCheckCollision(movementSpeed, _spaceshipPosition, _health);

                shipSphere = new BoundingSphere(_spaceshipPosition, 0.09f);
                CollisionType collisionType = CheckCollision(shipSphere);
                if (collisionType != CollisionType.None)
                {
                    if (collisionType == CollisionType.Trench)
                    {
                        _spaceshipPosition = new Vector3(8, 7, -3);
                        _spaceshipRotation = Quaternion.Identity;
                        if (!gmode)
                        {
                            _health -= 10;
                        }
                    }
                }

                if (_actualCheckpoint < 10)
                {
                    venusSphere = new BoundingSphere(checkpoints[_actualCheckpoint], 0.5f);
                    if (shipSphere.Intersects(venusSphere))
                    {
                        _actualCheckpoint++;
                    }
                }

                if (_actualCheckpoint >= 10)
                {
                    BoundingSphere TgcBound = new BoundingSphere(finalBossPosition, 0.09f);
                    if (shipSphere.Intersects(TgcBound))
                    {
                        State = GameState.Win;
                    }
                }
            }

            base.Update(gameTime);
        }