/// <summary> /// Draws the Level Editor UI and finds out if element was clicked /// </summary> /// <param name="texturesDictionary"></param> /// <param name="spriteBatch"></param> /// <param name="transformationMatrix"></param> /// <param name="gameObjectList"></param> /// <param name="graphics"></param> public void DrawLvlEditorUI(Dictionary <string, Texture2D> texturesDictionary, SpriteBatch spriteBatch, Matrix transformationMatrix, ref List <GameObject> gameObjectList, ref List <GameObject> levelGameObjects, GraphicsDevice graphics, ref LoadAndSave loadAndSave, ref Levels levelManager) { int j = 0; MouseState mouseState = Mouse.GetState(); Vector2 firstPosition = new Vector2(1750, 200); Vector2 transformedPos_firstPosition = Vector2.Transform(firstPosition, Matrix.Invert(transformationMatrix)); spriteBatch.Draw(texturesDictionary["Transparent_500x50"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["Transparent_1000x50"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["Climbingplant_38x64"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["Transparent_64x64"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; for (int i = 0; i < PlatformsDic.Count(); i++) { spriteBatch.Draw(Platform_TileSheet, transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), PlatformsDic.ElementAt(i).Value, Color.White, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0); j++; } spriteBatch.Draw(texturesDictionary["SnailShell"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["Armor_64x64"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["Shovel_64x64"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["Scissors_64x64"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["HealthItem"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["PowerPotion"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["JumpPotion"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["GoldenUmbrella"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["Spiderweb_64x64"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["VineDoor"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["Apple"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; j++; spriteBatch.Draw(texturesDictionary["EnemySpawnPoint"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; spriteBatch.Draw(texturesDictionary["cornnency"], transformedPos_firstPosition + j * new Vector2(0, 100) - new Vector2(0, yoffset), Color.White); j++; if (ButtonState.Pressed == mouseState.LeftButton && !button1Pushed) { Vector2 transformedPos = Vector2.Transform(new Vector2(1000, 200), Matrix.Invert(transformationMatrix)); Rectangle checkRectangle; button1Pushed = true; for (int i = 4; i < PlatformsDic.Count() + 4; i++) { checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + i * 100 - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { createNewPlatform(ref gameObjectList, PlatformsDic.ElementAt(i - 4).Key, transformationMatrix, graphics, texturesDictionary); } } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + 0 * 100 - yoffset, 500, 50); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Platform(texturesDictionary["Transparent_500x50"], new Vector2(512, 64), transformedPos, (int)Enums.ObjectsID.PLATFORM, (int)Enums.ObjectsID.INVISIBLE_WALL_500x50, false)); gameObjectList.Last().DontDrawThisObject(); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + 1 * 100 - yoffset, 1000, 50); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Platform(texturesDictionary["Transparent_1000x50"], new Vector2(1024, 64), transformedPos, (int)Enums.ObjectsID.PLATFORM, (int)Enums.ObjectsID.INVSIBLE_WALL_1000x50, false)); gameObjectList.Last().DontDrawThisObject(); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + 2 * 100 - yoffset, 38, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Platform(texturesDictionary["Climbingplant_38x64"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.VINE, (int)Enums.ObjectsID.VINE, false)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + 3 * 100 - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Platform(texturesDictionary["Transparent_64x64"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.PLATFORM, (int)Enums.ObjectsID.INVISIBLE_WALL_64x64, false)); gameObjectList.Last().DontDrawThisObject(); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 4) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["SnailShell"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.SNAILSHELL)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 5) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["Armor_64x64"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.ARMOR)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 6) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["Shovel_64x64"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.SHOVEL)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 7) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["Scissors_64x64"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.SCISSORS)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 8) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["HealthItem"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.HEALTHPOTION)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 9) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["PowerPotion"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.POWERPOTION)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 10) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["JumpPotion"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.JUMPPOTION)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 11) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["GoldenUmbrella"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.GOLDENUMBRELLA)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 12) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Platform(texturesDictionary["Spiderweb_64x64"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.PLATFORM, (int)Enums.ObjectsID.SPIDERWEB, false)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 13) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Platform(texturesDictionary["VineDoor"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.PLATFORM, (int)Enums.ObjectsID.VINEDOOR, false)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 14) * 100) - yoffset, 128, 128); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["Apple"], new Vector2(128, 128), transformedPos, (int)Enums.ObjectsID.APPLE)); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 16) * 100) - yoffset, 64, 64); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Platform(texturesDictionary["EnemySpawnPoint"], new Vector2(64, 64), transformedPos, (int)Enums.ObjectsID.PLATFORM, (int)Enums.ObjectsID.ENEMYSPAWNPOINT, true)); gameObjectList.Last().DontDrawThisObject(); } checkRectangle = new Rectangle((int)firstPosition.X, (int)firstPosition.Y + ((PlatformsDic.Count() + 17) * 100) - yoffset, 128, 128); if (checkRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { gameObjectList.Add(new Item(texturesDictionary["cornnency"], new Vector2(128, 128), transformedPos, (int)Enums.ObjectsID.CORNNENCY)); } } if (ButtonState.Released == mouseState.LeftButton) { button1Pushed = false; } Color color = new Color(); Vector2 positionBackButton = new Vector2(1550, 900); Vector2 transformedBackButton = Vector2.Transform(positionBackButton, Matrix.Invert(transformationMatrix)); Rectangle rectangleBackButton = new Rectangle((int)positionBackButton.X, (int)positionBackButton.Y, 200, 50); if (rectangleBackButton.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y))) { if (ButtonState.Pressed == mouseState.LeftButton && !button2Pushed) { button2Pushed = true; color = Color.LightGray; foreach (GameObject gameObject in gameObjectList) { levelGameObjects.Add(gameObject); } levelManager.sortGameObjects(); loadAndSave.Save(); } else { color = Color.White; } } else { button2Pushed = false; color = Color.White; } spriteBatch.Draw(texturesDictionary["LevelEditorUIBackButton"], transformedBackButton, color); }
//Player's itemcollisionChecker private void ItemCollisionManager(ref List <GameObject> interactiveObject, ref List <GameObject> gameObjectList, Levels levelManager, ref List <GameObject> allGameObjectsList) { for (int i = 0; i < interactiveObject.Count(); i++) { if (interactiveObject[i].objectID == (int)Enums.ObjectsID.SNAILSHELL) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggieEquipedSomething"); ItemUIManager.snailShellPickedUp = true; } } if (interactiveObject[i].objectID == (int)Enums.ObjectsID.SCISSORS) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggiePickupAnyItem"); ItemUIManager.scissorsPickedUp = true; } } if (interactiveObject[i].objectID == (int)Enums.ObjectsID.ARMOR) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggieEquipedSomething"); ItemUIManager.armorPickedUp = true; } } if (interactiveObject[i].objectID == (int)Enums.ObjectsID.SHOVEL) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggiePickupAnyItem"); ItemUIManager.shovelPickedUp = true; } } if (interactiveObject[i].objectID == (int)Enums.ObjectsID.HEALTHPOTION) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggiePickupAnyItem"); ItemUIManager.healthPickedUp = true; ItemUIManager.healthPotionsCount++; } } if (interactiveObject[i].objectID == (int)Enums.ObjectsID.JUMPPOTION) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggiePickupAnyItem"); ItemUIManager.jumpPickedUp = true; ItemUIManager.jumpPotionsCount++; } } if (interactiveObject[i].objectID == (int)Enums.ObjectsID.POWERPOTION) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggiePickupAnyItem"); ItemUIManager.powerPickedUp = true; ItemUIManager.powerPotionsCount++; } } if (interactiveObject[i].objectID == (int)Enums.ObjectsID.GOLDENUMBRELLA) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggiePickupAnyItem"); ItemUIManager.goldenUmbrellaPickedUp = true; } } if (interactiveObject[i].objectID == (int)Enums.ObjectsID.CORNNENCY) { if (DetectCollision(interactiveObject[i])) { audioManager.Play("ReggiePickupAnyItem"); for (int k = 0; k < allGameObjectsList.Count(); k++) { if (allGameObjectsList[k].objectID == (int)Enums.ObjectsID.CORNNENCY) { if (allGameObjectsList[k].gameObjectPosition == interactiveObject[i].gameObjectPosition) { gameObjectList.Remove(allGameObjectsList[k]); } } } ItemUIManager.cornnencyQuantity++; break; } } } }
internal void DrawShopKeeper(SpriteBatch spriteBatch, GameTime gameTime, Dictionary <string, Texture2D> texturesDictionary, Matrix transformationMatrix, SpriteFont font, Levels levelManager) { nPC_Animations.Animation(gameTime, spriteBatch, this); if (shopOpen == true) { drawShopInterface(spriteBatch, texturesDictionary, transformationMatrix); } //TextBoxTimingStuff timer += (float)gameTime.ElapsedGameTime.TotalSeconds; randomTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (levelManager.currentLevel == Enums.Level.HUB) { DrawAlmostRandomMessages(spriteBatch, gameTime, transformationMatrix, font, levelManager); } }
//Player Update Function that covers collision,controls,movement and inputs internal void Update(GameTime gameTime, List <GameObject> gameObjectsToRender, ref List <Enemy> enemyList, List <GameObject> interactiveObject, ref List <GameObject> gameObjects, LoadAndSave loadAndSave, IngameMenus ingameMenus, Levels levelManager, ref List <GameObject> allGameObjects, ShopKeeper shopKeeper, ItemUIManager itemUIManager, ref Boss hakume) { if (!playerSlowed) { movementSpeed = 10f; } if (!facingDirectionRight) { changeCollisionBox.X = 0; } else { changeCollisionBox.X = 50; } if (!shopKeeper.shopOpen) { PlayerControls(gameTime, enemyList, interactiveObject, ref gameObjects, loadAndSave, ingameMenus, gameObjects, shopKeeper, itemUIManager, hakume); } collisionBoxPosition = gameObjectPosition + changeCollisionBox; PlayerPositionCalculation(gameTime, gameObjectsToRender, interactiveObject); ItemCollisionManager(ref interactiveObject, ref gameObjects, levelManager, ref allGameObjects); if (invincibilityFrames) { InvincibleFrameState(gameTime); } Vibration(); }
private void DrawAlmostRandomMessages(SpriteBatch spriteBatch, GameTime gameTime, Matrix transformationMatrix, SpriteFont font, Levels levelManager) { if (timer > boxPopUpCooldown) { everySecondTime++; temp = ""; if (everySecondTime == 2) { temp = ""; everySecondTime = 0; } else if ((int)randomTimer % totalTextBoxesCount == 0 && alreadydrawn_0 == false) { temp = "Hey, Wurmling!"; alreadydrawn_0 = true; boxPopUpCooldown = 3; currentDrawnTextBoxesCount++; nPC_Animations.nextAnimation = NPC_Animations.NPCAnimations.IdleShopkeeper; } else if ((int)randomTimer % totalTextBoxesCount == 1 && alreadydrawn_1 == false) { temp = "Komm ma ran und kauf jetzt!"; alreadydrawn_1 = true; boxPopUpCooldown = 3.5f; currentDrawnTextBoxesCount++; nPC_Animations.nextAnimation = NPC_Animations.NPCAnimations.IdleShopkeeper; } else if ((int)randomTimer % totalTextBoxesCount == 2 && alreadydrawn_2 == false) { temp = "Jaa, ich will dich ja nicht hetzen\naber wenn du hier nur rumstehst und nichts kaufst,\ndann kannst du auch wieder weiter gehn!"; alreadydrawn_2 = true; boxPopUpCooldown = 5.5f; currentDrawnTextBoxesCount++; } else if ((int)randomTimer % totalTextBoxesCount == 3 && alreadydrawn_3 == false) { temp = "Nicht genug Korn? Da machste nix!\nHoechstens einen Trinken! HA, HA!"; alreadydrawn_3 = true; boxPopUpCooldown = 5; currentDrawnTextBoxesCount++; } else if ((int)randomTimer % totalTextBoxesCount == 4 && alreadydrawn_4 == false) { temp = "Ich kanns nur immer wieder sagen,\n mit Wurmlingen wie dir wird Hakumes Regime nie gestuertzt..."; alreadydrawn_4 = true; boxPopUpCooldown = 5; currentDrawnTextBoxesCount++; } else if ((int)randomTimer % totalTextBoxesCount == 5 && alreadydrawn_5 == false) { temp = "Paah! Du willst Hakumes Regime stuerzen?!\nOhne ordentliche Ausruestung kannst du doch gar nichts ausrichten!"; alreadydrawn_5 = true; boxPopUpCooldown = 5.5f; currentDrawnTextBoxesCount++; } else if ((int)randomTimer % totalTextBoxesCount == 6 && alreadydrawn_6 == false) { temp = "Ich habe das beste gruene zu verkaufen!\nAber ehrlich gesagt bin ich auch der einzige,\n der hier was verkauft"; alreadydrawn_6 = true; boxPopUpCooldown = 5.5f; currentDrawnTextBoxesCount++; } else if ((int)randomTimer % totalTextBoxesCount == 7 && alreadydrawn_7 == false) { temp = "Wo sind denn alle anderen hin?!\nVielleicht wurden sie von Hakumes Lakaien in die Sklaverei getrieben\noder dienen als Tauzugseil fuer die anderen Voegel,\naber was weiss ich schon"; alreadydrawn_7 = true; boxPopUpCooldown = 8.5f; currentDrawnTextBoxesCount++; } else if ((int)randomTimer % totalTextBoxesCount == 8 && alreadydrawn_8 == false) { temp = "Seit Hakume hier sein unwesen treibt\nund alle Wurmlinge als niedrige Nahrung klassifiziert hat,\nkommt hier kaum noch einer vorbei.\nSchoen das es dich gibt, kauf was!"; alreadydrawn_8 = true; boxPopUpCooldown = 8.5f; currentDrawnTextBoxesCount++; } else if ((int)randomTimer % totalTextBoxesCount == 9 && alreadydrawn_9 == false) { temp = "Die Voegel gehen mir echt auf mein Blatt!"; alreadydrawn_9 = true; boxPopUpCooldown = 4; currentDrawnTextBoxesCount++; } else if ((int)randomTimer % totalTextBoxesCount == 10 && alreadydrawn_10 == false) { temp = "Es koennte ja so schoen sein ohne diese Voegel!"; alreadydrawn_10 = true; boxPopUpCooldown = 4; currentDrawnTextBoxesCount++; } else { boxPopUpCooldown = 0; everySecondTime = 0; } timer = 0; } //resets all alreadydrawn bools if every text box was once displayed if (currentDrawnTextBoxesCount >= totalTextBoxesCount) { alreadydrawn_0 = false; alreadydrawn_1 = false; alreadydrawn_2 = false; alreadydrawn_3 = false; alreadydrawn_4 = false; alreadydrawn_5 = false; alreadydrawn_6 = false; alreadydrawn_7 = false; alreadydrawn_8 = false; alreadydrawn_9 = false; alreadydrawn_10 = false; currentDrawnTextBoxesCount = 0; } //draws the actual Textbox //if the shop isnt open he draws it dynamically onto your screen but only if the player is in hub if (!shopOpen) { spriteBatch.DrawString(font, temp, Vector2.Transform(new Vector2(650, 800), Matrix.Invert(transformationMatrix)), Color.Black, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0); } else { spriteBatch.DrawString(font, temp, new Vector2(2850, 4350), Color.Black, 0, Vector2.Zero, 0.4f, SpriteEffects.None, 0); } spriteBatch.DrawString(font, "Herald, der Shopdude", new Vector2(2650, 4200), Color.Black, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0); }