Skip to content
Permalink
Browse files

Add drills data

  • Loading branch information...
jhb563 committed May 7, 2019
1 parent c7528b0 commit 6ff526ed3d384ded60d3bf73f0b5812c2fcd71db
Showing with 15 additions and 6 deletions.
  1. +6 −2 src/JSONInstances.hs
  2. +6 −3 src/Runner.hs
  3. +3 −1 src/Types.hs
@@ -52,13 +52,15 @@ instance FromJSON Player where
location <- o .: "location"
currentStunDelay <- o .: "currentStunDelay"
nextStunDelay <- o .: "nextStunDelay"
return $ Player location currentStunDelay nextStunDelay
drillsRemaining <- o .: "drillsRemaining"
return $ Player location currentStunDelay nextStunDelay drillsRemaining

instance ToJSON Player where
toJSON p = object
[ "location" .= playerLocation p
, "currentStunDelay" .= playerCurrentStunDelay p
, "nextStunDelay" .= playerNextStunDelay p
, "drillsRemaining" .= playerDrillsRemaining p
]

instance FromJSON Enemy where
@@ -119,14 +121,16 @@ instance FromJSON PlayerGameParameters where
stunIncrease <- o .: "stunTimerIncrease"
stunMax <- o .: "stunTimerMax"
radius <- o .: "stunRadius"
return $ PlayerGameParameters initialStunTimer stunIncrease stunMax radius
drills <- o .: "initialDrills"
return $ PlayerGameParameters initialStunTimer stunIncrease stunMax radius drills

instance ToJSON PlayerGameParameters where
toJSON pp = object
[ "initialStunTimer" .= initialStunTimer pp
, "stunTimerIncrease" .= stunTimerIncrease pp
, "stunTimerMax" .= stunTimerMax pp
, "stunRadius" .= stunRadius pp
, "initialDrills" .= initialDrills pp
]

instance FromJSON EnemyGameParameters where
@@ -264,7 +264,7 @@ mkNewEnemy :: EnemyGameParameters -> Location -> Enemy
mkNewEnemy params loc = Enemy loc (initialLagTime params) (initialStunTime params) 0

newPlayer :: PlayerGameParameters -> Player
newPlayer params = Player (0, 0) 0 (initialStunTimer params)
newPlayer params = Player (0, 0) 0 (initialStunTimer params) (initialDrills params)

-- Mutators

@@ -275,9 +275,12 @@ clearStunCells :: World -> World
clearStunCells w = w { stunCells = []}

activatePlayerStun :: Player -> PlayerGameParameters -> Player
activatePlayerStun (Player loc _ nextStunTimer) params =
Player loc nextStunTimer newNextStun
activatePlayerStun pl params = pl
{ playerCurrentStunDelay = nextStunTimer
, playerNextStunDelay = newNextStun
}
where
nextStunTimer = playerNextStunDelay pl
newNextStun = min (stunTimerMax params) (nextStunTimer + (stunTimerIncrease params))

stunEnemy :: Enemy -> EnemyGameParameters -> Enemy
@@ -36,6 +36,7 @@ data Player = Player
{ playerLocation :: Location
, playerCurrentStunDelay :: Word
, playerNextStunDelay :: Word
, playerDrillsRemaining :: Word
}

data Enemy = Enemy
@@ -73,6 +74,7 @@ data PlayerGameParameters = PlayerGameParameters
, stunTimerIncrease :: Word
, stunTimerMax :: Word
, stunRadius :: Int
, initialDrills :: Word
}

data EnemyGameParameters = EnemyGameParameters
@@ -89,7 +91,7 @@ defaultGameParameters = GameParameters
25 25 4 20 playerParams enemyParams Nothing
where
playerParams = PlayerGameParameters
200 10 (maxBound :: Word) 2
200 10 (maxBound :: Word) 2 2
enemyParams = EnemyGameParameters 60 5 20 5 20 10

data RenderParameters = RenderParameters

0 comments on commit 6ff526e

Please sign in to comment.
You can’t perform that action at this time.