Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            getGametime(gameTime);
            //Get ship rotation
            var     deltaX     = Math.Sin(Rotation);
            var     deltaY     = -Math.Cos(Rotation);
            Vector2 moveVector = new Vector2((float)deltaX, (float)deltaY);

            if (currentShield == -1 && currentHealth == -1)
            {
                currentShield = maxShield;
                currentHealth = maxHealth;
                drawResources();
            }

            if (!_spawned)
            {
                _rocketHit       = (RocketHit)GameObjectHandler.Instance.FindGameObject("RocketHit");
                _shieldRegenLost = (ShieldRegenLost)GameObjectHandler.Instance.FindGameObject("ShieldRegenLost");
                _shieldLost      = (ShieldLost)GameObjectHandler.Instance.FindGameObject("ShieldLost");
                _autoLaserLost   = (AutoLaserLost)GameObjectHandler.Instance.FindGameObject("AutoLaserLost");
                _missileLost     = (MissileLost)GameObjectHandler.Instance.FindGameObject("MissileLost");
                _spawned         = true;
            }

            //All sorts of methods controlling the player
            Movement(moveVector);
            Animation();
            StayInsideSCreen();
            xpCalculator();
            ShootButton(moveVector, gameTime, Weapons.SemiLaser);
            ChangeWeapon();
            regainShield();
            shieldAbility();
            CheckDeath();


            if (gameTime.TotalGameTime.TotalMilliseconds > _msSinceLastHit + 200)
            {
                _rocketHit.Hide();

                _msSinceLastHit = gameTime.TotalGameTime.TotalMilliseconds;
            }

            if (gameTime.TotalGameTime.TotalMilliseconds > _msSinceLastFeedback + 2000)
            {
                _shieldRegenLost.Hide();
                _shieldLost.Hide();
                _autoLaserLost.Hide();
                _missileLost.Hide();
            }


            //What is keyboard and gamepad state?
            _keyState = Keyboard.GetState();
            _padState = GamePad.GetState(PlayerIndex.One);

            //Calculate delta time
            delta = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Experience


            //Run base Update
            base.Update(gameTime);
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public void LoadContent()
        {
            inputController1 = new InputController(PlayerIndex.One);


            AudioHandler.Instance.SetGameReference(gameReference);
            Spawner.Instance.SetGameReference(gameReference);

            gameSoundEffect                  = AudioHandler.Instance.LoadSoundEffect(AudioHandler.TypeOfSound.Game_Music);
            gameSoundEffectInstance          = gameSoundEffect.CreateInstance();
            gameSoundEffectInstance.Volume   = 0.2f;
            gameSoundEffectInstance.IsLooped = true;
            gameSoundEffectInstance.Play();

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(gameReference.GraphicsDevice);

            // TODO: use this.Content to load your game content here

            //Load textures
            backgroundTexture = gameReference.Content.Load <Texture2D>("Background_1280x720.png");

            //Temp GUI Weapon show
            Pause = gameReference.Content.Load <Texture2D>("Pause.png");


            //Make gameobjects
            Rocket _rocket = (Rocket)Spawner.Instance.Spawn(Spawner.TypeOfGameObject.Rocket, new Vector2(608, 328));

            _rocket.maxHealth = 10;
            _rocket.maxShield = 10;
            _rocket.Scale     = 0.7f;

            RocketHit _rocketHit = (RocketHit)Spawner.Instance.Spawn(Spawner.TypeOfGameObject.RocketHit, new Vector2(-1000, -1000));

            _rocketHit.Scale = 0.7f;

            AutoLaserLost _autoLaserLost =
                (AutoLaserLost)Spawner.Instance.Spawn(Spawner.TypeOfGameObject.AutoLaserLost, new Vector2(500, 20));

            _autoLaserLost.Scale = 2f;

            MissileLost _missileLost =
                (MissileLost)Spawner.Instance.Spawn(Spawner.TypeOfGameObject.MissileLost, new Vector2(500, 20));

            _missileLost.Scale = 2f;

            ShieldRegenLost _shieldRegenLost =
                (ShieldRegenLost)Spawner.Instance.Spawn(Spawner.TypeOfGameObject.ShieldRegenLost, new Vector2(500, 20));

            _shieldRegenLost.Scale = 2f;

            ShieldLost _shielLost =
                (ShieldLost)Spawner.Instance.Spawn(Spawner.TypeOfGameObject.ShieldLost, new Vector2(500, 20));

            _shielLost.Scale = 2f;


            UI ui = (UI)Spawner.Instance.Spawn(Spawner.TypeOfGameObject.UI, new Vector2(0, 640));


            //Controllers
            inputController1.InputGamePadLeftStickListeners.Add(_rocket);
        }