Пример #1
0
        protected override void Update(GameTime gameTime)
        {
            keyboardState = Keyboard.GetState();
            mouseState    = Mouse.GetState();

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

            player.Update(walls, isFacingLeft);
            playerShadow.Update(player.Position);

            if (camera.GetWorldPosition(new Vector2(Mouse.GetState().X, Mouse.GetState().Y)).X < player.Position.X + (player.Rectangle.Width) / 2) // Is the player turned left?
            {
                isFacingLeft = true;                                                                                                               // Yes
                gun.Shoot(bullets, bulletTex, 0, effect);
            }
            else
            {
                isFacingLeft = false; // No
                gun.Shoot(bullets, bulletTex, gunRightTex.Width, effect);
            }

            for (int i = 0; i < bullets.Count; i++) // Move bullets
            {
                bullets[i].Move();
            }

            for (int i = 0; i < walls.Count; i++) // Kollision med väggar
            {
                for (int j = 0; j < bullets.Count; j++)
                {
                    if (walls[i].Rectangle.Intersects(bullets[j].Rectangle)) // Platform & Bullet collision
                    {
                        bullets.RemoveAt(j);
                        j--;
                    }
                }
            }
            player.UpdateHitbox();

            if (isFacingLeft)
            {
                gun.Update(camera, player.Position, gunLeftTex);
            }
            else
            {
                gun.Update(camera, player.Position, gunRightTex);
            }

            telepadBase.Update();
            telepadCrystal.Update();

            camera.MoveCamera(player.Position);

            camera.UpdateCamera(GraphicsDevice.Viewport);

            base.Update(gameTime);
        }
Пример #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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            camera.UpdateCamera(GraphicsDevice.Viewport);
            base.Update(gameTime);
        }
Пример #3
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            player.Update(map);

            //Updatera Fiende och hjälp
            foreach (ObjectBase thing in UpdateLista)
            {
                thing.Update();
                if (thing.Dead)
                {
                    DeadLista.Add(thing);
                }
            }

            // Om blocken är döda ta bort dem från uppdateringslistan
            // Inte i samma loop för då fungerar ej foreach loopen korrekt
            foreach (ObjectBase Deadthing in DeadLista)
            {
                UpdateLista.Remove(Deadthing);
            }
            DeadLista.Clear();

            //"randomly" spawna in nya fiende
            if (r.Next(0, 70) == 1)
            {
                UpdateLista.Add(new Fiende(player, map));
            }

            // Skapa ett "hjälpblock" var 10onde sekund;
            if (gameTime.TotalGameTime.TotalSeconds > nextHelpBlock)
            {
                UpdateLista.Add(new Helpobject(player, map));
                nextHelpBlock += 10;
            }

            //Kolla om spelaren är under kartan och där med förlorat
            if (player.Pos.Y > 500)
            {
                gameOver = true;
            }

            camera.UpdateCamera(GraphicsDevice.Viewport);

            camera.Position = player.Rec.Location.ToVector2();


            base.Update(gameTime);
        }
Пример #4
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            KeyboardState kstate = Keyboard.GetState();

            if (kstate.IsKeyDown(Keys.W) && cubePos.X < graphics.PreferredBackBufferWidth - cubePos.Width)
            {
                cubePos.X += 10;
            }
            camera.Position = cubePos.Center.ToVector2();
            camera.UpdateCamera(GraphicsDevice.Viewport);
            base.Update(gameTime);
        }