diff --git a/assets/gui/main.png b/assets/gui/main.png new file mode 100644 index 0000000..1d2ae6e Binary files /dev/null and b/assets/gui/main.png differ diff --git a/lib/RPGEngine/Config.hs b/lib/RPGEngine/Config.hs index 3d4f938..66af492 100644 --- a/lib/RPGEngine/Config.hs +++ b/lib/RPGEngine/Config.hs @@ -23,6 +23,10 @@ bgColor = makeColor (37 / 256) (19 / 256) (26 / 256) 1 textColor :: Color textColor = white +-- Color of selection +selectionColor :: Color +selectionColor = red + -- Default scale zoom :: Float zoom = 5 diff --git a/lib/RPGEngine/Data/Game.hs b/lib/RPGEngine/Data/Game.hs index bd1cae4..da239a5 100644 --- a/lib/RPGEngine/Data/Game.hs +++ b/lib/RPGEngine/Data/Game.hs @@ -5,7 +5,7 @@ module RPGEngine.Data.Game ) where import RPGEngine.Data - ( Player(Player, position), + ( Player(..), Direction, Physical(Exit, Walkable, Entrance), State(..), @@ -33,4 +33,5 @@ isPlayerAtExit _ = False -- Check if the players health is <= 0, which means the player is dead. isPlayerDead :: Game -> Bool -isPlayerDead _ = False \ No newline at end of file +isPlayerDead g@Game{ state = Playing{ player = Player{ playerHp = (Just hp)}}} = hp <= 0 +isPlayerDead _ = False diff --git a/lib/RPGEngine/Input/Lose.hs b/lib/RPGEngine/Input/Lose.hs index 007a25f..a7ff57e 100644 --- a/lib/RPGEngine/Input/Lose.hs +++ b/lib/RPGEngine/Input/Lose.hs @@ -2,11 +2,16 @@ module RPGEngine.Input.Lose ( handleInputLose ) where -import RPGEngine.Input.Core (InputHandler) +import RPGEngine.Input.Core (InputHandler, handleAnyKey) -import RPGEngine.Data (Game) +import RPGEngine.Data (Game(..), State(..)) ------------------------------ Exported ------------------------------ handleInputLose :: InputHandler Game -handleInputLose = undefined \ No newline at end of file +handleInputLose = handleAnyKey retry + +---------------------------------------------------------------------- + +retry :: Game -> Game +retry g@Game{ state = Lose{ restart = restart }} = g{ state = restart } \ No newline at end of file diff --git a/lib/RPGEngine/Input/Playing.hs b/lib/RPGEngine/Input/Playing.hs index 6ca8f47..3068d24 100644 --- a/lib/RPGEngine/Input/Playing.hs +++ b/lib/RPGEngine/Input/Playing.hs @@ -50,7 +50,7 @@ checkPlaying g@Game{ state = s@Playing{ restart = restart }} = newGame where newGame | isPlayerDead g = loseGame | isPlayerAtExit g = g{ state = goToNextLevel s } | otherwise = g - loseGame = g{ state = restart } + loseGame = g{ state = Lose{ restart = restart }} checkPlaying g = g pauseGame :: Game -> Game diff --git a/lib/RPGEngine/Render/Core.hs b/lib/RPGEngine/Render/Core.hs index e901243..0c6754c 100644 --- a/lib/RPGEngine/Render/Core.hs +++ b/lib/RPGEngine/Render/Core.hs @@ -44,6 +44,7 @@ allItems = [ allGui :: [(String, FilePath)] allGui = [ + ("main", "main.png"), ("health", "health.png") ] diff --git a/lib/RPGEngine/Render/LevelSelection.hs b/lib/RPGEngine/Render/LevelSelection.hs index 85dc81c..082a8a1 100644 --- a/lib/RPGEngine/Render/LevelSelection.hs +++ b/lib/RPGEngine/Render/LevelSelection.hs @@ -4,7 +4,7 @@ module RPGEngine.Render.LevelSelection import RPGEngine.Render.Core (Renderer) -import RPGEngine.Config (resolution, zoom, uizoom) +import RPGEngine.Config (resolution, zoom, uizoom, textColor, selectionColor ) import RPGEngine.Data (State (..)) import Graphics.Gloss ( pictures, color, text, translate, blank ) @@ -25,7 +25,8 @@ renderLevelList LevelSelection{ levelList = list, selector = selector } = everyt where everything = pictures $ map render entries sel = selection selector entries = zip [0::Int .. ] list - render (i, path) | i == sel = color red $ scale uizoom uizoom $ translate 0 (offset i) $ text path - | otherwise = scale uizoom uizoom $ translate 0 (offset i) $ text path + render (i, path) | i == sel = color selectionColor $ make (i, path) + | otherwise = color textColor $ make (i, path) + make (i, path) = scale uizoom uizoom $ translate 0 (offset i) $ text path offset i = negate (250 * uizoom * fromIntegral i) renderLevelList _ = blank \ No newline at end of file diff --git a/lib/RPGEngine/Render/Lose.hs b/lib/RPGEngine/Render/Lose.hs index 1e6d730..cd1cfad 100644 --- a/lib/RPGEngine/Render/Lose.hs +++ b/lib/RPGEngine/Render/Lose.hs @@ -1,15 +1,21 @@ module RPGEngine.Render.Lose ( renderLose ) where - import RPGEngine.Render.Core (Renderer) +import RPGEngine.Config (uizoom, textColor) import RPGEngine.Data (State) -import Graphics.Gloss (text) +import Graphics.Gloss (text, scale, color, translate) + +------------------------------ Constants ----------------------------- + +message :: String +message = "You lose! Press any key to retry." ------------------------------ Exported ------------------------------ --- TODO renderLose :: Renderer State -renderLose _ = text "You lose" \ No newline at end of file +renderLose _ = scaled $ center $ color textColor $ text message + where scaled = scale uizoom uizoom + center = translate (-1200) 0 \ No newline at end of file diff --git a/lib/RPGEngine/Render/Menu.hs b/lib/RPGEngine/Render/Menu.hs index 473c96c..e9251e4 100644 --- a/lib/RPGEngine/Render/Menu.hs +++ b/lib/RPGEngine/Render/Menu.hs @@ -2,16 +2,23 @@ module RPGEngine.Render.Menu ( renderMenu ) where -import RPGEngine.Render.Core (Renderer) +import RPGEngine.Render.Core (Renderer, getRender) import RPGEngine.Config ( uizoom, textColor ) import RPGEngine.Data (State) -import Graphics.Gloss (text, scale, color, white, translate) +import Graphics.Gloss (text, scale, color, translate, pictures) + +------------------------------ Constants ----------------------------- + +message :: String +message = "[Press any key to start]" ------------------------------ Exported ------------------------------ renderMenu :: Renderer State -renderMenu _ = scaled $ center $ color textColor $ text "[Press any key to start]" - where scaled = scale uizoom uizoom - center = translate (-750) 0 \ No newline at end of file +renderMenu _ = pictures [main, pressAny] + where pressAny = scaled $ center $ color textColor $ text message + scaled = scale uizoom uizoom + center = translate (-800) (-320) + main = getRender "main" \ No newline at end of file diff --git a/lib/RPGEngine/Render/Win.hs b/lib/RPGEngine/Render/Win.hs index 189cef8..abaa095 100644 --- a/lib/RPGEngine/Render/Win.hs +++ b/lib/RPGEngine/Render/Win.hs @@ -4,12 +4,19 @@ module RPGEngine.Render.Win import RPGEngine.Render.Core (Renderer) +import RPGEngine.Config (uizoom, textColor) import RPGEngine.Data (State) -import Graphics.Gloss (text) +import Graphics.Gloss (text, scale, color, translate) + +------------------------------ Constants ----------------------------- + +message :: String +message = "You win! Press any key to return to the menu." ------------------------------ Exported ------------------------------ --- TODO renderWin :: Renderer State -renderWin _ = text "You win!\nPress any key to return to the menu." \ No newline at end of file +renderWin _ = scaled $ center $ color textColor $ text message + where scaled = scale uizoom uizoom + center = translate (-1500) 0 \ No newline at end of file