public SaveGameScreen(OnScreenChanged screenChanged, TradeScreenContents tradeContents) : base(screenChanged) { UserInterfaceLoader uiLoader = UserInterfaceLoader.GetInstance(); FontLoader fontLoader = FontLoader.GetInstance(); TradeContents = tradeContents; fileSelected = -1; Texture2D blankButtonSprite = uiLoader.Get("select"); Texture2D confirmButtonSprite = uiLoader.Get("confirm"); Texture2D backButtonSprite = uiLoader.Get("back"); backButton = new StaticEntity("Back Button", new Vector2(GameConstants.TILE_SIZE * 2, GameConstants.WINDOW_HEIGHT - GameConstants.TILE_SIZE), backButtonSprite); fileButtons = new List <StaticEntity>(); levelData = new List <String>(); weapon1ItemBoxes = new List <ItemBox>(); weapon2ItemBoxes = new List <ItemBox>(); shield1ItemBoxes = new List <ItemBox>(); charm1ItemBoxes = new List <ItemBox>(); for (int i = 0; i < GameConstants.NUMBER_OF_SAVES; i++) { fileButtons.Add(new StaticEntity("Button " + i.ToString(), new Vector2(GameConstants.TILE_SIZE * 2, GameConstants.TILE_SIZE * 3 + i * GameConstants.TILE_SIZE * 2), blankButtonSprite)); levelData.Add(""); weapon1ItemBoxes.Add(new ItemBox("Weapon1 File " + i.ToString(), new Vector2(GameConstants.TILE_SIZE * 7, GameConstants.TILE_SIZE * 3 + i * GameConstants.TILE_SIZE * 2))); weapon2ItemBoxes.Add(new ItemBox("Weapon2 File " + i.ToString(), new Vector2(GameConstants.TILE_SIZE * 8, GameConstants.TILE_SIZE * 3 + i * GameConstants.TILE_SIZE * 2))); shield1ItemBoxes.Add(new ItemBox("Shield1 File " + i.ToString(), new Vector2(GameConstants.TILE_SIZE * 9, GameConstants.TILE_SIZE * 3 + i * GameConstants.TILE_SIZE * 2))); charm1ItemBoxes.Add(new ItemBox("Charm1 File " + i.ToString(), new Vector2(GameConstants.TILE_SIZE * 10, GameConstants.TILE_SIZE * 3 + i * GameConstants.TILE_SIZE * 2))); } confirmButton = new StaticEntity("Confirm Button", new Vector2(GameConstants.TILE_SIZE * 5, GameConstants.WINDOW_HEIGHT - GameConstants.TILE_SIZE), confirmButtonSprite); font = fontLoader.Get("font"); font20 = fontLoader.Get("font20"); actionBarBackground = uiLoader.Get("blankBackground"); background = new StaticEntity("Background", new Vector2(GameConstants.WINDOW_WIDTH / 2, GameConstants.WINDOW_HEIGHT / 2), actionBarBackground); for (int i = 0; i < GameConstants.NUMBER_OF_SAVES; i++) { CheckGameData(i, levelData, weapon1ItemBoxes, weapon2ItemBoxes, shield1ItemBoxes, charm1ItemBoxes); } }
public override void Update(GameTime gameTime) { MouseState mouse = Mouse.GetState(); if (newGameButton.CollisionRectangle.Contains(mouse.Position) && mouse.LeftButton == ButtonState.Pressed && !leftMousePreviouslyPressed) { TradeScreenContents playerStartingGear = new TradeScreenContents(GameConstants.PLAYER_MAX_HIT_POINTS, 1, ItemFactoryContainer.Weapons.CreateSword(), ItemFactoryContainer.Weapons.CreateBow(), ItemFactoryContainer.Shields.CreateBasicShield(), ItemFactoryContainer.Charms.CreateEmptyCharm()); ScreenChanged(new CombatScreen(ScreenChanged, playerStartingGear)); } else if (loadGameButton.CollisionRectangle.Contains(mouse.Position) && mouse.LeftButton == ButtonState.Pressed && !leftMousePreviouslyPressed) { ScreenChanged(new LoadGameScreen(ScreenChanged)); } else if (sandboxButton.CollisionRectangle.Contains(mouse.Position) && mouse.LeftButton == ButtonState.Pressed && !leftMousePreviouslyPressed) { ScreenChanged(new SandboxScreen(ScreenChanged)); } else if (adventureButton.CollisionRectangle.Contains(mouse.Position) && mouse.LeftButton == ButtonState.Pressed && !leftMousePreviouslyPressed) { //TODO: Support adventure mode and level editor //gameMode = GameMode.Adventure; //if (!keyboard.IsKeyDown(Keys.LeftShift)) //{ // gameState = GameState.Battle; // InitiateCombat(gameTime); //} //else //{ // gameState = GameState.Editor; // leftMousePreviouslyPressed = true; // InitiateLevelEditor(); //} } leftMousePreviouslyPressed = mouse.LeftButton == ButtonState.Pressed; }
public override void Update(GameTime gameTime) { mouse = Mouse.GetState(); foreach (StaticEntity itemBoxBackground in itemBoxBackgrounds) { if (itemBoxBackgrounds.Count == itemBoxes.Count || itemBoxBackgrounds.IndexOf(itemBoxBackground) < itemBoxes.Count) { ItemBox correspondingBox = itemBoxes.ElementAt(itemBoxBackgrounds.IndexOf(itemBoxBackground)); if (itemBoxBackground.CollisionRectangle.Contains(mouse.Position.X, mouse.Position.Y)) { correspondingBox.IsHovered = true; } else { correspondingBox.IsHovered = false; } } } foreach (StaticEntity itemBoxBackground in equippedItemBoxBackgrounds) { ItemBox correspondingBox = equippedItemBoxes.ElementAt(equippedItemBoxBackgrounds.IndexOf(itemBoxBackground)); if (itemBoxBackground.CollisionRectangle.Contains(mouse.Position.X, mouse.Position.Y)) { correspondingBox.IsHovered = true; } else { correspondingBox.IsHovered = false; } } hoveredItemName = ""; hoveredItemType = ""; hoveredItemEffects = ""; hoveredItemDamage = ""; hoveredItemCooldown = ""; foreach (ItemBox itemBox in itemBoxes) { if (itemBox.IsHovered) { ItemBoxHovered(itemBox, mouse); } } foreach (ItemBox itemBox in equippedItemBoxes) { if (itemBox.IsHovered) { ItemBoxHovered(itemBox, mouse); } } equippedItemBoxes.ElementAt(0).ReplaceItem(weapon1); equippedItemBoxes.ElementAt(1).ReplaceItem(weapon2); equippedItemBoxes.ElementAt(2).ReplaceItem(shield1); equippedItemBoxes.ElementAt(3).ReplaceItem(charm1); foreach (ItemBox box in equippedItemBoxes) { box.Update(); } if (backButton.CollisionRectangle.Contains(mouse.Position) && mouse.LeftButton == ButtonState.Pressed) { ScreenChanged(new MainMenuScreen(ScreenChanged)); } if (playButton.CollisionRectangle.Contains(new Vector2(mouse.X, mouse.Y)) && mouse.LeftButton == ButtonState.Pressed && !leftMousePreviouslyPressed) { TradeScreenContents tradeContents = new TradeScreenContents(GameConstants.PLAYER_MAX_HIT_POINTS, 1, weapon1, weapon2, shield1, charm1); ScreenChanged(new CombatScreen(ScreenChanged, tradeContents)); } leftMousePreviouslyPressed = mouse.LeftButton == ButtonState.Pressed; }