protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit ------------------

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            RunningState.set_state(0);


            input.Update();                             // Update the inputs
            MouseState myMouseState = Mouse.GetState(); // Updates the mouse state

            //Go through each button currently on screen and change their status ------

            int limit = ButtonList.Count;

            for (int i = 0; i < limit; i++)
            {
                ButtonList[i].UpdateState(myMouseState);   //Update the button state based on where the mouse is pointing

                if (ButtonList[i].isPressed())             //Check if the button is pressed or not, if it is then the program needs to go onto the function list
                {
                    TitleFunctions(ButtonList[i].Get_Name());
                }
            }
            base.Update(gameTime);
        }
示例#2
0
    public ScreenSelect()
    {
        RunningState.set_state(1); //Set to 1 for title

        do
        {
            switch (RunningState.get_state())
            {
            case (1):     //1 for title screen
                using (var game = new TitleScreen())
                    game.Run();
                break;

            case (2):     //2 for game screen
                using (var game = new GameScreen())
                    game.Run();
                break;

            case (3):     //3 for death screen
                using (var game = new DeathScreen())
                    game.Run();
                break;
            }
        } while (RunningState.get_state() != 0); //Run the game until the running state is at 0, where the game will exit
    }
示例#3
0
 /// <summary>
 /// UnloadContent will be called once per game and is the place to unload
 /// all content.
 /// </summary>
 protected override void UnloadContent()
 {
     if (player.isDead == true)
     {
         this.Exit();
         RunningState.set_state(3);
     }
     else
     {
         RunningState.set_state(1);
     }
 }
        // Determine what happens when a button is pressed ---

        protected void TitleFunctions(string button_ID)
        {
            if (button_ID == "new_game")
            {
                RunningState.setPreviousState(1);
                RunningState.set_state(2); // Continue to the running game screen
                quit_window();
            }
            else if (button_ID == "exit")
            {
                RunningState.set_state(0); // Exit the game
                quit_window();
            }
        }
示例#5
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)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
        {
            this.Exit();
        }
        if (player.isDead == true)
        {
            RunningState.setScore(player.score);
            this.Exit();
            RunningState.set_state(3);
        }

        timeSinceScore += (float)gameTime.ElapsedGameTime.TotalSeconds;

        if (timeSinceScore > 2f)
        {
            player.score  += 100;
            timeSinceScore = 0f;
        }



        input.Update();
        player.Update(gameTime);
        enemy.Update(gameTime);
        UpdateBullets();

        if ((input.IsKeyDown(Keys.Z)))
        {
            player.spriteManager.setCurrentAction("shoot");
            if (input.WasKeyPressed(Keys.Z))
            {
                Shoot();
            }
        }

        else if ((input.IsKeyDown(Keys.Z)) && (input.IsKeyDown(Keys.Left)))
        {
            player.spriteManager.setCurrentAction("run+shoot");
            if (input.WasKeyPressed(Keys.Z))
            {
                player.velocity.X = -5 * player.speed;
                player.spriteManager.setCurrentDirection("left");
                player.isLeft = true;
                Shoot();
            }
        }

        else if ((input.IsKeyDown(Keys.Z)) && (input.IsKeyDown(Keys.Right)))
        {
            player.spriteManager.setCurrentAction("run+shoot");
            if (input.WasKeyPressed(Keys.Z))
            {
                player.velocity.X = 5 * player.speed;
                player.spriteManager.setCurrentDirection("right");
                player.isLeft = false;
                Shoot();
            }
        }

        else if ((input.IsKeyDown(Keys.Space)))
        {
            player.spriteManager.setCurrentAction("jump");
            if (player.hasJumped == false)
            {
                player.position.Y -= 10f;
                player.velocity.Y  = -9;
                player.hasJumped   = true;
            }
        }

        else if ((input.IsKeyDown(Keys.Left)) && (input.IsKeyDown(Keys.Down)))
        {
            player.velocity.X = -5 * player.speed;
            player.spriteManager.setCurrentDirection("left");
            player.spriteManager.setCurrentAction("slide");
            player.isLeft = true;
        }

        else if ((input.IsKeyDown(Keys.Right)) && (input.IsKeyDown(Keys.Down)))
        {
            player.velocity.X = 5 * player.speed;
            player.spriteManager.setCurrentDirection("right");
            player.spriteManager.setCurrentAction("slide");
            player.isLeft = false;
        }

        else if (input.IsKeyDown(Keys.Left))
        {
            player.velocity.X = -5 * player.speed;
            player.spriteManager.setCurrentDirection("left");
            player.spriteManager.setCurrentAction("run");
            player.isLeft = true;
        }

        else if (input.IsKeyDown(Keys.Right))
        {
            player.velocity.X = 5 * player.speed;
            player.spriteManager.setCurrentDirection("right");
            player.spriteManager.setCurrentAction("run");
            player.isLeft = false;
        }


        else
        {
            player.velocity.X = 0;
            player.spriteManager.setCurrentAction("idle");
        }


        foreach (PlatformTiles tile in map.CollisionTiles)
        {
            player.PlatformCollsion(tile.Rectangle, map.Width, map.Height, camera.bottom_edge, camera.top_edge);
            enemy.Collision(tile.Rectangle, map.Width, map.Height);
            camera.Update(player.position, map.Width, map.Height, gameTime, player);
        }

        //for (int j = 0; j < bullets.Count; j++)
        //{
        //    if (bullets[j].TrapCollsion(bullets[j].rectangle, map.Width, map.Height, map.TrapTiles[j]))
        //    {
        //        BackgroundTiles newTile = new BackgroundTiles("0", map.TrapTiles[j].Rectangle);
        //        map.TrapTiles.RemoveAt(j);
        //        map.BackgroundTiles.Insert(j+1, newTile);

        //    }

        //}
        for (int i = 0; i < map.TrapTiles.Count; i++)
        {
            player.TrapCollsion(map.TrapTiles[i].Rectangle, map.Width, map.Height);
            foreach (Bullet bullet in bullets)
            {
                bullet.TrapCollsion(map.TrapTiles[i].Rectangle, map.Width, map.Height, map.TrapTiles[i], player);
            }
        }

        for (int i = 0; i < map.TrapTiles.Count; i++)
        {
            if (map.TrapTiles[i].isVisible == false)
            {
                BackgroundTiles newTile = new BackgroundTiles("0", map.TrapTiles[i].Rectangle);
                map.TrapTiles.RemoveAt(i);
                map.BackgroundTiles.Insert(i, newTile);
            }
        }



        base.Update(gameTime);
    }