Example #1
0
 /// <summary>
 /// Creates a button to advacne to the next screen.
 /// </summary>
 /// <param name="The rectangle to be used"></param>
 /// <param name="The Button object you want passed in"></param>
 /// <returns name="returns true if the button is clicked on"></returns>
 ///
 public bool ButtonPress(Button SpecificButton)
 {
     previousms = ms;
     ms         = Mouse.GetState();
     if (SpecificButton.enterButton() == true && previousms.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released)
     {
         return(true);
     }
     return(false);
 }
Example #2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        ///
        protected override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();

            //States for animations and drawing
            switch (state)
            {
                #region Mainmenu
            case GameState.MainMenu:
                //menu filler art

                spriteBatch.Draw(MenuBack, FullScreen, Color.White);
                MainMenuText = "       Fight off enemies and try not to die! \nWASD to move, and click to swing your sword.\n       Press 'Set Stats' to build a character.";
                spriteBatch.Draw(Logo, LogoLoc, Color.White);

                // Button drawing and logic
                spriteBatch.Draw(ButtonBack, buttonPosSetStats, Color.White);
                if (SetStats.enterButton() == true)
                {
                    spriteBatch.Draw(ButtonBack, buttonPosSetStats, Color.SandyBrown);
                }
                if (SetStats.enterButton() == true && ms.LeftButton == ButtonState.Pressed)
                {
                    spriteBatch.Draw(ButtonPressed, buttonPosSetStats, Color.White);
                }
                spriteBatch.DrawString(font, MainMenuText, CenterScreen, Color.SaddleBrown);
                spriteBatch.DrawString(font, "Set Stats", new Vector2(buttonPosSetStats.X + 32, buttonPosSetStats.Y + 8), Color.Silver);

                break;
                #endregion

                #region Itemmenu
            case GameState.ItemMenu:


                spriteBatch.Draw(MenuBack, FullScreen, Color.White);


                ItemMenuText =
                    "\n \n" +
                    "                       Select where to allocate your stats!" +
                    "\n" +
                    "\n                               Points Left to Spend: " + PlayerStats.totalStats +
                    "\n \n" +
                    "                       Strength(Damage):          " + PlayerStats.strength +
                    "\n \n" +
                    "                       Dexterity(Speed):            " + PlayerStats.dexterity +
                    "\n \n" +
                    "                       Constitution(Health):       " + PlayerStats.constitution;

                spriteBatch.DrawString(font, ItemMenuText, new Vector2(0, 0), Color.SaddleBrown);

                // Has button location

                if (PlayerStats.totalStats != 0)
                {
                    spriteBatch.Draw(ButtonBack, buttonPosPlay, Color.Gray);
                }

                else
                {
                    spriteBatch.Draw(ButtonBack, buttonPosPlay, Color.White);
                    if (Play.enterButton() == true)
                    {
                        spriteBatch.Draw(ButtonBack, buttonPosPlay, Color.SandyBrown);
                    }
                    if (Play.enterButton() == true && ms.LeftButton == ButtonState.Pressed)
                    {
                        spriteBatch.Draw(ButtonPressed, buttonPosPlay, Color.White);
                    }
                }
                spriteBatch.DrawString(font, "Play", new Vector2(buttonPosPlay.X + 28, buttonPosPlay.Y + 8), Color.Silver);



                // Button Draw Logic
                spriteBatch.Draw(StatSetterup, upStrPos, Color.Brown);
                if (upStr.enterButton() == true)
                {
                    spriteBatch.Draw(StatSetterup, upStrPos, Color.SandyBrown);
                }

                spriteBatch.Draw(StatSetterdown, downStrPos, Color.Brown);
                if (downStr.enterButton() == true)
                {
                    spriteBatch.Draw(StatSetterdown, downStrPos, Color.SandyBrown);
                }

                spriteBatch.Draw(StatSetterup, upDexPos, Color.Brown);
                if (upDex.enterButton() == true)
                {
                    spriteBatch.Draw(StatSetterup, upDexPos, Color.SandyBrown);
                }

                spriteBatch.Draw(StatSetterdown, downDexPos, Color.Brown);
                if (downDex.enterButton() == true)
                {
                    spriteBatch.Draw(StatSetterdown, downDexPos, Color.SandyBrown);
                }

                spriteBatch.Draw(StatSetterup, upConPos, Color.Brown);
                if (upCon.enterButton() == true)
                {
                    spriteBatch.Draw(StatSetterup, upConPos, Color.SandyBrown);
                }

                spriteBatch.Draw(StatSetterdown, downConPos, Color.Brown);
                if (downCon.enterButton() == true)
                {
                    spriteBatch.Draw(StatSetterdown, downConPos, Color.SandyBrown);
                }



                break;
                #endregion

                #region Playgame
            case GameState.PlayGame:
                //walls, doors textures
                //floor texture
                //health bar, current weapon box
                //spriteBatch.Draw(Character, characterPos, Color.White);
                //enemies
                //collision animations (create a method for this)
                string health = (mainChar.healthPoints).ToString();
                if (testFloor.floorNum % 4 == 0)
                {
                    GraphicsDevice.Clear(Color.Sienna);
                }
                else if (testFloor.floorNum % 3 == 0)
                {
                    GraphicsDevice.Clear(Color.Maroon);
                }
                else if (testFloor.floorNum % 2 == 0)
                {
                    GraphicsDevice.Clear(Color.IndianRed);
                }
                else
                {
                    GraphicsDevice.Clear(Color.SaddleBrown);
                }

                spriteBatch.DrawString(font, health, new Vector2(50, 40), Color.White);



                //Drawing Game Objects
                //spriteBatch.Draw(mainChar.getSprite(), mainChar.loc.Center, null, Color.White, rotate, mainChar.origin, 1.0f, SpriteEffects.None, 0f);
                DrawCharacterWalking(rotate, mainChar.origin);

                //Drawing enemies
                for (int i = 0; i < testFloor.currentRoom.enemies.Count; i++)
                {
                    Enemy enemyTemp = testFloor.currentRoom.enemies[i];


                    if (enemyTemp.checkAlive())
                    {
                        //spriteBatch.Draw(testFloor.currentRoom.enemies[i].getSprite(), testFloor.currentRoom.enemies[i].loc.Center, null, Color.White, rotate2, testFloor.currentRoom.enemies[i].origin, 1.0f, SpriteEffects.None, 0f);
                        DrawEnemyWalking(testFloor.currentRoom.enemies[i].loc.Center, rotate2, testFloor.currentRoom.enemies[i].origin);
                    }
                }

                //Drawing blade
                if (leftMousePress)
                {
                    spriteBatch.Draw(blade.getSprite(), blade.loc.Center, null, Color.White, rotate + 3.926f - 0.1047f * blade.swingtime, blade.origin, 0.65f, SpriteEffects.None, 0f);
                }

                // Healthbar
                spriteBatch.Draw(fullHealthBar, new Rectangle(150, 50, (int)mainChar.maxHP * 2, 40), Color.Black);
                spriteBatch.Draw(healthBar, new Rectangle(150, 50, (int)mainChar.healthPoints * 2, 40), Color.White);

                // Other UI
                spriteBatch.DrawString(font, "Level " + mainChar.level, new Vector2((int)mainChar.maxHP * 2 + 200, 40), Color.Green);
                spriteBatch.DrawString(font, "Floor " + testFloor.floorNum, new Vector2((int)mainChar.maxHP * 2 + 400, 40), Color.Silver);

                //Drawing walls
                testFloor.currentRoom.DrawWalls(spriteBatch);
                // testFloor.currentRoom.SetDoorSprite(sealedVDoor, sealedHDoor);
                if (!testFloor.currentRoom.RoomClear())
                {
                    testFloor.currentRoom.SetDoorSprite(sealedVDoor, sealedHDoor);
                }
                else
                {
                    testFloor.currentRoom.SetDoorSprite(openVDoor, openHDoor);
                }
                testFloor.currentRoom.DrawAllDoors(spriteBatch);

                //Drawing collectibles
                foreach (Collectible drop in testFloor.currentRoom.drops)
                {
                    drop.Draw(spriteBatch);
                }

                // Informs player of levelup

                if (frameCountDraw < 60)
                {
                    spriteBatch.DrawString(font, "Level up!", new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2), Color.Red);
                    frameCountDraw++;
                }



                break;
                #endregion

                #region Pausemenu
            case GameState.PauseMenu:


                health = (mainChar.healthPoints).ToString();
                GraphicsDevice.Clear(Color.CornflowerBlue);

                spriteBatch.DrawString(font, health, new Vector2(50, 40), Color.White);



                //Drawing Game Objects
                spriteBatch.Draw(mainChar.getSprite(), mainChar.loc.Center, null, Color.White, rotate, mainChar.origin, 1.0f, SpriteEffects.None, 0f);

                //Drawing enemies
                for (int i = 0; i < testFloor.currentRoom.enemies.Count; i++)
                {
                    Enemy enemyTemp = testFloor.currentRoom.enemies[i];


                    if (enemyTemp.checkAlive())
                    {
                        spriteBatch.Draw(testFloor.currentRoom.enemies[i].getSprite(), testFloor.currentRoom.enemies[i].loc.Center, null, Color.White, rotate2, testFloor.currentRoom.enemies[i].origin, 1.0f, SpriteEffects.None, 0f);
                    }
                }


                if (leftMousePress)
                {
                    spriteBatch.Draw(blade.getSprite(), blade.loc.Center, null, Color.White, rotate + 3.926f - 0.1047f * blade.swingtime, blade.origin, 0.65f, SpriteEffects.None, 0f);
                }

                spriteBatch.Draw(fullHealthBar, new Rectangle(150, 50, (50 * PlayerStats.constitution), 40), Color.Black);
                spriteBatch.Draw(healthBar, new Rectangle(150, 50, (int)mainChar.healthPoints * 2, 40), Color.White);

                //Drawing walls
                testFloor.currentRoom.DrawWalls(spriteBatch);
                testFloor.currentRoom.DrawAllDoors(spriteBatch);

                // Has button location

                spriteBatch.Draw(ButtonBack, buttonPosResume, Color.White);

                if (Resume.enterButton() == true)
                {
                    spriteBatch.Draw(ButtonBack, buttonPosResume, Color.SandyBrown);
                }

                if (Resume.enterButton() == true && ms.LeftButton == ButtonState.Pressed)
                {
                    spriteBatch.Draw(ButtonPressed, buttonPosResume, Color.White);
                }

                spriteBatch.DrawString(font, "Resume", new Vector2(buttonPosResume.X + 28, buttonPosResume.Y + 8), Color.Silver);
                PauseMenuText = "         The Game is Paused \n Press 'p' or 'Resume' to Resume.";
                spriteBatch.DrawString(font, PauseMenuText, CenterScreen, Color.SaddleBrown);

                foreach (Collectible drop in testFloor.currentRoom.drops)
                {
                    drop.Draw(spriteBatch);
                }
                break;
                #endregion

                #region Gameover
            case GameState.Gameover:
                //game over background texture
                //final stats
                //buttons, back to main menu
                spriteBatch.Draw(MenuBack, FullScreen, Color.White);
                GameOverText = "  Ur ded Scrub";
                //CenterScreen == new Vector2(280, 500)
                //spriteBatch.DrawString(font, GameOverText, CenterScreen, Color.SaddleBrown);
                spriteBatch.DrawString(font, GameOverText, new Vector2(280, 150), Color.SaddleBrown);


                int finalScore = ((testFloor.floorNum - 1) * 100) + mainChar.enemiesKilled;

                //spriteBatch.Draw(RIP, RIPloc, Color.White);

                //Reward Medals
                if (finalScore >= 750)
                {
                    spriteBatch.Draw(GoldMedal, MedalLoc, Color.White);
                }
                else if (finalScore >= 350)
                {
                    spriteBatch.Draw(SilverMedal, MedalLoc, Color.White);
                }
                else if (finalScore >= 1)
                {
                    spriteBatch.Draw(BronzeMedal, MedalLoc, Color.White);
                }
                else
                {
                    spriteBatch.Draw(TinMedal, MedalLoc, Color.White);
                }

                testFloor.currentRoom = testFloor.floorLayout[1, 1];
                testFloor.currentRoom.SetEnemies(EnemySprite, 3);
                testFloor.currentRoom.SpawnEnemies();
                // Has button location

                spriteBatch.Draw(ButtonBack, buttonPosRestart, Color.White);
                if (Restart.enterButton() == true)
                {
                    spriteBatch.Draw(ButtonBack, buttonPosRestart, Color.SandyBrown);
                }
                if (Restart.enterButton() == true && ms.LeftButton == ButtonState.Pressed)
                {
                    spriteBatch.Draw(ButtonPressed, buttonPosRestart, Color.White);
                }
                spriteBatch.DrawString(font, "Restart", new Vector2(buttonPosRestart.X + 28, buttonPosRestart.Y + 8), Color.Silver);

                spriteBatch.Draw(ButtonBack, buttonPosQuit, Color.White);
                if (Quit.enterButton() == true)
                {
                    spriteBatch.Draw(ButtonBack, buttonPosQuit, Color.SandyBrown);
                }
                if (Quit.enterButton() == true && ms.LeftButton == ButtonState.Pressed)
                {
                    spriteBatch.Draw(ButtonPressed, buttonPosQuit, Color.White);
                }
                spriteBatch.DrawString(font, "Quit", new Vector2(buttonPosQuit.X + 20, buttonPosQuit.Y + 8), Color.Silver);



                // 750 pts is gold, 350 is silver, 1 is bronze, 0 is tin.
                spriteBatch.DrawString(font, "Final Score = " + finalScore, new Vector2(280, 350), Color.ForestGreen);
                break;
                #endregion
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }
Example #3
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)
        {
            //Keyboard states
            previousKbState = kbState;
            kbState         = Keyboard.GetState();



            //Gameplay states
            switch (state)
            {
                #region MainMenu
            case GameState.MainMenu:
                ResetGame();

                if (ButtonPress(SetStats) == true)
                {
                    state = GameState.ItemMenu;
                }
                break;
                #endregion

                #region ItemMenu
            case GameState.ItemMenu:
                // Has button size


                if (ButtonPress(Play) &&
                    PlayerStats.totalStats == 0)
                {
                    ReCheckStats();
                    state = GameState.PlayGame;
                }

                if (upStr.enterButton() && previousms.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released)
                {
                    PlayerStats.upStr();
                }
                else if (downStr.enterButton() && previousms.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released)
                {
                    PlayerStats.downStr();
                }
                else if (upDex.enterButton() && previousms.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released)
                {
                    PlayerStats.upDex();
                }
                else if (downDex.enterButton() && previousms.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released)
                {
                    PlayerStats.downDex();
                }
                else if (upCon.enterButton() && previousms.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released)
                {
                    PlayerStats.upCon();
                }
                else if (downCon.enterButton() && previousms.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released)
                {
                    PlayerStats.downCon();
                }


                break;
                #endregion

                #region PlayGame
            case GameState.PlayGame:
                if (mainChar.healthPoints <= 0)
                {
                    state = GameState.Gameover;
                }
                else if (SingleKeyPress(Keys.P) == true)
                {
                    state = GameState.PauseMenu;
                }


                //Player walking animation
                UpdateAnimation(gameTime);

                //Function for player movement
                CharacterMovement(mainChar);

                if (testFloor.isFloorClear())
                {
                    testFloor.changeFloors();
                    testFloor.currentRoom = testFloor.enterDoor(mainChar);
                    //testFloor.currentRoom.SetEnemies(EnemySprite, 3);
                    // testFloor.currentRoom.SpawnEnemies();
                }

                #region CharCollision
                else if (testFloor.currentRoom.RoomClear())
                {
                    if (testFloor.currentRoom.RoomExit(mainChar))
                    {
                        testFloor.currentRoom = testFloor.enterDoor(mainChar);
                        int x = testFloor.currentRoom.xPos;
                        int y = testFloor.currentRoom.yPos;

                        if (testFloor.checkLeftDoor(x, y))
                        {
                            testFloor.currentRoom.SetDoor("left");
                        }
                        if (testFloor.checkUpperDoor(x, y))
                        {
                            testFloor.currentRoom.SetDoor("top");
                        }
                        if (testFloor.checkRightDoor(x, y))
                        {
                            testFloor.currentRoom.SetDoor("right");
                        }
                        if (testFloor.checkLowerDoor(x, y))
                        {
                            testFloor.currentRoom.SetDoor("bottom");
                        }
                        testFloor.currentRoom.SetEB();
                        if (!testFloor.currentRoom.isCleared)
                        {
                            testFloor.currentRoom.SetEnemies(EnemySprite, 3);
                            testFloor.currentRoom.SpawnEnemies();
                        }
                    }
                }
                else
                {
                    //Player-Wall collision
                    mainChar.loc.Center.X = MathHelper.Clamp(mainChar.loc.Center.X, mainChar.loc.Radius + 50, 1550 - mainChar.loc.Radius);
                    mainChar.loc.Center.Y = MathHelper.Clamp(mainChar.loc.Center.Y, mainChar.loc.Radius + 50, 850 - mainChar.loc.Radius);
                }

                foreach (Collectible drop in testFloor.currentRoom.drops)
                {
                    drop.playerIntersect(mainChar);
                }

                for (int i = 0; i < testFloor.currentRoom.drops.Count; i++)
                {
                    if (testFloor.currentRoom.drops[i].picked)
                    {
                        testFloor.currentRoom.drops.Remove(testFloor.currentRoom.drops[i]);
                    }
                }
                #endregion

                //Rotates the character to the mouse
                #region CharRotate
                ms = Mouse.GetState();
                float xdist = ms.X - mainChar.loc.Center.X;
                float ydist = ms.Y - mainChar.loc.Center.Y;
                rotate = (float)(System.Math.Atan2(ydist, xdist) + 1.570);
                #endregion


                blade.moveWeapon(mainChar, rotate);

                if (ms.LeftButton == ButtonState.Pressed && cd == 0)
                {
                    attackcd = true;
                }

                if (attackcd)
                {
                    if (blade.swingtime < 16)
                    {
                        movespeed      = 5 + (2 * PlayerStats.dexterity);
                        leftMousePress = true;
                        foreach (Enemy e in testFloor.currentRoom.enemies)
                        {
                            if (e.playerIntersect(blade) && e.checkAlive())
                            {
                                Character.charHit(mainChar, e);

                                if (!e.checkAlive())
                                {
                                    mainChar.enemiesKilled++;
                                    testFloor.currentRoom.SpawnCollectible(dropSprite, e.loc.Center.X, e.loc.Center.Y);
                                }

                                if (mainChar.CheckXP())
                                {
                                    PlayerStats.dexterity++;
                                    PlayerStats.strength++;
                                    double temphp = mainChar.healthPoints;
                                    lvlhp += 10;
                                    ReCheckStats();
                                    mainChar.healthPoints = temphp;
                                    frameCountDraw        = 0;
                                }
                            }
                        }
                        blade.swingtime++;
                    }
                    else
                    {
                        movespeed      = 10 + (2 * PlayerStats.dexterity);
                        leftMousePress = false;
                        cd             = 40 - PlayerStats.dexterity * 5;
                        attackcd       = false;
                    }
                }
                else
                {
                    leftMousePress  = false;
                    blade.swingtime = 0;
                    if (cd != 0)
                    {
                        cd--;
                    }
                }



                #region EnemyAI
                //Enemy AI function
                for (int i = 0; i < testFloor.currentRoom.enemies.Count; i++)
                {
                    //Rotates the enemy to the character
                    if (testFloor.currentRoom.enemies[i].checkAlive())
                    {
                        rotate2 = Character.getAngleBetween(mainChar, testFloor.currentRoom.enemies[i]);
                        testFloor.currentRoom.enemies[i].followChar(mainChar);
                    }
                }

                #endregion

                break;


                #endregion

                #region PauseMenu
            case GameState.PauseMenu:
                // Has button size


                if (ButtonPress(Resume) == true || (SingleKeyPress(Keys.P) == true))
                {
                    state = GameState.PlayGame;
                }
                break;
                #endregion

                #region Gameover
            case GameState.Gameover:

                if (ButtonPress(Restart) == true)
                {
                    state = GameState.MainMenu;
                }

                if (Quit.enterButton() && previousms.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released)
                {
                    Exit();
                }

                break;
                #endregion
            }



            //Exit on pressing escape
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) //Readded for ease of update
            {
                Exit();
            }



            base.Update(gameTime);
        }