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; } }
public void Update(GameTime gameTime) { Vector2 mousePosition = KeyMouseReader.MouseScreenPosition; IsMouseHovered = Hitbox.Contains(mousePosition.ToPoint()); if (IsMouseHovered && KeyMouseReader.LeftClick() && Action != null && KeyMouseReader.oldMouseState.LeftButton != Microsoft.Xna.Framework.Input.ButtonState.Pressed) { Action(); } }
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); }
protected void SelectUnitState() { TargetSpell spellToChange = (TargetSpell)selectingSpell; Character previousCharacter = null; Color outlineColor = Color.Yellow; foreach (Character c in allCharacters) { if (team1.Contains(c)) { if (spellToChange.targetTeam == TargetSpell.TargetTeam.Enemy) { c.outlineColor = Color.Red; } } else { c.outlineColor = Color.Yellow; } if (c.hitbox.Contains(KeyMouseReader.mousePosition)) { if (previousCharacter != null) { previousCharacter.drawOutline = false; } c.drawOutline = true; } else { c.drawOutline = false; } previousCharacter = c; if (c.hitbox.Contains(KeyMouseReader.mousePosition) && KeyMouseReader.LeftClick()) { if (team2.Contains(c)) { if (spellToChange.targetTeam == TargetSpell.TargetTeam.Enemy) { spellToChange.target = c; c.drawOutline = false; currentState = CombatState.ChoseAction; } } } } }
public bool IsClicked() { if (KeyMouseReader.KeyPressed(keyBind)) { return(true); } if (hitBox.Contains(KeyMouseReader.mousePosition)) { if (KeyMouseReader.LeftClick()) { return(true); } } return(false); }
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() { 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(); } } } } } }
protected void TilePicker() { if (selectedTileType == 0) { foreach (Tile t in floorTiles) { Rectangle tileHitbox = new Rectangle((int)t.position.X, (int)t.position.Y, t.texture.Width, t.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = t; selectedEntity = null; } } } if (selectedTileType == 1) { foreach (Tile t in wallTiles) { Rectangle tileHitbox = new Rectangle((int)t.position.X, (int)t.position.Y, t.texture.Width, t.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = t; selectedEntity = null; } } } if (selectedTileType == 2) { foreach (Entity e in entities) { Rectangle tileHitbox = new Rectangle((int)e.position.X, (int)e.position.Y, e.texture.Width, e.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = null; selectedEntity = e; } } } if (selectedTileType == 3) { foreach (Entity i in items) { Rectangle tileHitbox = new Rectangle((int)i.position.X, (int)i.position.Y, i.texture.Width, i.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = null; selectedEntity = i; } } } if (selectedTileType == 4) { foreach (PortalEntity p in portals) { Rectangle tileHitbox = new Rectangle((int)p.position.X, (int)p.position.Y, p.texture.Width, p.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = null; selectedEntity = p; } } } }
public override void Update(GameTime gameTime) { if (KeyMouseReader.KeyPressed(Keys.P)) { ClickCounter++; switch (ClickCounter % 7) { case 0: SelectedObject = ObjectEnum.Platform; break; case 1: SelectedObject = ObjectEnum.VerticalPlatform; break; case 2: SelectedObject = ObjectEnum.HorizontalPlatform; break; case 3: SelectedObject = ObjectEnum.SpikePlatform; break; case 4: SelectedObject = ObjectEnum.CloudPlatform; break; case 5: SelectedObject = ObjectEnum.IcePlatform; break; case 6: SelectedObject = ObjectEnum.FadingPlatform; break; default: throw new ArgumentOutOfRangeException(); } } if (KeyMouseReader.KeyPressed(Keys.U)) { SelectedObject = ObjectEnum.Player; } if (KeyMouseReader.KeyPressed(Keys.G)) { SelectedObject = ObjectEnum.Goal; } if (Keyboard.GetState().IsKeyDown(Keys.E)) { SelectedObject = ObjectEnum.Enemy; } if (Keyboard.GetState().IsKeyDown(Keys.R)) { SelectedObject = ObjectEnum.WalkingEnemy; } if (Keyboard.GetState().IsKeyDown(Keys.C)) { SelectedObject = ObjectEnum.None; } if (Keyboard.GetState().IsKeyDown(Keys.Q)) { SelectedObject = ObjectEnum.UnlimitedPower; } if (Keyboard.GetState().IsKeyDown(Keys.W)) { SelectedObject = ObjectEnum.SlowWorld; } if (Keyboard.GetState().IsKeyDown(Keys.H)) { SelectedObject = ObjectEnum.HpGain; } if (KeyMouseReader.KeyPressed(Keys.S)) { SaveToFile(); } if (KeyMouseReader.KeyPressed(Keys.L)) { ReadFromFile(); } if (KeyMouseReader.KeyDown(Keys.Right)) { CamPos.X += 1; CamPos.Y += 0; } else if (KeyMouseReader.KeyDown(Keys.Left)) { CamPos.X += -1; CamPos.Y += 0; } if (KeyMouseReader.KeyDown(Keys.Up)) { CamPos.X += 0; CamPos.Y += -1; } else if (KeyMouseReader.KeyDown(Keys.Down)) { CamPos.X += 0; CamPos.Y += 1; } Cam.SetPos(CamPos); MousePosition = KeyMouseReader.MousePosition; var transform = Matrix.Invert(Cam.GetTransform()); Vector2.Transform(ref MousePosition, ref transform, out MousePosition); PlacePosition = MousePosition; if (Objects.Count > 0 && SelectedObject != ObjectEnum.Player) { var closestObj = Objects[0]; foreach (var obj in Objects) { if (Vector2.Distance(obj.GetCenter(), MousePosition) < Vector2.Distance(closestObj.GetCenter(), MousePosition)) { closestObj = obj; } } if (Vector2.Distance(closestObj.GetCenter(), MousePosition) < 25) { PlacePosition = closestObj.GetCenter().X - MousePosition.X < 0 ? new Vector2(closestObj.Dest.Right, closestObj.Dest.Top) : new Vector2(closestObj.Dest.Left - closestObj.Dest.Width, closestObj.Dest.Top); } } if (KeyMouseReader.LeftClick()) { switch (SelectedObject) { case ObjectEnum.Platform: Objects.Add(new Platform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.VerticalPlatform: Objects.Add(new VerticalPlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.HorizontalPlatform: Objects.Add(new HorizontalPlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.SpikePlatform: Objects.Add(new SpikePlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.CloudPlatform: Objects.Add(new CloudPlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.IcePlatform: Objects.Add(new IcePlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.FadingPlatform: Objects.Add(new FadingPlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.Player: Objects.Add(new Player(PlacePosition, TextureManager.NogardAbilitySpritesheet)); break; case ObjectEnum.Enemy: Objects.Add(new BaseEnemy(MousePosition, TextureManager.EnemySpritesheet)); break; case ObjectEnum.WalkingEnemy: Objects.Add(new StandardEnemy(MousePosition, TextureManager.EnemySpritesheet)); break; case ObjectEnum.FlyingEnemy: Objects.Add(new FlyingEnemy(MousePosition, TextureManager.EnemySpritesheet)); break; case ObjectEnum.Goal: Objects.Add(new Goal(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.None: Objects.RemoveAll(item => Vector2.Distance(item.GetCenter(), MousePosition) < 25); break; case ObjectEnum.UnlimitedPower: Objects.Add(new UnlimitedPowerObject(PlacePosition, TextureManager.UnlimitedPowerTex)); break; case ObjectEnum.SlowWorld: Objects.Add(new SlowWorldPowerObject(PlacePosition, TextureManager.SlowWorldTex)); break; case ObjectEnum.HpGain: Objects.Add(new HealthGain(PlacePosition, TextureManager.HpGainTex)); break; default: throw new ArgumentOutOfRangeException(); } } }
protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } KeyMouseReader.Update(); foreach (Ship s in p1_ships) { s.Update(gameTime); } foreach (Ship s in p2_ships) { s.Update(gameTime); } foreach (Tile g in p1_grid) { g.Update(gameTime); } foreach (Tile g in p2_grid) { g.Update(gameTime); } if (!running) { if (!ship_placement) { if (KeyMouseReader.LeftClick() && KeyMouseReader.mouse_position.X < 500 && !grab_p1) { ship_to_move = ship_selected(); if (ship_to_move != null) { grab_p1 = true; } } else if (grab_p1) { ship_to_move.ship_pos = new Vector2(KeyMouseReader.mouse_position.X, KeyMouseReader.mouse_position.Y); if (KeyMouseReader.LeftClick()) { if (ship_on_ship()) { ship_to_move.ship_pos.X = (((int)ship_to_move.ship_pos.X / 50) * 50 + ship_to_move.ship_frame_size.Y / 2 + 3); ship_to_move.ship_pos.Y = (((int)ship_to_move.ship_pos.Y / 50) * 50 + ship_to_move.ship_frame_size.Y / 2 + 3); grab_p1 = false; } if (ship_to_move.ship_bounding_box.Right >= 500 || ship_to_move.ship_bounding_box.Top <= 3 || ship_to_move.ship_bounding_box.Left <= 3 || ship_to_move.ship_bounding_box.Bottom >= 500) { grab_p1 = true; } } } if (Keyboard.GetState().IsKeyDown(Keys.Space) && grab_p1 == false) { ship_placement = true; } } if (ship_placement && !play) { if (KeyMouseReader.LeftClick() && KeyMouseReader.mouse_position.X > 700 && !grab_p2) { ship_to_move = ship_selected(); if (ship_to_move != null) { grab_p2 = true; } } else if (grab_p2) { ship_to_move.ship_pos = new Vector2(KeyMouseReader.mouse_position.X, KeyMouseReader.mouse_position.Y); if (KeyMouseReader.LeftClick()) { if (ship_on_ship()) { ship_to_move.ship_pos.X = (((int)ship_to_move.ship_pos.X / 50) * 50 + ship_to_move.ship_frame_size.Y / 2) - 3; ship_to_move.ship_pos.Y = (((int)ship_to_move.ship_pos.Y / 50) * 50 + ship_to_move.ship_frame_size.Y / 2) + 2; grab_p2 = false; } if (ship_to_move.ship_bounding_box.Right >= 1197 || ship_to_move.ship_bounding_box.Top <= 3 || ship_to_move.ship_bounding_box.Left <= 697 || ship_to_move.ship_bounding_box.Bottom >= 500) { grab_p2 = true; } } } if (Keyboard.GetState().IsKeyDown(Keys.Enter) && grab_p2 == false) { play = true; } } if (play == true) { if (KeyMouseReader.LeftClick()) { Tile tile = tile_selected(); if (tile != null && KeyMouseReader.mouse_position.X > 700 && KeyMouseReader.mouse_position.Y < 500 && !player_turn) { if (tile.hit == true || tile.miss == true) { shoot = false; } else { shoot = true; } if (shoot == true) { Ship temp = get_ship(tile.tile_bb); if (temp != null && tile.hit == false && tile.miss == false) { tile.hit = true; hit_p1 += 1; temp.ship_life -= 1; hit_sound.Play(); } else { tile.miss = true; miss_p1 += 1; miss_sound.Play(); } player_turn = true; } } if (tile != null && KeyMouseReader.mouse_position.X < 500 && KeyMouseReader.mouse_position.Y < 500 && player_turn) { if (tile.hit == true || tile.miss == true) { shoot = false; } else { shoot = true; } if (shoot == true) { Ship temp = get_ship(tile.tile_bb); if (temp != null && tile.hit == false && tile.miss == false) { tile.hit = true; hit_p2 += 1; temp.ship_life -= 1; hit_sound.Play(); } else { tile.miss = true; miss_p2 += 1; miss_sound.Play(); } player_turn = !player_turn; } } } } if (hit_p1 == 17 || hit_p2 == 17) { running = true; } base.Update(gameTime); } }
public void Control(GameTime gt) { if (KeyMouseReader.keyState.IsKeyDown(Keys.E) && GamePlayManager.levelComplete == true && Key.keyPickedUp == true) { GamePlayManager.levelNumber++; GamePlayManager.currentLevel = "level" + GamePlayManager.levelNumber.ToString(); GamePlayManager.map = new MapParser("Content/" + GamePlayManager.currentLevel + ".txt"); GamePlayManager.levelComplete = false; Key.keyPickedUp = false; } if (KeyMouseReader.keyState.IsKeyDown(Keys.D)) { WalkingAnimation(gt); velocity.X = normalVel; } else if (KeyMouseReader.keyState.IsKeyDown(Keys.A))// && pos.X >= startPos.X { WalkingAnimation(gt); velocity.X = -normalVel; } else { velocity.X = 0; } if (KeyMouseReader.mouseState.X >= bX / 2) { playerFacing = Facing.Right; } else if (KeyMouseReader.mouseState.X <= bX / 2) { playerFacing = Facing.Left; } if (KeyMouseReader.keyState.IsKeyDown(Keys.LeftShift)) { if (dashCount > 0) { if (KeyMouseReader.keyState.IsKeyDown(Keys.D)) { velocity.X += dashLength; } if (KeyMouseReader.keyState.IsKeyDown(Keys.A)) { velocity.X -= dashLength; } //save dash snapshot here dashCount = 0; } } if (KeyMouseReader.keyState.IsKeyDown(Keys.Space) && isGrounded) { velocity.Y = -jumpHeight; //jump height isGrounded = false; playerFacing = Facing.Jump; //srRect = new Rectangle(tileSize.X * 3, tileSize.Y * 0, tileSize.X, tileSize.Y); } if (KeyMouseReader.keyState.IsKeyDown(Keys.S) && isGrounded) { velocity.Y = jumpHeight; isGrounded = false; downPlatform = false; playerFacing = Facing.Jump; //srRect = new Rectangle(tileSize.X * 3, tileSize.Y * 0, tileSize.X, tileSize.Y); } if (KeyMouseReader.LeftClick()) { if (shotCount > 0 && canShoot) { bullet = new Bullet(AssetManager.bomb, pos, playerFacing); bulletList.Add(bullet); bullet.isActive = true; shotCount = 0; } } if (KeyMouseReader.keyState.IsKeyDown(Keys.F)) { melee.isActive = true; } else { melee.isActive = false; } if (KeyMouseReader.keyState.IsKeyDown(Keys.Q)) { PunchingAnimation(gt); } if (KeyMouseReader.keyState.IsKeyDown(Keys.R)) { KickingAnimation(gt); } }