Skip to content

Commit

Permalink
Add hitpoints to player model
Browse files Browse the repository at this point in the history
  • Loading branch information
chendrix committed Jul 3, 2015
1 parent 7d1feb1 commit 9b5a404
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/Rogue.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Numpad
import Rogue.Model exposing (..)
import Rogue.Update exposing (..)
import Rogue.View exposing (..)
import Signal exposing ((<~), (~), Signal)

-- SIGNALS

Expand All @@ -18,8 +19,9 @@ gameState =

input : Signal Input
input =
Signal.map Input <| Signal.mergeMany
[ Keyboard.wasd
, Keyboard.arrows
, Numpad.numpad
]
Input <~
Signal.mergeMany
[ Keyboard.wasd
, Keyboard.arrows
, Numpad.numpad
]
4 changes: 3 additions & 1 deletion src/Rogue/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import Now

type alias GameMap = Matrix Cell

type alias HitPoints = Int
type alias Player =
{ inventory : List Item
, hp : HitPoints
}

type alias Game =
Expand Down Expand Up @@ -39,7 +41,7 @@ type alias Input =
}

newPlayer : Player
newPlayer = {inventory = []}
newPlayer = {inventory = [], hp = 100}

randomizeLocationsWithin : Int -> Int -> List Location
randomizeLocationsWithin size numLocations =
Expand Down
8 changes: 6 additions & 2 deletions src/Rogue/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ viewCell curLocation cellLocation c =
Barrier _ -> barrier

viewPlayer : Player -> Element
viewPlayer {inventory} =
txt (String.join "" ["Item Count: ", List.length inventory |> toString ])
viewPlayer {inventory, hp} =
flow down
[ txt (String.join "" ["Item Count: ", List.length inventory |> toString ])
, txt (String.join "" ["Current HP: ", hp |> toString ])
]


txt str =
Text.fromString str
Expand Down

0 comments on commit 9b5a404

Please sign in to comment.