Skip to content

Commit

Permalink
Add one button rest to full
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-holmes committed Mar 16, 2018
1 parent 312ce46 commit 48ee1df
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions game/controls/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ 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}

var KeyQuestion = Mapping{Name: "Help", Action: Help, Keys: []string{"?"}, SdlKeys: []sdl.Keycode{sdl.K_SLASH}, Shift: true}

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}

Expand All @@ -59,7 +60,7 @@ var AllMappings = []*Mapping{
&KeyUpLeft,
&KeyGreater,
&KeyLesser,
&KeyFive,
&KeyPeriod,
&KeyEsc,
&KeyM,
&KeyE,
Expand All @@ -71,6 +72,7 @@ var AllMappings = []*Mapping{
&KeyG,
&KeyT,
&KeyD,
&KeyR,
&KeyEnter,
&KeyQuestion,
&KeyCQ,
Expand Down Expand Up @@ -105,6 +107,7 @@ const (
Throw
Drop
Examine
Rest
Get
Confirm
Help
Expand Down
22 changes: 20 additions & 2 deletions game/creature.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type Creature struct {

State MonsterBehavior

Resting bool

X int
Y int

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions game/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 48ee1df

Please sign in to comment.