private bool Normal(RLKey key) { if (IsPressed(RLKey.Keypad5)) { ISelfAction action = (ISelfAction)player.Actions.Find(x => x.Name == "Wait"); return(action.Execute()); } else if (MovementPressed()) { return(CheckMovement()); } else if (IsPressed(RLKey.Comma)) { Item item = GameController.CurrentMap.GetItemAt(player.X, player.Y); GameController.CurrentMap.RemoveItem(item); GameController.InventorySystem.AddItem(item); } else if (IsPressed(RLKey.I)) { InventoryScreen inventoryScreen = new InventoryScreen(false, true, _rootConsole); inventoryScreen.Init(); Game.GameStack.Push(inventoryScreen); } SystemKeys(key); return(false); }
public KeyPress(RLKey key, bool shift = false, bool control = false, bool alt = false) { Key = key; Shift = shift; Control = control; Alt = alt; }
public bool CastSpell(Player player, RLKey key) { int x = player.X; int y = player.Y; Tuple <int, int> d = null; switch (key) { case RLKey.S: { y++; d = new Tuple <int, int>(0, 1); break; } case RLKey.W: { y--; d = new Tuple <int, int>(0, -1); break; } case RLKey.D: { x++; d = new Tuple <int, int>(1, 0); break; } case RLKey.A: { x--; d = new Tuple <int, int>(-1, 0); break; } } Fireball fireball = new Fireball(x, y, d); fireball.Draw(); Game.spells.Add(fireball); return(false); }
private void HandleLocationTargeting(RLKey key) { int x = _cursorPosition.X; int y = _cursorPosition.Y; DungeonMap map = Game.DungeonMap; if (key == RLKey.Right) { x++; } else if (key == RLKey.Left) { x--; } else if (key == RLKey.Up) { y--; } else if (key == RLKey.Down) { y++; } if (map.IsInFov(x, y)) { _cursorPosition.X = x; _cursorPosition.Y = y; } }
public static void AddKeyboardInput(RLKey key) { if (keyDict.ContainsKey(key)) { lock (queuedInput) queuedInput.Add(keyDict[key]); } }
private bool SystemKeys(RLKey key) { if (IsPressed(RLKey.Escape)) { _rootConsole.Close(); } return(false); }
public RLKeyPress(RLKey key, bool alt, bool shift, bool control, bool repeating, bool numLock, bool capsLock, bool scrollLock) { Key = key; Alt = alt; Shift = shift; Control = control; Repeating = repeating; NumLock = numLock; CapsLock = capsLock; ScrollLock = scrollLock; }
private bool MenuKeys(RLKey key) { if (IsPressed(RLKey.Up)) { _currentMenu.Previous(); } else if (IsPressed(RLKey.Down)) { _currentMenu.Next(); } return(false); }
private bool MediumAttack(RLKey key) { if (IsPressed(RLKey.Keypad5)) { ISelfAction action = (ISelfAction)player.Actions.Find(x => x.Name == "Wait"); return(action.Execute()); } else if (MovementPressed()) { ICellAction action = (ICellAction)player.Actions.Find(x => x.Name == "Slash"); return(action.Execute(map.GetCell(player.X, player.Y), lastDirection)); } return(false); }
private void HandleLocationTargeting(RLKey key) { int x = _cursorPosition.X; int y = _cursorPosition.Y; DungeonMap map = Game.DungeonMap; if (key == RLKey.Up || key == RLKey.Keypad8) { y--; } else if (key == RLKey.Down || key == RLKey.Keypad2) { y++; } else if (key == RLKey.Left || key == RLKey.Keypad4) { x--; } else if (key == RLKey.Right || key == RLKey.Keypad6) { x++; } else if (key == RLKey.Keypad7) { y--; x--; } else if (key == RLKey.Keypad9) { y--; x++; } else if (key == RLKey.Keypad1) { y++; x--; } else if (key == RLKey.Keypad3) { y++; x++; } if (map.IsInFov(x, y)) { _cursorPosition.X = x; _cursorPosition.Y = y; } }
public bool HandleKey(RLKey key) { Player player = Game.Player; if (key == RLKey.Q) { return(player.QAbility.Perform()); } if (key == RLKey.W) { return(player.WAbility.Perform()); } if (key == RLKey.E) { return(player.EAbility.Perform()); } if (key == RLKey.R) { return(player.RAbility.Perform()); } if (key == RLKey.X || key == RLKey.L || key == RLKey.Slash) { return(player.XAbility.Perform()); } bool didUseItem = false; if (key == RLKey.Number1 && player.Item1.RemainingUses > 0) { didUseItem = player.Item1.Use(); } else if (key == RLKey.Number2 && player.Item2.RemainingUses > 0) { didUseItem = player.Item2.Use(); } else if (key == RLKey.Number3 && player.Item3.RemainingUses > 0) { didUseItem = player.Item3.Use(); } else if (key == RLKey.Number4 && player.Item4.RemainingUses > 0) { didUseItem = player.Item4.Use(); } return(didUseItem); }
public bool HandleKey(RLKey key) { if (key == RLKey.Q) { return(Game.Player.QAbility.Perform()); } if (key == RLKey.W) { return(Game.Player.WAbility.Perform()); } if (key == RLKey.E) { return(Game.Player.EAbility.Perform()); } if (key == RLKey.R) { return(Game.Player.RAbility.Perform()); } bool didUseItem = false; if (key == RLKey.Number1) { didUseItem = Game.Player.Item1.Use(); } else if (key == RLKey.Number2) { didUseItem = Game.Player.Item2.Use(); } else if (key == RLKey.Number3) { didUseItem = Game.Player.Item3.Use(); } else if (key == RLKey.Number4) { didUseItem = Game.Player.Item4.Use(); } if (didUseItem) { RemoveItemsWithNoRemainingUses(); } return(didUseItem); }
public bool CheckInput(RLKeyPress keyPress) { RLKey key = keyPress.Key; map = GameController.CurrentMap; bool didPlayerAct = false; //check if pressedKeys is still up to date for (int i = 0; i < pressedKeys.Count; i++) { RLKey k = pressedKeys[i]; if (Keyboard.GetState().IsKeyUp((Key)k)) { pressedKeys.Remove(k); i--; } } //Add currently pressed key to the list if (!pressedKeys.Contains(key)) { pressedKeys.Add(key); } lastDirection = CheckDirection(key); controlState = CheckForState(); foreach (var control in controls) { if (control.Key.Equals(controlState)) { didPlayerAct = control.Value(key); } } if (didPlayerAct) { //Add the player back into scheduling system, after taking an action(and getting a new speed) GameController.SchedulingSystem.Add(player); GameController.EndPlayerTurn(); } controlState = ResetState(); return(didPlayerAct); }
private bool Debug(RLKey key) { if (IsPressed(RLKey.S)) { Console.WriteLine("--------------------------"); int i = 0; foreach (var a in GameController.SchedulingSystem.SCHEDULEABLES) { foreach (IScheduleable b in a.Value) { i++; Console.WriteLine($"{a.Key}: {b.GetType().ToString()}"); } } Console.WriteLine("--------------------------"); Console.WriteLine($"Scheduling entities: {i - 1}"); Console.WriteLine($"Map entities: {GameController.CurrentMap.Monsters.Count}"); Console.WriteLine(); } else if (IsPressed(RLKey.I)) { Console.WriteLine("--------------------------"); foreach (var a in GameController.CurrentMap.Items) { Console.WriteLine($"{a.X}, {a.Y}"); } Console.WriteLine("--------------------------"); Console.WriteLine($"Inventory: {GameController.InventorySystem.ItemCount()}"); Console.WriteLine(); } else if (IsPressed(RLKey.C)) { GameController.ChangeLevel(true); return(false); } else if (IsPressed(RLKey.E)) { GameController.CurrentMap.RevealMap(); } return(false); }
private Direction CheckDirection(RLKey key) { if (MovementPressed()) { lastMovementKey = key; } else if (Keyboard.GetState().IsKeyUp((Key)key)) { lastMovementKey = RLKey.Unknown; } switch (lastMovementKey) { case RLKey.Keypad7: return(Direction.UpLeft); case RLKey.Keypad8: return(Direction.Up); case RLKey.Keypad9: return(Direction.UpRight); case RLKey.Keypad4: return(Direction.Left); case RLKey.Keypad6: return(Direction.Right); case RLKey.Keypad1: return(Direction.DownLeft); case RLKey.Keypad2: return(Direction.Down); case RLKey.Keypad3: return(Direction.DownRight); default: return(Direction.None); } }
private void HandleSelectableTargeting(RLKey key) { if (key == RLKey.Right || key == RLKey.Down) { _currentTargetIndex++; if (_currentTargetIndex >= _selectableTargets.Count) { _currentTargetIndex = 0; } _cursorPosition = _selectableTargets[_currentTargetIndex]; } else if (key == RLKey.Left || key == RLKey.Up) { _currentTargetIndex--; if (_currentTargetIndex < 0) { _currentTargetIndex = _selectableTargets.Count - 1; } _cursorPosition = _selectableTargets[_currentTargetIndex]; } }
public bool MovePlayer(Player player, DungeonMap dungeonMap, RLKey key) { Game.time++; x = player.X; y = player.Y; switch (key) { case RLKey.Up: { y -= 1; break; } case RLKey.Down: { y += 1; break; } case RLKey.Left: { x -= 1; break; } case RLKey.Right: { x += 1; break; } default: return(false); } return(dungeonMap.SetActorPosition(ref player, x, y)); }
public override void MovingLogic() { base.MovingLogic(); var keyPress = Program.MainConsole.Keyboard.GetKeyPress(); if (keyPress != null) { //if (keyPress.Key == lastPressedKey || keyPress.Repeating) //{ // return; //} lastPressedKey = keyPress.Key; switch (keyPress.Key) { case RLKey.W: this.TryToMove(Vector.Up); break; case RLKey.S: this.TryToMove(-Vector.Up); break; case RLKey.A: this.TryToMove(-Vector.Right); break; case RLKey.D: this.TryToMove(Vector.Right); break; case RLKey.Up: this.TryToAttack(Vector.Up); break; case RLKey.Down: this.TryToAttack(-Vector.Up); break; case RLKey.Left: this.TryToAttack(-Vector.Right); break; case RLKey.Right: this.TryToAttack(Vector.Right); break; } } else { lastPressedKey = RLKey.Unknown; } }
public bool HandleKey(RLKey key) { if (_selectionType == SelectionType.Target) { HandleSelectableTargeting(key); } else if (_selectionType == SelectionType.Area) { HandleLocationTargeting(key); } else if (_selectionType == SelectionType.Line) { HandleLocationTargeting(key); } if (key == RLKey.Enter) { _targetable.SelectTarget(_cursorPosition); StopTargeting(); return(true); } return(false); }
private void DrawInventoryMenu(RLConsole console) { int currentX = 4; int currentY = 4; var inventory = this.Floor.Player.GetComponentOfType <Component_Inventory>(); int idx = 0; foreach (var entity in inventory.InventoriedEntities) { RLKey useKey = (RLKey)(idx + 83); console.Print(currentX, currentY, useKey.ToString() + ": " + entity.Label, RLColor.Black); currentY += 2; if (currentY > Menu_Inventory.inventoryHeight - 4) { currentX = Menu_Inventory.inventoryWidth / 2; currentY = 4; } idx += 1; } }
public bool CheckInput(RLKeyPress keyPress) { RLKey key = keyPress.Key; //check if pressedKeys is still up to date for (int i = 0; i < pressedKeys.Count; i++) { RLKey k = pressedKeys[i]; if (Keyboard.GetState().IsKeyUp((Key)k)) { pressedKeys.Remove(k); i--; } } //Add currently pressed key to the list if (!pressedKeys.Contains(key)) { pressedKeys.Add(key); } MenuKeys(key); SystemKeys(key); return(true); }
public bool HandleKey(RLKey key) { bool didUseItem = false; if (key == RLKey.Number1) { if (Game.Player.items.Count > 0) { didUseItem = Game.Player.items[0].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number2) { if (Game.Player.items.Count > 1) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number3) { if (Game.Player.items.Count > 2) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number4) { if (Game.Player.items.Count > 3) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number5) { if (Game.Player.items.Count > 4) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number6) { if (Game.Player.items.Count > 5) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number7) { if (Game.Player.items.Count > 6) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number8) { if (Game.Player.items.Count > 7) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number9) { if (Game.Player.items.Count > 8) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.Number0) { if (Game.Player.items.Count > 9) { didUseItem = Game.Player.items[1].Use(); } else { Game.MessageLog.Add($"{Game.Player.Name} glances in their empty item bag."); } } else if (key == RLKey.P) { if (Game.DungeonMap.PickUpTreasure(Game.Player, Game.Player.X, Game.Player.Y)) { // PickUpTreasure is the action so meaningfully nothing } else { Game.MessageLog.Add("Nothing to pick up."); } } else if (key == RLKey.L) { /* We want to make the "Look" message interesting, so even * if there is nothing, we'll say something. */ bool sawSomething = false; ICell currentPlayerCell = Game.DungeonMap.GetCell(Game.Player.X, Game.Player.Y); List <ITreasurePile> currentPlayerCellItems = Game.DungeonMap.GetItemsAt(Game.Player.X, Game.Player.Y); if (currentPlayerCellItems != null) { for (int i = 0; i < currentPlayerCellItems.Count; i++) { if (currentPlayerCellItems[i].Treasure is HeadEquipment || currentPlayerCellItems[i].Treasure is HandEquipment || currentPlayerCellItems[i].Treasure is FeetEquipment || currentPlayerCellItems[i].Treasure is BodyEquipment) { Game.MessageLog.Add($"{Game.Player.Name} sees the {currentPlayerCellItems[i].Treasure.Name} (+{(currentPlayerCellItems[i].Treasure as IEquipment).Defense} defense)."); } else { Game.MessageLog.Add($"{Game.Player.Name} sees {currentPlayerCellItems[i].Treasure.Name}."); } } sawSomething = true; } for (int i = 0; i < Game.DungeonMap.Plants.Count; i++) { if (Game.DungeonMap.Plants[i].X == Game.Player.X && Game.DungeonMap.Plants[i].Y == Game.Player.Y) { Game.MessageLog.Add($"{Game.Player.Name} sees the {Game.DungeonMap.Plants[i].Name}."); sawSomething = true; } } for (int i = 0; i < Game.DungeonMap.Doors.Count; i++) { if (Game.DungeonMap.Doors[i].X == Game.Player.X && Game.DungeonMap.Doors[i].Y == Game.Player.Y) { // We know the door is open because the tile has to be walkable Game.MessageLog.Add($"{Game.Player.Name} sees an open door."); sawSomething = true; } } if (Game.DungeonMap.StairsUp != null) { if (Game.DungeonMap.StairsUp.X == Game.Player.X && Game.DungeonMap.StairsUp.Y == Game.Player.Y) { // We know the door is open because the tile has to be walkable Game.MessageLog.Add($"{Game.Player.Name} some stairs leading up."); sawSomething = true; } } if (Game.DungeonMap.StairsDown.X == Game.Player.X && Game.DungeonMap.StairsDown.Y == Game.Player.Y) { // We know the door is open because the tile has to be walkable Game.MessageLog.Add($"{Game.Player.Name} some stairs leading down."); sawSomething = true; } // The last ditch effort to see something interesting: scower the tiles around the player List <ICell> cellsAroundPlayer = Game.DungeonMap.GetBorderCellsInSquare(Game.Player.X, Game.Player.Y, 1).ToList(); Monster currentMonster = Game.DungeonMap.GetMonsterAt(Game.Player.X, Game.Player.Y); List <Plant> currentPlants = Game.DungeonMap.GetPlantsAt(Game.Player.X, Game.Player.Y); foreach (ICell cell in cellsAroundPlayer) { currentMonster = Game.DungeonMap.GetMonsterAt(cell.X, cell.Y); currentPlants = Game.DungeonMap.GetPlantsAt(cell.X, cell.Y); if (currentMonster != null) { Game.MessageLog.AnnounceMonster(currentMonster); sawSomething = true; } if (currentPlants != null) { foreach (Plant plant in currentPlants) { if (plant is Tree) { Game.MessageLog.Add($"{Game.Player.Name} sees a tree."); sawSomething = true; } } } } if (!sawSomething) { // TODO: Make this "default" message a bit more varied and interesting Game.MessageLog.Add($"{Game.Player.Name} sees nothing out of the ordinary."); } } if (didUseItem) { RemoveItemsWithNoRemainingUses(); } return(didUseItem); }
public InputEvent(InputComands command, RLKey key) { Command = command; Key = key; }
private bool IsPressed(RLKey key) { return(pressedKeys.Contains(key)); }