From 48ee1dfbb9d4414366a97a6d6b7875d448f4f03b Mon Sep 17 00:00:00 2001 From: Thomas Holmes Date: Fri, 16 Mar 2018 03:03:34 -0400 Subject: [PATCH] Add one button rest to full --- CHANGELOG.md | 8 ++++++-- game/controls/mapping.go | 11 +++++++---- game/creature.go | 22 ++++++++++++++++++++-- game/level.go | 12 ++++++++++++ 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 973d61f..6fe6757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ Changelog --------- * 2.0.2 - * Add the ability to cycle through font sizes on the intro screen. - * Window is resizeable at all times. + * UI + * Add the ability to cycle through font sizes on the intro screen. + * Window is resizeable at all times. + * Add some additional keypad bindings + * Gameplay + * Can rest to full while monsters not in sight by pressing r or 5. * 2.0.1 * Reduce default font size to 12 pixels. Should be a good size by default on most displays. * 2.0.0 diff --git a/game/controls/mapping.go b/game/controls/mapping.go index 81df906..ba852c5 100644 --- a/game/controls/mapping.go +++ b/game/controls/mapping.go @@ -22,7 +22,7 @@ var KeyDown = Mapping{Name: "Down", Action: Down, Keys: []string{"J", "KP_2", "D var KeyDownLeft = Mapping{Name: "DownLeft", Action: DownLeft, Keys: []string{"B", "KP_1"}, SdlKeys: []sdl.Keycode{sdl.K_b, sdl.K_KP_1}} var KeyLeft = Mapping{Name: "Left", Action: Left, Keys: []string{"H", "KP_4", "LEFT"}, SdlKeys: []sdl.Keycode{sdl.K_h, sdl.K_KP_4, sdl.K_LEFT}} var KeyUpLeft = Mapping{Name: "UpLeft", Action: UpLeft, Keys: []string{"Y", "KP_7"}, SdlKeys: []sdl.Keycode{sdl.K_y, sdl.K_KP_7}} -var KeyFive = Mapping{Name: "Wait", Action: Wait, Keys: []string{".", "KP_.", "5"}, SdlKeys: []sdl.Keycode{sdl.K_PERIOD, sdl.K_5, sdl.K_KP_5, sdl.K_KP_PERIOD}} +var KeyPeriod = Mapping{Name: "Wait", Action: Wait, Keys: []string{".", "KP_."}, SdlKeys: []sdl.Keycode{sdl.K_PERIOD, sdl.K_KP_PERIOD}} var KeyGreater = Mapping{Name: "Descend", Action: Descend, Keys: []string{">"}, SdlKeys: []sdl.Keycode{sdl.K_PERIOD}, Shift: true} var KeyLesser = Mapping{Name: "Ascend", Action: Ascend, Keys: []string{"<"}, SdlKeys: []sdl.Keycode{sdl.K_COMMA}, Shift: true} @@ -30,14 +30,15 @@ var KeyQuestion = Mapping{Name: "Help", Action: Help, Keys: []string{"?"}, SdlKe var KeyM = Mapping{Name: "Messages", Action: Messages, Keys: []string{"M"}, SdlKeys: []sdl.Keycode{sdl.K_m}} var KeyE = Mapping{Name: "Equip", Action: Equip, Keys: []string{"E"}, SdlKeys: []sdl.Keycode{sdl.K_e}, HideHelp: true} -var KeyI = Mapping{Name: "Inventory", Action: Inventory, Keys: []string{"I"}, SdlKeys: []sdl.Keycode{sdl.K_i}} +var KeyI = Mapping{Name: "Inventory", Action: Inventory, Keys: []string{"I", "KP--"}, SdlKeys: []sdl.Keycode{sdl.K_i, sdl.K_KP_MINUS}} var KeyB = Mapping{Name: "Warp", Action: Warp, Keys: []string{"W", "KP_+"}, SdlKeys: []sdl.Keycode{sdl.K_w, sdl.K_KP_PLUS}} var KeyQ = Mapping{Name: "Quaff", Action: Quaff, Keys: []string{"Q"}, SdlKeys: []sdl.Keycode{sdl.K_q}, HideHelp: true} var KeyA = Mapping{Name: "Activate", Action: Activate, Keys: []string{"A"}, SdlKeys: []sdl.Keycode{sdl.K_a}, HideHelp: true} -var KeyX = Mapping{Name: "Examine", Action: Examine, Keys: []string{"X"}, SdlKeys: []sdl.Keycode{sdl.K_x}} +var KeyX = Mapping{Name: "Examine", Action: Examine, Keys: []string{"X", "KP_*"}, SdlKeys: []sdl.Keycode{sdl.K_x, sdl.K_KP_MULTIPLY}} var KeyG = Mapping{Name: "Get", Action: Get, Keys: []string{"G"}, SdlKeys: []sdl.Keycode{sdl.K_g}} var KeyT = Mapping{Name: "Throw", Action: Throw, Keys: []string{"T"}, SdlKeys: []sdl.Keycode{sdl.K_t}, HideHelp: true} var KeyD = Mapping{Name: "Drop", Action: Drop, Keys: []string{"D"}, SdlKeys: []sdl.Keycode{sdl.K_d}, HideHelp: true} +var KeyR = Mapping{Name: "Rest", Action: Rest, Keys: []string{"R", "KP_5", "5"}, SdlKeys: []sdl.Keycode{sdl.K_r, sdl.K_KP_5, sdl.K_5}} var KeyCQ = Mapping{Name: "Quit", Action: Quit, Keys: []string{"CTRL-Q"}, SdlKeys: []sdl.Keycode{sdl.K_q}, Control: true} @@ -59,7 +60,7 @@ var AllMappings = []*Mapping{ &KeyUpLeft, &KeyGreater, &KeyLesser, - &KeyFive, + &KeyPeriod, &KeyEsc, &KeyM, &KeyE, @@ -71,6 +72,7 @@ var AllMappings = []*Mapping{ &KeyG, &KeyT, &KeyD, + &KeyR, &KeyEnter, &KeyQuestion, &KeyCQ, @@ -105,6 +107,7 @@ const ( Throw Drop Examine + Rest Get Confirm Help diff --git a/game/creature.go b/game/creature.go index 3277ad2..3359a7f 100644 --- a/game/creature.go +++ b/game/creature.go @@ -65,6 +65,8 @@ type Creature struct { State MonsterBehavior + Resting bool + X int Y int @@ -332,6 +334,10 @@ func (creature *Creature) EndGame() { m.Broadcast(m.M{ID: FoodSpoiled}) } +func (player *Creature) Safe(world *World) bool { + return !world.CurrentLevel().CreatureInSight() +} + // Update returns true if an action that would constitute advancing the turn took place func (creature *Creature) Update(turn uint64, action controls.Action, world *World) bool { success := false @@ -340,8 +346,17 @@ func (creature *Creature) Update(turn uint64, action controls.Action, world *Wor if creature.IsFoodRuined() { creature.EndGame() return true + } else if creature.Resting { + if creature.HP.Current >= creature.HP.Max { + creature.Resting = false + } else if !creature.Safe(world) { + creature.Resting = false + } else { + success = true + } + } else { + success = creature.HandleInput(action, world) } - success = creature.HandleInput(action, world) } else { success = creature.Pursue(turn, world) } @@ -498,6 +513,10 @@ func (player *Creature) HandleInput(action controls.Action, world *World) bool { gl.Append("Costs at least 1 ST to Warp.") } return false + case controls.Rest: + if player.Safe(world) { + player.Resting = true + } case controls.Messages: m.Broadcast(m.M{ID: ShowFullGameLog}) return false @@ -600,7 +619,6 @@ func (creature *Creature) Notify(message m.M) { if d, ok := message.Data.(PlayerDropItemMessage); ok { creature.DropItem(d.Item, d.World) } - case PlayerWarp: if d, ok := message.Data.(PlayerWarpMessage); ok { creature.TryWarp(d.World, d.TargetX, d.TargetY, d.Cost) diff --git a/game/level.go b/game/level.go index 71454b8..03b80a9 100644 --- a/game/level.go +++ b/game/level.go @@ -60,6 +60,18 @@ func (level *Level) GetCreatureAtTile(xPos int, yPos int) (*Creature, bool) { return nil, false } +func (level *Level) CreatureInSight() bool { + for _, t := range level.Tiles { + if level.VisionMap.VisibilityAt(t.X, t.Y) == Visible && + t.Creature != nil && + t.Creature.Team == MonsterTeam { + return true + } + } + + return false +} + // GetVisibleCreatures returns a slice of creatures sorted so that the first is the closest // based on euclidean distance. func (level *Level) GetVisibleCreatures(originX int, originY int) []*Creature {