/// <summary> /// uses the first potion in the list if the player has any potions /// </summary> /// <param name="items"></param> /// <param name="player"></param> void UsePotion() { //saves the index of the potion we are using. if the index is null, don't remove anything int?indexToRemove = null; //check all the elements in the list foreach (Item item in player.ItemsHeld) { //if this one is a potion if (item is HealthPotion) { HealthPotion potion = (HealthPotion)item; //use it potion.Use(player); //remove it from the list indexToRemove = player.ItemsHeld.IndexOf(item); //don't check anymore elements in the list break; } } //remove the item if the index isn't null if (indexToRemove != null) { int valueInt = (int)indexToRemove; player.ItemsHeld.RemoveAt(valueInt); } }
/// <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); //load temporary wall and floor assets wallTexture = Content.Load <Texture2D>("Wall_tile"); floorTexture = Content.Load <Texture2D>("Ground_tile"); entranceTexture = Content.Load <Texture2D>("Entrance_tile"); exitTexture = Content.Load <Texture2D>("exit"); //load spritefont font = Content.Load <SpriteFont>("File"); //Move select textures //selectionText = Content.Load<SpriteFont>("AttackFont"); selectionBGTxt = Content.Load <Texture2D>("SelectionBG"); //load temp player texture playerTexture = Content.Load <Texture2D>("mayor_anim"); enemyTexture = Content.Load <Texture2D>("slime_idle"); //item textures hpPotTexture = Content.Load <Texture2D>("HealthPotion.png"); //instantiate Tile Controller tileController = new TileController(26, 26); //create first level with filepath tileController.CreateLevel1("..\\..\\..\\..\\Levels\\Oomph.txt"); //player rectangle is set to the find rectangle point entrance1 = tileController.FindEntrance(1); exit1 = tileController.FindExit(1); playerRectangle.Location = new Point(entrance1.X * 32, entrance1.Y * 32); //gamestate textures pauseMenu = Content.Load <Texture2D>("pause screen"); //player menu texture playerMenuTexture = Content.Load <Texture2D>("MenuDrop"); //menu nodes and menu stack //why on earth did I use a tree here menuRoot = new MenuNode("menu", MenuItem.root); menuRoot.Add(new MenuNode("items", MenuItem.menu)); menuRoot.Add(new MenuNode("attacks", MenuItem.menu)); menuRoot.Add(new MenuNode("back", MenuItem.back)); //add items here menuRoot.MenuItems.ElementAt <MenuNode>(0).Add(new MenuNode("use health potion", MenuItem.item)); menuRoot.MenuItems.ElementAt <MenuNode>(0).Add(new MenuNode("back", MenuItem.back)); //add attacks here menuRoot.MenuItems.ElementAt <MenuNode>(1).Add(new MenuNode("WEAK ATTACK", MenuItem.attack)); menuRoot.MenuItems.ElementAt <MenuNode>(1).Add(new MenuNode("back", MenuItem.back)); characterController = new CharacterController(26, 26); player = new Player(characterController, tileController, 10, playerRectangle, playerTexture); enemy = new Enemy(characterController, tileController, 10, enemyRectangle, enemyTexture, player); enemy2 = new Enemy(characterController, tileController, 10, enemyRectangle2, enemyTexture, player); potOne = new HealthPotion(10, potOneRect, hpPotTexture); potTwo = new HealthPotion(10, potTwoRect, hpPotTexture); potThree = new HealthPotion(10, potThreeRect, hpPotTexture); items.Add(potOne); items.Add(potTwo); items.Add(potThree); mainMenu = Content.Load <Texture2D>("Title screen"); //loading shader stuff effect1 = Content.Load <Effect>("lighteffect"); lightMask = Content.Load <Texture2D>("lightmask"); var pp = GraphicsDevice.PresentationParameters; lightsTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight); mainTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight); Random rng = new Random(); foreach (Item i in items) { i.Populate(tileController, 1, rng); } //menu stack menuStack = new MenuStack(menuRoot, player); }