Refactored world runner.
[hollow-plutonium.git] / Player.hs
blob43be952f0abb885898bb6e4ed69af67ca96982d1
1 module Player where
4 data Player = Player {
5 fire :: Bool,
6 dir :: (Int,Int),
7 shots :: Int,
8 lives :: Int
9 } deriving (Show)
12 setFire :: Bool -> Player -> Player
13 setFire tf pl = pl { fire = tf }
15 addDir :: (Int,Int) -> Player -> Player
16 addDir (dx,dy) pl = pl { dir = (x',y') } where
17 (x',y') = (clamp (x+dy), clamp (y+dy))
18 (x,y) = dir pl
19 clamp = signum
21 subDir :: (Int,Int) -> Player -> Player
22 subDir dxdy pl = addDir (-dxdy) pl
24 incShots pl = pl { shots = succ (shots pl) }
25 decShots pl = pl { shots = pred (shots pl) }
26 incLives pl = pl { lives = succ (lives pl) }
27 decLives pl = pl { lives = pred (lives pl) }