public void Toggle() { if (!isActive) { if (container.X < 0) { container.X = 0; } else if (container.X > (screenWidth - container.Width)) { container.X = screenWidth - container.Width; } if (container.Y < 0) { container.Y = 0; } else if (container.Y > (screenHeight - container.Height)) { container.Y = screenHeight - container.Height; } for (int i = 0; i < inventoryItems.Count; i++) { inventoryItems[i].SetLocation(new Vector2(container.X + 20 + ((i % 5) * 50), container.Y + 50 + ((i / 5) * 50))); } } Game1.ToggleMenu(this); isActive = !isActive; }
public void ToggleDialog(int screenWidth, int screenHeight, GraphicsDevice graphicsDevice) { if (dialogBox != null && dialogBox.GetIsActive()) { dialogBox.Close(); } else { dialogBox = new DialogBox(greetingDialog, greetingChoices, screenWidth, screenHeight, this); dialogBox.CreateTextures(graphicsDevice); } Game1.ToggleMenu(dialogBox); }
public void GetHit(String direction, int damage) { invulnerableTimer = 100; invulnerable = true; health -= damage; if (health <= 0) { /* die(); */ location = currentLocation.GetSpawnPoint(); health = maxHealth; mana = maxMana; xp = 0; Game1.ToggleMenu(new InfoBox("dead.")); } state = "hurt"; hurtCounter = 20; if (direction == "left") { horizontalVelocity -= 5; } else { horizontalVelocity += 5; } if (!isFalling) { verticalVelocity = -7; } else { verticalVelocity -= 3; } isFalling = true; }
public void Close() { Game1.ToggleMenu(this); }
public void CloseDialog() { dialogBox.Close(); Game1.ToggleMenu(dialogBox); }
public void Toggle() { Game1.ToggleMenu(this); isActive = !isActive; }
public void Update(KeyboardState keyboardState, Tile[][] tiles, MouseState mouseState) { newLocation = location; if (invulnerableTimer > 0) { invulnerableTimer--; if (this.state == "hurt" && invulnerableTimer < 80) { this.state = "invulnerable"; } if (invulnerableTimer == 0) { invulnerable = false; this.state = "normal"; } } if (!previousKeyboardState.IsKeyDown(Keys.OemComma) && keyboardState.IsKeyDown(Keys.OemComma)) { if (inventory.RemoveFromInventory(new InventoryItem(new Items.HealthPotion(1), new Vector2(0, 0)))) { health += 50; if (health > maxHealth) { health = maxHealth; } } } if (!previousKeyboardState.IsKeyDown(Keys.OemPeriod) && keyboardState.IsKeyDown(Keys.OemPeriod)) { if (inventory.RemoveFromInventory(new InventoryItem(new Items.ManaPotion(1), new Vector2(0, 0)))) { mana = maxMana; } } if (!previousKeyboardState.IsKeyDown(Keys.I) && keyboardState.IsKeyDown(Keys.I)) { Game1.ToggleMenu(inventory); } if (!previousKeyboardState.IsKeyDown(Keys.O) && keyboardState.IsKeyDown(Keys.O)) { Game1.ToggleMenu(equipmentMenu); } if (!(keyboardState.IsKeyDown(Keys.A) ^ keyboardState.IsKeyDown(Keys.D))) // if both or neither are pressed { textureChangeCounter = 5; currentTextureState = 1; } else { if (textureChangeCounter <= 0) { currentTextureState++; if (currentTextureState > 2) { currentTextureState = 0; } textureChangeCounter = 5; } if (keyboardState.IsKeyDown(Keys.A)) { if (previousKeyboardState.IsKeyDown(Keys.A) && !isFalling) { textureChangeCounter--; } newLocation.X -= 4; facing = "left"; } if (keyboardState.IsKeyDown(Keys.D)) { if (previousKeyboardState.IsKeyDown(Keys.D) && !isFalling) { textureChangeCounter--; } newLocation.X += 4; facing = "right"; } } if (keyboardState.IsKeyDown(Keys.LeftControl)) { Console.WriteLine(location.X + ", " + location.Y); } if (keyboardState.IsKeyDown(Keys.Space) && !isFalling) { isFalling = true; verticalVelocity = -20; } if (projectileCooldown > 0) { projectileCooldown--; } if (keyboardState.IsKeyDown(Keys.J) && projectileCooldown == 0 && mana >= 25) { if (swingFacing == "right") { Projectiles.Add(new Projectile(new Vector2(location.X + (width / 2) - (30 / 2), location.Y + (height / 2) - (30 / 2)), projectileTexture, 10, currentLocation, this)); } else if (swingFacing == "left") { Projectiles.Add(new Projectile(new Vector2(location.X + (width / 2) - (30 / 2), location.Y + (height / 2) - (30 / 2)), projectileTexture, -10, currentLocation, this)); } projectileCooldown = 60; mana -= 25; } if (keyboardState.IsKeyDown(Keys.F) && !previousKeyboardState.IsKeyDown(Keys.F) && equipmentMenu.GetEquippedItem() != null && swinging == false) { if (equipmentMenu.GetEquippedItem().GetItem().GetType() == typeof(Items.SwordItem)) { swinging = true; swingFacing = facing; swordIsActive = true; } else if (equipmentMenu.GetEquippedItem().GetItem().GetType() == typeof(Items.ScytheItem)) { swinging = true; swingFacing = facing; scytheIsActive = true; } } if (!swinging) { swingFacing = facing; } if (swinging) { swordTextureChangeCounter--; if (swordTextureChangeCounter < 0) { swordTextureChangeCounter = 5; currentSwordTextureState++; if (currentSwordTextureState >= 2) { swinging = false; scytheIsActive = false; swordIsActive = false; currentSwordTextureState = 0; } } } if (isFalling) { newLocation.Y += verticalVelocity; verticalVelocity++; } newHitBox = new Rectangle((int)newLocation.X, (int)newLocation.Y, width, height); Collisions.CollideWithTiles(tiles, this); location = newLocation; hitBox = newHitBox; if (facing == "left") { swordHitBox = new Rectangle((int)location.X - swordOffset, (int)location.Y, swordOffset, height); } else if (facing == "right") { swordHitBox = new Rectangle((int)location.X + width, (int)location.Y, swordOffset, height); } if (keyboardState.IsKeyDown(Keys.E) && !previousKeyboardState.IsKeyDown(Keys.E)) { foreach (Portal portal in currentLocation.GetPortals()) { if (Collisions.EntityCollisions(hitBox, portal.hitBox)) { Travel(portal.GetDestination(), portal.GetPositionDestination()); } } } if (manaRegenCooldown > 0) { manaRegenCooldown--; } if (manaRegenCooldown == 0 && (mana < maxMana)) { mana++; manaRegenCooldown = 10; } for (int i = Projectiles.Count - 1; i >= 0; i--) // some elements may be removed, so iterate backwards. { Projectiles[i].Update(tiles); } previousKeyboardState = keyboardState; }