public void Update(GameTime gameTime) { ship_bounding_box = new Rectangle((int)ship_pos.X - offset, (int)ship_pos.Y - offset, width, height); if (ship_bounding_box.Contains(KeyMouseReader.mouse_position)) { ship_select = true; } else { ship_select = false; } if (Game1.grab_p1 == true && KeyMouseReader.mouse_position.X < 500 || Game1.grab_p2 == true && KeyMouseReader.mouse_position.X > 700) { if (KeyMouseReader.RightClick()) { if (ship_select == true) { rotation_angle = (rotation_angle == 0 ? MathHelper.ToRadians(90) : 0); int temp = height; height = width; width = temp; } } } }
//Usage of items with mouseclicks. public static void ItemUse() { foreach (Inventory inventory in map.inventoryArray) { if (inventory.GetHitBox.Contains(mouseRect)) { if (KeyMouseReader.RightClick()) { inventory.occupied = false; row = 0; column = 0; } } } foreach (Item item in map.inventory) { if (item.GetHitBox.Contains(mouseRect) && item.isCollected) { if (KeyMouseReader.RightClick()) { item.inInventory = false; map.inventory.Remove(item); } break; } } }
public void HandleInput() { if (KeyMouseReader.KeyPressed(Keys.M)) { EventManager.Dispatch(new PopStateEvent()); } if (KeyMouseReader.KeyPressed(Keys.Escape)) { EventManager.Dispatch(new PopStateEvent()); } if (KeyMouseReader.MouseScreenPosition.X < bounds.Left || KeyMouseReader.MouseScreenPosition.X > bounds.Right || KeyMouseReader.MouseScreenPosition.Y < bounds.Top || KeyMouseReader.MouseScreenPosition.Y > bounds.Bottom) { Opacity = 0.5f; if (KeyMouseReader.LeftClick() || KeyMouseReader.RightClick()) { EventManager.Dispatch(new PopStateEvent()); } } else { Opacity = 1.0f; } }
protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) //Click the Escape button to close the program. { this.Exit(); } KeyMouseReader.Update(); if (running) { spawn += (float)gameTime.ElapsedGameTime.TotalSeconds; foreach (Asteroid a in asteroid_list) { a.Update(gameTime); if (KeyMouseReader.LeftClick() || KeyMouseReader.RightClick()) { if (a.asteroid_boundingbox.Contains(KeyMouseReader.mouse_position)) //When you click this line will check to see if the mouse position is inside the asteroids boundingbox. { asteroid_list.Remove(a); //If the mouse position is inside the asteroids boundingbox, the asteroid is removed. sound_asteroid_hit.Play(); //It then plays the sound for asteroids getting hit. hud.Score += 1; //Increases the score in the HUD by one per destoryed asteroid. score = score + 1; //Increases the score in the window title by one per destroyed asteroid. this.Window.Title = "Asteroid Asteroids destroyed: " + score + " Buildings left: " + life; break; //Stops the if and updates the asteroid_list. } } if (a.asteroid_boundingbox.Intersects(city_boundingbox)) //When the asteroids boundingbox hits the city's boundingbox { asteroid_list.Remove(a); //The asteroid is removed. sound_city_hit.Play(); //Then the sound is played for when an asteroid hits the city. hud.Life -= 1; //Deceeases the amount of lives you have left in the HUD by one per asteroid that hits the city. life = life - 1; //Decreases the amount of lives you have left in the window title by one per asteroid that hits the city. this.Window.Title = "Asteroid Asteroids destroyed: " + score + " Buildings left: " + life; break; } } if (life == 0) //When you run out of lives, { this.Window.Title = "Asteroid Asteroids destroyed: " + score + " Buildings left: " + life + " The city is lost! Press Esc to run for your life!"; running = false; //the game stops. } } LoadAsteroid(); base.Update(gameTime); }
private void HandleInput() { UpdateFocus(); if (KeyMouseReader.KeyPressed(Keys.Escape)) { EventManager.Dispatch(new PopStateEvent()); } if (!isHovered) { if (KeyMouseReader.LeftClick() || KeyMouseReader.RightClick()) { EventManager.Dispatch(new PopStateEvent()); } } }
public void Update(GameTime gameTime) { if (KeyMouseReader.RightClick()) { for (int i = 0; i < equipmentSlots.Count(); i++) { if (new Rectangle(equipmentSlots[i].GraphicLocationX, equipmentSlots[i].GraphicLocationY, 64, 64).Contains(KeyMouseReader.mouseState.Position)) { if (equipmentSlots[i].Item == null) { break; } if (tabManager.inventoryTab.inventorySystem.AddItem(equipmentSlots[i].Item)) { tabManager.map.player.team.characters[0].UnequipItem(equipmentSlots[i].Item); equipmentSlots[i].Item = null; equipmentSlots[i].InventoryFull = false; Archive.soundEffectDictionary["equip"].Play(); } } } } }
public void Update() { if (KeyMouseReader.LeftClick()) { if (!ItemInHand) { for (int i = 0; i < xNumberOfSlots; i++) { for (int j = 0; j < yNumberOfSlots; j++) { if (new Rectangle(invSlot[i, j].GraphicLocationX, invSlot[i, j].GraphicLocationY, 64, 64).Contains(KeyMouseReader.mouseState.Position)) { if (invSlot[i, j].Item == null) { break; } itemInHand = inPlayerHand.Item; inPlayerHand.Item = invSlot[i, j].Item; invSlot[i, j].Item = itemInHand; ItemInHand = true; if (invSlot[i, j].Item == null) { invSlot[i, j].InventoryFull = false; } else { invSlot[i, j].InventoryFull = true; } break; } } } } else { for (int i = 0; i < xNumberOfSlots; i++) { for (int j = 0; j < yNumberOfSlots; j++) { if (new Rectangle(invSlot[i, j].GraphicLocationX, invSlot[i, j].GraphicLocationY, 64, 64).Contains(KeyMouseReader.mouseState.Position)) { itemInHand = inPlayerHand.Item; inPlayerHand.Item = invSlot[i, j].Item; invSlot[i, j].Item = itemInHand; if (inPlayerHand.Item == null) { ItemInHand = false; } if (invSlot[i, j].Item == null) { invSlot[i, j].InventoryFull = false; } else { invSlot[i, j].InventoryFull = true; } } } } } } if (KeyMouseReader.RightClick()) { for (int i = 0; i < xNumberOfSlots; i++) { for (int j = 0; j < yNumberOfSlots; j++) { if (new Rectangle(invSlot[i, j].GraphicLocationX, invSlot[i, j].GraphicLocationY, 64, 64).Contains(KeyMouseReader.mouseState.Position)) { if (invSlot[i, j].Item == null) { break; } if (tabManager.characterTab.characterSystem.TryEquip(invSlot[i, j].Item)) { invSlot[i, j].Item = null; invSlot[i, j].InventoryFull = false; Archive.soundEffectDictionary["equip"].Play(); } } } } } }
public override void Update(GameTime gameTime) { if (KeyMouseReader.mouseState.LeftButton == ButtonState.Pressed) { selectionBox = new Rectangle( Math.Min(KeyMouseReader.mouseState.X, KeyMouseReader.leftMouseDownPosition.X), Math.Min(KeyMouseReader.mouseState.Y, KeyMouseReader.leftMouseDownPosition.Y), Math.Abs(KeyMouseReader.mouseState.X - KeyMouseReader.leftMouseDownPosition.X), Math.Abs(KeyMouseReader.mouseState.Y - KeyMouseReader.leftMouseDownPosition.Y)); } if (KeyMouseReader.LeftClickInPlace()) { if (rPressed) { Point p = Grid.Vector2ToGridPos(KeyMouseReader.mouseState.Position.ToVector2()); gm.SpawnPowerPlant(p.X, p.Y, faction); } else if (aPressed) { //A-move selected units foreach (IAttackable s in selection) { if (s is Unit) { (s as Unit).Controller.AttackMove(KeyMouseReader.mouseState.Position.ToVector2()); } } } else { selection.Clear(); IAttackable s = gm.ClickSelect(KeyMouseReader.mouseState.Position.ToVector2(), faction); if (s != null) { selection.Add(s); } } selectionBox = new Rectangle(); } else if (KeyMouseReader.LeftButtonReleased()) { selection = gm.BoxSelect(selectionBox, faction); selectionBox = new Rectangle(); } if (KeyMouseReader.LeftButtonReleased()) { aPressed = false; rPressed = false; } if (KeyMouseReader.KeyPressed(Keys.S)) //Stop { foreach (IAttackable s in selection) { if (s is Unit) { (s as Unit).Controller.Stop(); } } } if (KeyMouseReader.KeyPressed(Keys.A)) //Attack { aPressed = true; } if (KeyMouseReader.KeyPressed(Keys.H)) //Hold position { foreach (IAttackable s in selection) { if (s is Unit) { (s as Unit).Controller.HoldPosition(); } } } if (KeyMouseReader.KeyPressed(Keys.R)) { //Attack rPressed = true; } //UGLY!!! if (KeyMouseReader.RightClick()) { Attackable a = gm.GetAttackableAtLocation(KeyMouseReader.mouseState.Position.ToVector2(), faction); if (a != null) { foreach (IAttackable s in selection) { if (s is Unit) { (s as Unit).Controller.Attack(a); } } } else { Path p = null; foreach (IAttackable s in selection) { if (s is Unit) { if (p == null) { p = gm.GetPath(s.Position, KeyMouseReader.mouseState.Position.ToVector2()); } (s as Unit).Controller.FollowPath(p); } } } } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { KeyMouseReader.Update(); if (KeyMouseReader.RightClick()) { camera.Update(new Vector2(KeyMouseReader.mouseState.X - camera.CameraPos.X, KeyMouseReader.mouseState.Y - camera.CameraPos.Y)); } grid.Update(new Vector2(KeyMouseReader.mouseState.X, KeyMouseReader.mouseState.Y)); if (navigateTabs == NavigationTabs.ChooseObject) { if (chooseObject == ChooseObject.Player) { grid.tileType = TileGrid.TileType.AddPlayer; } else if (chooseObject == ChooseObject.Wall) { grid.tileType = TileGrid.TileType.AddWall; } else if (chooseObject == ChooseObject.Teleport) { grid.tileType = TileGrid.TileType.AddTeleport; } else if (chooseObject == ChooseObject.EnemySpawner) { grid.tileType = TileGrid.TileType.AddSpawner; } else if (chooseObject == ChooseObject.Pistol) { grid.tileType = TileGrid.TileType.AddPistol; } } hud.Update(camera.CameraPos); if (navigateTabs == NavigationTabs.SetGrid) { SetGrid(); } else if (navigateTabs == NavigationTabs.ChooseTool && chooseTool == ChooseTools.SaveLevel) { grid.SaveToJsonFile(); Console.WriteLine("SAVED"); chooseTool = ChooseTools.AddTiles; hud.selected = 0; } switch (navigateTabs) { case NavigationTabs.ChooseTool: if (KeyMouseReader.KeyPressed(Keys.Escape)) { navigateTabs = NavigationTabs.SetGrid; } if (KeyMouseReader.KeyPressed(Keys.Enter)) { if (hud.selected == 0) { chooseTool = ChooseTools.AddTiles; navigateTabs = NavigationTabs.ChooseCategory; } else if (hud.selected == 1) { chooseTool = ChooseTools.RemoveTiles; } else if (hud.selected == 2) { chooseTool = ChooseTools.SaveLevel; } hud.selected = 0; } break; case NavigationTabs.ChooseCategory: if (KeyMouseReader.KeyPressed(Keys.Escape)) { navigateTabs = NavigationTabs.ChooseTool; } if (KeyMouseReader.KeyPressed(Keys.Enter)) { if (hud.selected == 0) { chooseCategory = ChooseCategory.Characters; } else if (hud.selected == 1) { chooseCategory = ChooseCategory.Environment; } else if (hud.selected == 2) { chooseCategory = ChooseCategory.Weapons; } hud.selected = 0; navigateTabs = NavigationTabs.ChooseObject; } break; case NavigationTabs.ChooseObject: if (KeyMouseReader.KeyPressed(Keys.Escape)) { navigateTabs = NavigationTabs.ChooseCategory; } if (KeyMouseReader.KeyPressed(Keys.Enter)) { if (chooseCategory == ChooseCategory.Characters) { if (hud.selected == 0) { chooseObject = ChooseObject.Player; } else if (hud.selected == 1) { chooseObject = ChooseObject.EnemySpawner; } else if (hud.selected == 2) { chooseObject = ChooseObject.Enemy; } } else if (chooseCategory == ChooseCategory.Environment) { if (hud.selected == 0) { chooseObject = ChooseObject.Wall; } else if (hud.selected == 1) { chooseObject = ChooseObject.Teleport; } } else if (chooseCategory == ChooseCategory.Weapons) { if (hud.selected == 0) { chooseObject = ChooseObject.Pistol; } } } break; } // TODO: Add your update logic here base.Update(gameTime); }