Esempio n. 1
0
        public void Update(GameTime gameTime)
        {
            //getting keyboard state
            KeyboardState keyState = Keyboard.GetState();

            //power up timer
            if ((int)power > 0)
            {
                timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (timer > interval)
                {
                    timer = 0;
                    power = powerUP.one;
                }
            }

            //boundingbox for our player ship
            boundinBox = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);

            //set rectangle for health bar
            healthRectangle = new Rectangle((int)healthBarPosition.X, (int)healthBarPosition.Y, health, 25);

            //Fire Bullets
            if (keyState.IsKeyDown(Keys.Space))
            {
                Shoot();
            }

            UpdateBullets();

            //controles of the player
            if (keyState.IsKeyDown(Keys.Up))
            {
                position.Y = position.Y - speed;
            }
            if (keyState.IsKeyDown(Keys.Left))
            {
                position.X = position.X - speed;
            }

            if (keyState.IsKeyDown(Keys.Down))
            {
                position.Y = position.Y + speed;
            }
            if (keyState.IsKeyDown(Keys.Right))
            {
                position.X = position.X + speed;
            }

            //ship stays in screen
            if (position.X <= 0)
            {
                position.X = 0;
            }

            if (position.X >= 750 - texture.Width)
            {
                position.X = 750 - texture.Width;
            }

            if (position.Y <= 0)
            {
                position.Y = 0;
            }

            if (position.Y >= 850 - texture.Height)
            {
                position.Y = 850 - texture.Height;
            }
        }
Esempio n. 2
0
        public void Update(GameTime gameTime)
        {
            //getting keyboard state
            KeyboardState keyState = Keyboard.GetState();

            //power up timer
            if ((int)power > 0)
            {
                timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (timer > interval)
                {
                    timer = 0;
                    power = powerUP.one;
                }
            }

            //boundingbox for our player ship
            boundinBox = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);

            //set rectangle for health bar
            healthRectangle = new Rectangle((int)healthBarPosition.X, (int)healthBarPosition.Y, health, 25);

            //Fire Bullets
            if( keyState.IsKeyDown(Keys.Space))
            {
                Shoot();
            }

            UpdateBullets();

            //controles of the player
            if (keyState.IsKeyDown(Keys.Up))
            {
                position.Y = position.Y - speed;
            }
            if (keyState.IsKeyDown(Keys.Left))
            {
                position.X = position.X - speed;
            }

            if (keyState.IsKeyDown(Keys.Down))
            {
                position.Y = position.Y + speed;
            }
            if (keyState.IsKeyDown(Keys.Right))
            {
                position.X = position.X + speed;
            }

            //ship stays in screen
            if (position.X <= 0)
                position.X = 0;

            if (position.X >= 750 - texture.Width)
                position.X = 750 - texture.Width;

            if (position.Y <= 0)
                position.Y = 0;

            if (position.Y >= 850 - texture.Height)
                position.Y = 850 - texture.Height;
        }