//---------CONSTRUCTORS--------- public Instructions() { //Buttons backPosition = new Rectangle((int)(SpritesDirectory.width * .0125), //10 (int)(SpritesDirectory.height * 0.02083), //10 (int)(SpritesDirectory.width * .125), //100 (int)(SpritesDirectory.height * .0833)); //40 backButton = new Button("Back", backPosition, SpritesDirectory.GetFont("Arial40")); backButton.IsActive = backButton.IsVisible = true; //-----TEXT----- backstoryPosition = new Rectangle((int)(SpritesDirectory.width * .0125), //10 (int)(SpritesDirectory.height * .4167), //200 SpritesDirectory.width, //screen width SpritesDirectory.height); //screen height howToPlayPosition = new Rectangle((int)(SpritesDirectory.width * .0125), //10 (int)(SpritesDirectory.height * .625), //300 SpritesDirectory.width, //screen width SpritesDirectory.height); //screen height //Backstory backstory = "You play an elf named Elion. He saw a hat on an Ogre and decided to follow it into a cave to take his hat."; howToPlay = "Click on an ability button and then click on an enemy to attack."; }
public void Draw(SpriteBatch batch) { //Draw background batch.Draw(SpritesDirectory.GetSprite("CombatBackground"), new Rectangle(0, 0, SpritesDirectory.width, SpritesDirectory.height), Color.White); //Draw Header batch.DrawString( SpritesDirectory.GetFont("Arial40"), "Instructions", new Vector2((SpritesDirectory.width / 2) - (SpritesDirectory.GetFont("Arial40").MeasureString("Instructions").X / 2), (int)(SpritesDirectory.height * .04167)), //Half, 20 Color.White); //Draw Backstory batch.DrawString( SpritesDirectory.GetFont("Arial16"), WordWrap(backstory, SpritesDirectory.GetFont("Arial16"), backstoryPosition), new Vector2((int)(SpritesDirectory.width * .04375), (int)(SpritesDirectory.height * .4167)), //35, 200 Color.White); //Draw Instructions batch.DrawString( SpritesDirectory.GetFont("Arial16"), WordWrap(howToPlay, SpritesDirectory.GetFont("Arial16"), howToPlayPosition), new Vector2((SpritesDirectory.width / 2) - (SpritesDirectory.GetFont("Arial16").MeasureString(howToPlay).X / 2), (int)(SpritesDirectory.height * .625)), Color.White); //Draw Button backButton.Draw(batch); }
/// <summary> /// Constructor /// </summary> /// <param name="text">Text for the button to display</param> /// <param name="rect">Size and location of the button</param> /// <param name="font">Font for the text to be displayed in</param> /// <param name="padding">The distance between the text and the edge of the button</param> public Button(string text, Rectangle rect, SpriteFont font, int padding = 5) { this.text = text; this.rect = rect; this.font = font; this.padding = padding; //Un-used parameters in DrawString origin = new Vector2(0); clicked = false; buttonBack = SpritesDirectory.GetSprite("Button"); buttonBackClicked = SpritesDirectory.GetSprite("ButtonClicked"); //Calclates the scale Vector2 stringSize = font.MeasureString(text); float stringX = stringSize.X; float stringY = stringSize.Y; scale = Math.Min((rect.Height - (2 * padding)) / stringY, (rect.Width - (2 * padding)) / stringX); //Centers the text position position = new Vector2(rect.X + ((rect.Width - (stringX * scale)) * 0.5f), rect.Y + ((rect.Height - (stringY * scale)) * 0.5f)); mouse = Mouse.GetState(); }
public Play() { player = new Player(SpritesDirectory.GetSprite("Elion"), new Point((int)(SpritesDirectory.width * .125), //100 (int)(SpritesDirectory.height * .4167)), //200 (int)(SpritesDirectory.width * .125), //100 (int)(SpritesDirectory.height * .4167), //200 1); floor = new Queue <Room>(); safeRoom = new SafeRoom(); player.AttackPostEvent += safeRoom.UpdateEnemyStat; state = PlayState.PlayerInput; floorLevel = 1; //-1 for selectedTarget and selectedAbility indicates no selection selectedAbility = -1; selectedTarget = -1; abilityButton = new Button[6]; int count = 0; for (int x = 0; x < 3; x++) { for (int y = 0; y < 2; y++) { abilityButton[count] = new Button( player.Abilities[count].Name, new Rectangle( (int)(SpritesDirectory.width * (.15 + .17 * Math.Pow(x, 1.8))), //x (int)(SpritesDirectory.height * (.78 + (y * .1))), //y (int)(SpritesDirectory.width * .14), //width (int)(SpritesDirectory.height * .08)), //height SpritesDirectory.GetFont("Arial40")); abilityButton[count].IsActive = abilityButton[count].IsVisible = true; count++; } } Rectangle newAbilityRect = new Rectangle((int)(SpritesDirectory.width * .75), (int)(SpritesDirectory.height * .755), (int)(SpritesDirectory.width * .1875), (int)(SpritesDirectory.height * .1042)); newAbilityButton = new Button("null", newAbilityRect, SpritesDirectory.GetFont("Arial40")); //Textbox Rectangle textBox = new Rectangle((int)(SpritesDirectory.width * .25), //200 (int)(SpritesDirectory.height * .02083), //10 (int)(SpritesDirectory.width * .5), //400 (int)(SpritesDirectory.height * .2083)); //100 description = new TextBox("null", textBox, SpritesDirectory.GetFont("Arial16")); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here SpritesDirectory.Init(this); AnimationsDirectory.animations(this); PostInitialize(); }
/// <summary> /// Constructor /// </summary> public SafeRoom() { timer = 0; playerStats = new TextBox("player stats", new Rectangle((int)(SpritesDirectory.width * 0.25), (int)(SpritesDirectory.height * 0.7), (int)(SpritesDirectory.width * 0.5), (int)(SpritesDirectory.height * 0.25)), SpritesDirectory.GetFont("Arial16")); }
public void Draw(SpriteBatch batch) { //Draw background batch.Draw(SpritesDirectory.GetSprite("CombatBackground"), new Rectangle(0, 0, SpritesDirectory.width, SpritesDirectory.height), Color.White); //Draw Name batch.DrawString( SpritesDirectory.GetFont("Arial60"), "Hat Quest", new Vector2((SpritesDirectory.width / 2) - (SpritesDirectory.GetFont("Arial60").MeasureString("Hat Quest").X / 2), 100), Color.White); //Draw Button playButton.Draw(batch); instructionsButton.Draw(batch); }
/// <summary> /// The constructor defines the Position and Texture of the Entity /// </summary> /// <param name="texture">The Entity's Texture</param> /// <param name="position">The Top-Left corner of the Entity</param> /// <param name="width">How wide you want the Entity</param> /// <param name="height">How tall you want the Entity</param> public Entity(Texture2D texture, Point position, int width, int height, int hatPosition) { this.position = new Rectangle(position.X, position.Y, width, height); this.texture = texture; abilities = new List <Ability>(); isVisible = isActive = true; hats = new List <Hat>(); effects = new List <StatusEffect>(); stats = new List <string>(); this.hatPosition = hatPosition; animation = new Animations(10.0, 1.0 / 10.0, SpritesDirectory.GetSprite("StatusEffect"), 10, 116, 1523, 826); }
//---------CONSTRUCTORS--------- public Menu() { //Buttons playPosition = new Rectangle(SpritesDirectory.width / 2 - (int)((SpritesDirectory.width * .1875) / 2), (int)(SpritesDirectory.height * .625), //300 (int)(SpritesDirectory.width * .1875), //150 (int)(SpritesDirectory.height * .0833)); //40 playButton = new Button("Play", playPosition, SpritesDirectory.GetFont("Arial40")); instructionsPosition = new Rectangle(SpritesDirectory.width / 2 - (int)((SpritesDirectory.width * .1875) / 2), (int)(SpritesDirectory.height * .79167), //380 (int)(SpritesDirectory.width * .1875), //150 (int)(SpritesDirectory.height * .0833)); //40 instructionsButton = new Button("Instructions", instructionsPosition, SpritesDirectory.GetFont("Arial40")); playButton.IsActive = playButton.IsVisible = true; instructionsButton.IsActive = instructionsButton.IsVisible = true; }
//---------CONSTRUCTORS--------- /// <summary> /// Constructor /// </summary> /// <param name="text">Text for the textbox to display</param> /// <param name="rect">Size and location of the textbox</param> /// <param name="font">Font for the text to be displayed in</param> /// <param name="padding">The distance between the text and the edge of the textbox</param> public TextBox(string text, Rectangle rect, SpriteFont font, int padding = 5) { this.text = text; this.rect = rect; this.font = font; this.padding = padding; //Un-used parameters in DrawString origin = new Vector2(0); textboxBack = SpritesDirectory.GetSprite("Button"); //Word Wrap string[] words = text.Split(' '); Vector2 stringLength = new Vector2(0); wrapped = ""; //Centers the text position position = new Vector2(rect.X + 15, rect.Y + 15); mouse = Mouse.GetState(); }
//---------CONSTRUCTORS--------- public static void animations(Game game) { animationsDirectory = new Dictionary <string, Texture2D>(); animationsDirectory.Add("Mario", SpritesDirectory.GetSprite("MarioTest")); }
public void Draw(SpriteBatch batch) { #region Draw //Draw background batch.Draw(SpritesDirectory.GetSprite("CombatBackground"), new Rectangle(0, 0, (SpritesDirectory.width), (int)(SpritesDirectory.height * 1.25)), Color.White); //Draw the player and enemies player.Draw(batch); if (floor != null && floor.Count > 0) { floor.Peek().Draw(batch); } //---------Draw player Stats--------- string[] stats = player.GetStats(); //Background batch.Draw(SpritesDirectory.GetSprite("Button"), new Rectangle((int)(SpritesDirectory.width * .0125), (int)(SpritesDirectory.height * (1 / 64.0)), (int)(SpritesDirectory.width * .15), (int)(SpritesDirectory.height * ((4 + (5 * stats.Length)) / 128.0))),//.14583 Color.White); for (int k = 0; k < stats.Length; k++) { batch.DrawString(SpritesDirectory.GetFont("Arial12"), stats[k], new Vector2((int)(SpritesDirectory.width * .03125), (int)(SpritesDirectory.height * ((4 + (5 * k)) / 128.0) + (3 / 128.0))),//.03125 Color.White); } //Draw based on the PlayState switch (state) { case PlayState.PlayerInput: foreach (Button ab in abilityButton) { ab.Draw(batch); } //Draw stats of enemy being hovered over for (int k = 4; k > -1; k--) { if (floor.Peek()[k] != null && floor.Peek()[k].Selected(mouseCurrent)) { stats = floor.Peek()[k].GetStats(); batch.Draw(SpritesDirectory.GetSprite("Button"), new Rectangle((int)(SpritesDirectory.width * (64 / 80.0)), //670 (int)(SpritesDirectory.height * (1 / 64.0)), //7.5 (int)(SpritesDirectory.width * .1875), //150 (int)(SpritesDirectory.height * ((4 + (5 * stats.Length)) / 128.0))), Color.White); for (int j = 0; j < stats.Length; j++) { batch.DrawString(SpritesDirectory.GetFont("Arial12"), stats[j], new Vector2((int)(SpritesDirectory.width * (65 / 80.0)), (int)(SpritesDirectory.height * ((4 + (5 * j)) / 128.0) + (3 / 128.0))), Color.White); } } } break; case PlayState.PlayerAttack: break; case PlayState.EnemyTurn: break; case PlayState.CombatEnd: //If the player won the combat if (player.IsActive) { droppedHat.Draw(batch, null, 0); description.Text = string.Format("You defeated the enemy and got: {0}!", droppedHat.Name); if (droppedHat.HasAbility) { description.Text = string.Format("Please select an ability to replace."); //Ability 1 Button abilityButton[0].Draw(batch); //Ability 2 Button abilityButton[1].Draw(batch); //Ability 3 Button abilityButton[2].Draw(batch); //Ability 4 Button abilityButton[3].Draw(batch); //New Ability Button newAbilityButton.Draw(batch); } } //If the player lost the combat else { description.Text = string.Format("You were defeated :("); } description.Text = description.Text + "Press ENTER to continue"; break; case PlayState.SafeRoom: safeRoom.Draw(batch); break; } //Draw textbox if (description.IsVisible) { description.Draw(batch); } #endregion }
public MainState Update(GameTime time) { #region Update //Update the current keyboard and mouse state mouseLast = mouseCurrent; mouseCurrent = Mouse.GetState(); keyboardLast = keyboardCurrent; keyboardCurrent = Keyboard.GetState(); //Update the gameplay based on the current state and inputs switch (state) { case PlayState.PlayerInput: if (!player.IsActive) { state = PlayState.CombatEnd; } else { state = GetPlayerInput(); } if (state == PlayState.PlayerAttack) { //Hide buttons foreach (Button ab in abilityButton) { ab.IsActive = ab.IsVisible = false; } player.Animation.SetSprite(SpritesDirectory.GetSprite("StatusEffect"), 10, 116, 1523, 826); description.IsVisible = true; } break; case PlayState.PlayerAttack: //Placeholder state for player animations player.Animation.UpdateAnimation(time); //call the event when the PlayState changes if (player.Animation.IsDone) { player.TurnEnd(); state = PlayState.EnemyTurn; } break; case PlayState.EnemyTurn: state = floor.Peek().TakeEnemyTurn(player, time); //Update the description text to describe the current enemy attack description.Text = floor.Peek().Description; if (state == PlayState.PlayerInput) { player.TurnStart(); //Reveal buttons foreach (Button ab in abilityButton) { ab.IsActive = ab.IsVisible = true; } } else if (state == PlayState.CombatEnd) { description.IsVisible = true; //Get the dropped hat and remove the room droppedHat = HatsDirectory.GetRandomHat(floorLevel, floor.Dequeue().GetDroppedHats()); if (player.IsActive) { player.Loot = droppedHat; } //Hide buttons abilityButton[4].IsVisible = abilityButton[4].IsActive = false; abilityButton[5].IsVisible = abilityButton[5].IsActive = false; if (droppedHat.HasAbility) { //Make and enable the ability to select the new ability Rectangle newAbilityRect = new Rectangle((int)(SpritesDirectory.width * .75), (int)(SpritesDirectory.height * .755), (int)(SpritesDirectory.width * .1875), (int)(SpritesDirectory.height * .1042)); newAbilityButton = new Button(droppedHat.Ability.Name, newAbilityRect, SpritesDirectory.GetFont("Arial40")); newAbilityButton.IsVisible = newAbilityButton.IsActive = true; abilityButton[0].IsVisible = abilityButton[0].IsActive = true; abilityButton[1].IsVisible = abilityButton[1].IsActive = true; abilityButton[2].IsVisible = abilityButton[2].IsActive = true; abilityButton[3].IsVisible = abilityButton[3].IsActive = true; } //Disable all the ability buttons if there is no new ability to select else { abilityButton[0].IsVisible = abilityButton[0].IsActive = false; abilityButton[1].IsVisible = abilityButton[1].IsActive = false; abilityButton[2].IsVisible = abilityButton[2].IsActive = false; abilityButton[3].IsVisible = abilityButton[3].IsActive = false; } } break; case PlayState.CombatEnd: if (keyboardCurrent.IsKeyDown(Keys.Enter) && keyboardLast.IsKeyUp(Keys.Enter) && (!player.IsActive || ((lastClicked != null && lastClicked.Clicked) || (player.Loot != null && !player.Loot.HasAbility)))) { if (!player.IsActive) { return(MainState.Menu); } if (player.Loot != null) { if (player.Loot.HasAbility && temp != 0) { player.Loot.Equip(player, temp); player.Loot = null; abilityButton[temp] = new Button(player.Abilities[temp].Name, abilityButton[temp].Rect, SpritesDirectory.GetFont("Arial40")); } else { player.Loot.Equip(player); player.Loot = null; } } //Move to the next combat if the floor still has rooms left if (floor.Count > 0) { state = PlayState.PlayerInput; } //Move to the safe room if the current floor has been completed else { state = PlayState.SafeRoom; } if (state == PlayState.PlayerInput) { floor.Peek().IsVisible = true; } if (state == PlayState.PlayerInput) { floor.Peek().IsVisible = true; } } else if (player.Loot != null) { if (player.Loot.HasAbility) { #region Ability selection //Enable ability buttons for (int k = 0; k < 4; k++) { if (abilityButton[k].IsPressed(mouseLast, mouseCurrent)) { if (lastClicked != null) { lastClicked.Clicked = false; } lastClicked = abilityButton[k]; abilityButton[k].Clicked = true; temp = k; } } if (newAbilityButton.IsPressed(mouseLast, mouseCurrent)) { if (lastClicked != null) { lastClicked.Clicked = false; } lastClicked = newAbilityButton; newAbilityButton.Clicked = true; } #endregion } } if (state == PlayState.PlayerInput) { //Reveal buttons foreach (Button ab in abilityButton) { ab.IsActive = ab.IsVisible = true; } } else if (state == PlayState.SafeRoom) { description.IsVisible = true; description.Text = "You feel safe here and take a moment to rest...\n" + "Press ENTER to continue"; safeRoom.SetUp(player.Hats.Count); } break; case PlayState.SafeRoom: state = safeRoom.Update(keyboardCurrent, keyboardLast); if (state == PlayState.PlayerInput) { player.CurrentMP = player.MaxMP; player.Health = player.MaxHealth; floorLevel++; GenerateFloor(); floor.Peek().IsVisible = true; //Reveal buttons foreach (Button ab in abilityButton) { ab.IsActive = ab.IsVisible = true; } description.IsVisible = false; } break; } return(MainState.Play); #endregion }