Beispiel #1
0
        private void loadNewLevel()
        {
            if (previousGameState == Game1.GameState.Fail)
            {
                level--;
                previousGameState = Game1.GameState.Start;
            }

            level++;

            // Clear current lists
            bears.Clear();
            shots.Clear();
            deadBears.Clear();
            trees.Clear();
            mushrooms.Clear();
            houses.Clear();
            outOfBoundTrees.Clear();
            ground.Clear();

            rabbit = new Bear(carrotModel, ((Game1)Game).camera.cameraPosition - new Vector3(0, 0, -5), Vector3.Zero);

            this.addMushrooms(50);
            this.addTrees(4 * level);
            this.addHouses(5);
            this.addBears(6 * level);
            this.addGround();
        }
Beispiel #2
0
 private void MenuItemClick(bool IsClick, Game1.GameState gameState)
 {
     if (IsClick)
     {
         _cursorState = CursorState.Hand;
         if (Mouse.GetState().LeftButton == ButtonState.Pressed)
         {
             ((Game1)Game).gameState = gameState;
             if (!((Game1)Game).IsGameStateChanged)
             {
                 ((Game1)Game).IsGameStateChanged = true;
             }
         }
     }
 }
 public void SetData(string main, Game1.GameState currGameState)
 {
     textToDraw = main;
     this.currentGameState = currGameState;
     switch (currentGameState)
     {
         case Game1.GameState.START:
         case Game1.GameState.LEVEL_CHANGE:
             secondaryTextToDraw = "Press ENTER to begin";
             break;
         case Game1.GameState.END:
             secondaryTextToDraw = "Press ENTER to quit";
             break;
     }
 }
        public void SetData(string main, Game1.GameState currGameState)
        {
            textToDraw = main;
            this.currentGameState = currGameState;

            switch (currentGameState)
            {
                case Game1.GameState.START:
                case Game1.GameState.LEVEL_CHANGE:
                    secondaryTextToDraw = "Press Enter To Begin The game";
                    break;
                case Game1.GameState.END:
                    secondaryTextToDraw = "Press Enter to Exit The game";
                    break;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Initialize class variables
        /// </summary>
        /// <param name="bg">Background texture</param>
        /// <param name="bot1">play button texture</param>
        /// <param name="bot2">continue button texture</param>
        /// <param name="bot3">exit button texture</param>
        /// <param name="sound">click sound</param>
        /// <param name="gd">graphics manager</param>
        /// <param name="status">game state</param>
        /// <param name="saveexists">If a safe file is found</param>
        public void Initialize(Texture2D bg, Texture2D bot1, Texture2D bot2, Texture2D bot3, Texture2D texturaTitulo, SoundEffect sound, GraphicsDevice gd, Game1.GameState status, bool saveexists)
        {
            this.MyGraphics     = gd;
            this.bIsSaved       = saveexists;
            this.MyStatus       = status;
            this.Background     = bg;
            this.PlayButton     = bot1;
            this.ContinueButton = bot2;
            this.ExitButton     = bot3;
            this.SelectSound    = sound;

            this.title = texturaTitulo;

            //Definen los rectangulos sobre los que se pintan los botones
            this.Button1 = new Rectangle((MyGraphics.Viewport.Width / 2) - PlayButton.Width / 2, (MyGraphics.Viewport.Height / 2) - (int)PlayButton.Height + 20, PlayButton.Width, PlayButton.Height);
            this.Button2 = new Rectangle((MyGraphics.Viewport.Width / 2) - PlayButton.Width / 2, MyGraphics.Viewport.Height / 2 + 20, PlayButton.Width, PlayButton.Height);
            this.Button3 = new Rectangle((MyGraphics.Viewport.Width / 2) - PlayButton.Width / 2, (MyGraphics.Viewport.Height / 2) + (int)ExitButton.Height + 20, PlayButton.Width, PlayButton.Height);
        }
Beispiel #6
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            if (currentGameState == Game1.GameState.Start)
            {
                level             = 0;
                previousGameState = Game1.GameState.Start;
            }

            if (currentGameState == Game1.GameState.Fail)
            {
                previousGameState = Game1.GameState.Fail;
            }

            if (currentGameState == Game1.GameState.Initial)
            {
                loadNewLevel();
            }

            base.Update(gameTime);
        }
Beispiel #7
0
 /// <summary>
 /// Update
 /// </summary>
 /// <param name="deltaTime">time between frames</param>
 /// <param name="touchPosition">screen touch location</param>
 public void Update(float deltaTime, Vector2 touchPosition, TouchLocationState TouchState)
 {
     if (TouchState == TouchLocationState.Released)
     {
         //If a save file is found we show the Continue button
         if (bIsSaved)
         {
             if (Button1.Intersects(new Rectangle((int)touchPosition.X, (int)touchPosition.Y, 0, 0)))
             {
                 SelectSound.Play();
                 this.MyStatus = Game1.GameState.INGAME;
             }
             else if (Button2.Intersects(new Rectangle((int)touchPosition.X, (int)touchPosition.Y, 0, 0)))
             {
                 SelectSound.Play();
                 this.MyStatus = Game1.GameState.LOADGAME;
             }
             else if (Button3.Intersects(new Rectangle((int)touchPosition.X, (int)touchPosition.Y, 0, 0)))
             {
                 SelectSound.Play();
                 this.MyStatus = Game1.GameState.EXIT;
             }
         }
         //If no asve file
         else
         {
             if (Button1.Intersects(new Rectangle((int)touchPosition.X, (int)touchPosition.Y, 0, 0)))
             {
                 SelectSound.Play();
                 this.MyStatus = Game1.GameState.INGAME;
             }
             else if (Button2.Intersects(new Rectangle((int)touchPosition.X, (int)touchPosition.Y, 0, 0)))
             {
                 SelectSound.Play();
                 this.MyStatus = Game1.GameState.EXIT;
             }
         }
     }
 }
Beispiel #8
0
 public StateChanger(Game1.GameState s)
 {
     this.s = s;
 }
Beispiel #9
0
 public void setGameState(Game1.GameState state)
 {
     currentGameState = state;
 }
Beispiel #10
0
        // update method
        public void Update(GameTime gameTime, Game1.GameState gameState)
        {
            if (gameState == Game1.GameState.PLAY)
            {
                #region collision
                //checks for collisions with room's bounding box
                foreach (GameComponent g in game.Components)
                {
                    if (g is Room)
                    {
                        Room r = (Room)g;
                        currentRoom = r.GetID();

                        //collision logic
                        Rectangle b = r.Boundary;
                        SetBoundary(b);
                        if (!b.Contains(this.boundingBox))
                        {
                            contained = false;
                        }
                    }
                    else if (g is Door)
                    {
                        Door d = (Door)g;

                        //collision logic
                        Rectangle b        = d.getActivationArea();
                        bool      isActive = d.getActive();
                        if (b.Intersects(this.boundingBox) && isActive)
                        {
                            inArea      = true;
                            newPosition = d.getExitLocation();
                            newRoom     = d.getDestination();
                        }
                    }
                    else if (g is NPC)
                    {
                        NPC n = (NPC)g;

                        //collision logic
                        Rectangle b = n.getActivationArea();
                        //bool isActive = d.getActive();
                        if (b.Intersects(this.boundingBox))
                        {
                            nearNPC = true;
                        }
                    }
                }

                #endregion

                #region input
                KeyboardState keyboardState = Keyboard.GetState();
                ms = Mouse.GetState();

                //activation if player is in activation area
                if (keyboardState.IsKeyDown(Keys.E) && inArea == true && teleportReleased)
                {
                    displayActivationMessage = true;
                    inArea = false;
                    // Maybe but the changeLevel method somewhere else? can't access from here
                    // ((Game1)Game).ChangeLevel(currentRoom, newRoom);

                    //this.DrawOrder = 20;
                    this.position    = newPosition;
                    teleportReleased = false;
                }

                if (keyboardState.IsKeyDown(Keys.E) && nearNPC == true)
                {
                    // in the future, we'll have this display dialogue to give guests
                    nearNPC = false;
                    // ((Game1)Game).ChangeGameState(Game1.GameState.WIN);
                }

                if (keyboardState.IsKeyUp(Keys.E))
                {
                    teleportReleased = true;
                    inArea           = false;
                    nearNPC          = false;
                }

                //logic for animation
                if (direction == Facing.Left)
                {
                    drawRectangle.Y = texture.Height / spriteRows;
                }
                else if (direction == Facing.Right)
                {
                    drawRectangle.Y = 0;
                }

                //move the sprite with WASD
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    direction = Facing.Right;
                    if (position.X < boundary.Right)
                    {
                        position.X += 5;
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.A))
                {
                    direction = Facing.Left;
                    if (position.X > boundary.Left)
                    {
                        position.X -= 5;
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.W))
                {
                    if (position.Y > boundary.Top)
                    {
                        position.Y -= 5;
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.S))
                {
                    if (position.Y < boundary.Bottom)
                    {
                        position.Y += 5;
                    }
                }

                contained = true;

                // weapon handling
                if (keyboardState.IsKeyDown(Keys.Space))
                {
                    weapon.shoot(position + bulletOrigin, direction);
                }
                if (keyboardState.IsKeyDown(Keys.R))
                {
                    weapon.reload();
                }

                // changing weapons
                if (keyboardState.IsKeyDown(Keys.D1))
                {
                    if (hasMelee == true)
                    {
                        game.Components.Remove(weapon);
                        weapon = melee;
                        game.Components.Add(weapon);
                    }
                }
                if (keyboardState.IsKeyDown(Keys.D2))
                {
                    if (hasPistol == true)
                    {
                        game.Components.Remove(weapon);
                        weapon = pistol;
                        game.Components.Add(weapon);
                    }
                }
                if (keyboardState.IsKeyDown(Keys.D3))
                {
                    if (hasAssaultRifle == true)
                    {
                        game.Components.Remove(weapon);
                        weapon = assaultRifle;
                        game.Components.Add(weapon);
                    }
                }
                if (keyboardState.IsKeyDown(Keys.D4))
                {
                    if (hasShotgun == true)
                    {
                        game.Components.Remove(weapon);
                        weapon = shotgun;
                        game.Components.Add(weapon);
                    }
                }
                #endregion

                #region animate

                // check for movement
                if (position.X == prevX && position.Y == prevY)
                {
                    animate    = false;
                    frameCount = 0;
                }
                else
                {
                    animate = true;
                }

                // if player is moving, animate
                if (animate)
                {
                    if (frameCount == animationSpeed)
                    {
                        // check for rollover on sprite strip
                        if ((drawRectangle.X + drawRectangle.Width) > (texture.Width - drawRectangle.Width))
                        {
                            drawRectangle.X = 0;
                        }
                        else
                        {
                            drawRectangle.X += drawRectangle.Width;
                        }

                        // restart timer
                        frameCount = 0;
                    }
                }

                // increment animation assets as appropriate
                frameCount += 1;
                prevX       = position.X;
                prevY       = position.Y;

                //set previous position
                previousPosition = position;
                #endregion

                //ends the game if player's health is 0, will later go to menus
                if (health <= 0)
                {
                    //((Game1)Game).ChangeGameState(Game1.GameState.LOSE);
                }

                boundingBox.X = (int)position.X;
                boundingBox.Y = (int)position.Y;
            }
        }
        public void SetData(string main, Game1.GameState currGameState)
        {
            textToDraw = main;
            this.currentGameState = currGameState;

            #if(XBOX360)
            string buttons = "START";
            #else
            string buttons = "ENTER or the GamePad's START BUTTON";
            #endif

            switch (currentGameState)
            {
                case Game1.GameState.START:
                case Game1.GameState.LEVEL_CHANGE:
                    secondaryTextToDraw = "Press " + buttons + " to begin";
                    break;
                case Game1.GameState.END:
                    secondaryTextToDraw = "Press " + buttons + " to quit";
                    break;
            }
        }
Beispiel #12
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            keyboardState = Keyboard.GetState();
            //get the keystates
            bool sDown = keyboardState.IsKeyDown(Keys.S);
            bool downDown = keyboardState.IsKeyDown(Keys.Down);
            bool wDown = keyboardState.IsKeyDown(Keys.W);
            bool upDown = keyboardState.IsKeyDown(Keys.Up);
            bool escDown = keyboardState.IsKeyDown(Keys.Escape);
            bool enter = keyboardState.IsKeyDown(Keys.Enter);

            //need to save whatever the previous menu was so we can go back to that
            //when we do the esc key
            if (previousGameState == Game1.GameState.MainMenu)
                savedGameState = Game1.GameState.MainMenu;
            if (previousGameState == Game1.GameState.PauseMenu)
                savedGameState = Game1.GameState.PauseMenu;
            if (previousGameState == Game1.GameState.GameOver)
                savedGameState = Game1.GameState.GameOver;

            switch(Game1.currentGameState)
            {
                case Game1.GameState.StartUp:
                    #region Start Up
                    msSinceStart += gameTime.ElapsedGameTime.Milliseconds;
                    if(!keyDown && enter)
                        msSinceStart = 6001;
                    if (msSinceStart > 6000)
                        Game1.currentGameState = Game1.GameState.MainMenu;
                    #endregion
                    break;
                case Game1.GameState.MainMenu:
                    #region Main Menu
                    msSinceWin = 0;
                    MediaPlayer.Stop();
                    noMusic = true;
                    selMax = menuOps.Count-1;
                    if (!keyDown && (sDown || downDown))
                    {
                        keyDown = true;
                        moveDown = true;
                    }
                    if (!keyDown && (wDown || upDown))
                    {
                        keyDown = true;
                        moveUp = true;
                        moveDown = false; //ignore down
                    }
                    if (moveDown)
                    {
                        sel++;
                        if (sel > selMax)
                            sel = 0;
                        moveDown = false;
                    }
                    if (moveUp)
                    {
                        sel--;
                        if (sel < 0)
                            sel = selMax;
                        moveUp = false;
                    }

                    if (!keyDown && enter)
                    {
                        enter = false; //reset for next time
                        if (sel == 0) Game1.currentGameState = Game1.GameState.NewGame;
                        if (sel == 1) Game1.currentGameState = Game1.GameState.InstructionScreen;
                        if (sel == 2) Game1.currentGameState = Game1.GameState.Credits;
                        if (sel == 3) Game1.currentGameState = Game1.GameState.GameExit;
                    }
                #endregion
                    break;
                case Game1.GameState.InstructionScreen:
                    #region Instruction Screen area
                    if (escDown)
                        Game1.currentGameState = savedGameState;
                    #endregion
                    break;
                case Game1.GameState.InGame:
                    #region In Game
                    if (noMusic)
                    {
                        noMusic = false;
                        Game1.audioManager.playBackgroundMusic();
                    }
                    if (!keyDown && escDown)
                    {
                        Game1.currentGameState = Game1.GameState.PauseMenu;
                    }
                    #endregion
                    break;
                case Game1.GameState.PauseMenu:
                    #region Pause Menu
                    selMax = pauseOps.Count - 1;
                    noMusic = true;
                    MediaPlayer.Pause();
                    if (!keyDown && (sDown || downDown))
                    {
                        keyDown = true;
                        moveDown = true;
                    }
                    if (!keyDown && (wDown || upDown))
                    {
                        keyDown = true;
                        moveUp = true;
                        moveDown = false; //ignore down
                    }
                    if (moveDown)
                    {
                        sel++;
                        if (sel > selMax)
                            sel = 0;
                        moveDown = false;
                    }
                    if (moveUp)
                    {
                        sel--;
                        if (sel < 0)
                            sel = selMax;
                        moveUp = false;
                    }

                    if (enter)
                    {
                        enter = false; //reset for next time
                        if (sel == 0) Game1.currentGameState = Game1.GameState.InGame;
                        if (sel == 1) Game1.currentGameState = Game1.GameState.InstructionScreen;
                        if (sel == 2) Game1.currentGameState = Game1.GameState.GameExit;
                    }
                    #endregion
                    break;
                case Game1.GameState.Credits:
                    #region Credits
                    //Game1.audioManager.playCredits();
                    //won't play audio correctly, leaving out
                    noMusic = true;
                    if (!keyDown && escDown)
                        Game1.currentGameState = savedGameState;
                    #endregion
                    break;
                case Game1.GameState.YouWin:
                    #region You Win
                    msSinceWin += gameTime.ElapsedGameTime.Milliseconds;
                    if(!keyDown && enter)
                        msSinceWin = 5001;
                    if (msSinceWin > 5000)
                        Game1.currentGameState = Game1.GameState.MainMenu;
                    #endregion
                    break;
                case Game1.GameState.GameOver:
                    #region GameOver
                    MediaPlayer.Stop();
                    noMusic = true;
                    selMax = gameOverOps.Count - 1;
                    if (!keyDown && (sDown || downDown))
                    {
                        keyDown = true;
                        moveDown = true;
                    }
                    if (!keyDown && (wDown || upDown))
                    {
                        keyDown = true;
                        moveUp = true;
                        moveDown = false; //ignore down
                    }
                    if (moveDown)
                    {
                        sel++;
                        if (sel > selMax)
                            sel = 0;
                        moveDown = false;
                    }
                    if (moveUp)
                    {
                        sel--;
                        if (sel < 0)
                            sel = selMax;
                        moveUp = false;
                    }

                    if (enter)
                    {
                        enter = false; //reset for next time
                        if (sel == 0) Game1.currentGameState = Game1.GameState.NewGame;
                        if (sel == 1) Game1.currentGameState = Game1.GameState.InstructionScreen;
                        if (sel == 2) Game1.currentGameState = Game1.GameState.Credits;
                        if (sel == 3) Game1.currentGameState = Game1.GameState.GameExit;
                    }
                #endregion
                    break;

            }
            //save the current gamestate for use next time
            previousGameState = Game1.currentGameState;

            //reset for next time through
            keyDown = sDown || downDown || wDown || upDown || escDown || enter;
            base.Update(gameTime);
        }
        public void SetData(string textToDraw, Game1.GameState currGameState)
        {
            this.textToDraw = textToDraw;
            this.currentGameState = currGameState;

            switch (currentGameState) {
                case Game1.GameState.START:
                case Game1.GameState.LEVEL_CHANGE:
                    secondaryTextToDraw = "WASD to move, Space bar to boost.\n\n Press ENTER to begin";
                    break;
                case Game1.GameState.END:
                    secondaryTextToDraw = "Press ENTER to quit";

                    break;
            }
        }