Skip to content
Permalink
Browse files

Render drill powerup and indicator

  • Loading branch information...
jhb563 committed May 9, 2019
1 parent 1e768db commit a854fea5d07320f95c5aa42cba66b126468b4678
Showing with 42 additions and 4 deletions.
  1. +7 −0 src/JSONInstances.hs
  2. +10 −1 src/OptionsParser.hs
  3. +21 −2 src/Runner.hs
  4. +4 −1 src/Types.hs
@@ -187,6 +187,9 @@ instance ToJSON PlayerRenderParameters where
, "baseColor" .= (ColorWrapper (playerIndicatorColor prp))
, "stunIndicatorSize" .= playerStunIndicatorSize prp
, "stunIndicatorColor" .= (ColorWrapper (playerStunIndicatorColor prp))
, "drillPowerupSize" .= playerDrillPowerupSize prp
, "drillIndicatorSize" .= playerDrillIndicatorSize prp
, "drillColor" .= (ColorWrapper (playerDrillColor prp))
]

instance FromJSON PlayerRenderParameters where
@@ -195,7 +198,11 @@ instance FromJSON PlayerRenderParameters where
(ColorWrapper baseColor) <- o .: "baseColor"
stunSize <- o .: "stunIndicatorSize"
(ColorWrapper stunColor) <- o .: "stunIndicatorColor"
drillPowerupSize <- o .: "drillPowerupSize"
drillIndicatorSize <- o .: "drillIndicatorSize"
(ColorWrapper drillColor) <- o .: "drillColor"
return $ PlayerRenderParameters size baseColor stunSize stunColor
drillPowerupSize drillIndicatorSize drillColor

instance ToJSON EnemyRenderParameters where
toJSON erp = object
@@ -23,6 +23,9 @@ data RenderParamInfo = RenderParamInfo
(Maybe Color)
(Maybe Float)
(Maybe Color)
(Maybe Float)
(Maybe Float)
(Maybe Color)
-- Enemy Parameters
(Maybe Float)
(Maybe Color)
@@ -68,6 +71,9 @@ parseRenderInfo = RenderParamInfo <$>
maybeColorParser (long "player-color" <> help "The player indicator color") <*>
maybeFloatParser (long "stun-indicator-size" <> help "The player's stun indicator size") <*>
maybeColorParser (long "stun-indicator-color" <> help "The player's stun indicator color") <*>
maybeFloatParser (long "drill-size" <> help "The size of drill powerups") <*>
maybeFloatParser (long "drill-indicator-size" <> help "The player's drill indicator size") <*>
maybeColorParser (long "" <> help "The drill powerup and indicator color") <*>
maybeFloatParser (long "enemy-size" <> help "The enemy indicator size") <*>
maybeColorParser (long "enemy-base-color" <> help "The enemy's normal color") <*>
maybeColorParser (long "enemy-stun-color" <> help "The enemy's stunned color") <*>
@@ -78,7 +84,7 @@ parseRenderInfo = RenderParamInfo <$>
mergeOptions :: RenderParameters -> RenderParamInfo -> RenderParameters
mergeOptions
rp
(RenderParamInfo sd_ sox_ soy_ tox_ toy_ tsx_ tsy_ pis_ pic_ psis_ psic_ es_ ebc_ esc_ cwc_ csc_ cww_)
(RenderParamInfo sd_ sox_ soy_ tox_ toy_ tsx_ tsy_ pis_ pic_ psis_ psic_ dps_ dis_ dc_ es_ ebc_ esc_ cwc_ csc_ cww_)
= RenderParameters
(fromMaybe (screenDimen rp) sd_)
(fromMaybe (screenOffsetX rp) sox_)
@@ -90,6 +96,9 @@ mergeOptions
(fromMaybe (playerIndicatorColor prp) pic_)
(fromMaybe (playerStunIndicatorSize prp) psis_)
(fromMaybe (playerStunIndicatorColor prp) psic_)
(fromMaybe (playerDrillPowerupSize prp) dps_)
(fromMaybe (playerDrillIndicatorSize prp) dis_)
(fromMaybe (playerDrillColor prp) dc_)
)
(EnemyRenderParameters
(fromMaybe (enemySize erp) es_)
@@ -73,7 +73,13 @@ drawingFunc rp world
| worldResult world == GameLost = Translate textOffsetX textOffsetY $ Scale textScaleX textScaleY
(Text "Oh no! You've lost! Press enter to restart this maze!")
| otherwise = Pictures
[mapGrid, startPic, endPic, playerMarker, Pictures (enemyPic <$> worldEnemies world)]
[ mapGrid
, startPic
, endPic
, playerMarker
, Pictures (enemyPic <$> worldEnemies world)
, Pictures (drillPic <$> worldDrillPowerUpLocations world)
]
where
(textOffsetX, textOffsetY) = textOffset rp
(textScaleX, textScaleY) = textScale rp
@@ -84,11 +90,14 @@ drawingFunc rp world
(px, py) = cellCenter (conversion (playerLocation (worldPlayer world)))

playerRP = playerRenderParameters rp
drillReadyMarker = if playerDrillsRemaining (worldPlayer world) > 0
then Color (playerDrillColor playerRP) (Circle (playerDrillIndicatorSize playerRP))
else Blank
stunReadyCircle = if playerCurrentStunDelay (worldPlayer world) == 0
then Color (playerStunIndicatorColor playerRP) (Circle (playerStunIndicatorSize playerRP))
else Blank
playerIndicator = Color (playerIndicatorColor playerRP) $ Circle (playerIndicatorSize playerRP)
playerMarker = translate px py (Pictures [stunReadyCircle, playerIndicator])
playerMarker = translate px py (Pictures [drillReadyMarker, stunReadyCircle, playerIndicator])

startCoords = conversion (startLocation world)
endCoords = conversion (endLocation world)
@@ -142,6 +151,16 @@ drawingFunc rp world
enemyColor = if currentStun == 0 then enemyBaseColor enemyParams else enemyStunnedColor enemyParams
in Color enemyColor (Polygon [tl, tr, br, bl])

drillPic :: Location -> Picture
drillPic loc =
let (centerX, centerY) = cellCenter $ conversion loc
radius = playerDrillPowerupSize playerRP
top = (centerX, centerY + radius)
br = (centerX + radius, centerY - radius)
bl = (centerX - radius, centerY - radius)
drillColor = playerDrillColor playerRP
in Color drillColor (Polygon [top, br, bl])

inputHandler :: Event -> World -> World
inputHandler event w
| worldResult w == GameWon = case event of
@@ -112,6 +112,9 @@ data PlayerRenderParameters = PlayerRenderParameters
, playerIndicatorColor :: Color
, playerStunIndicatorSize :: Float
, playerStunIndicatorColor :: Color
, playerDrillPowerupSize :: Float
, playerDrillIndicatorSize :: Float
, playerDrillColor :: Color
}

data EnemyRenderParameters = EnemyRenderParameters
@@ -130,6 +133,6 @@ defaultRenderParameters :: RenderParameters
defaultRenderParameters = RenderParameters
625 10 10 (-275, 0) (0.12, 0.25) playerParams enemyParams cellParams
where
playerParams = PlayerRenderParameters 10 black 5 red
playerParams = PlayerRenderParameters 10 black 5 red 5.0 2.0 violet
enemyParams = EnemyRenderParameters 10 orange yellow
cellParams = CellRenderParameters blue cyan 2

0 comments on commit a854fea

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