80 lines
No EOL
2.1 KiB
Haskell
80 lines
No EOL
2.1 KiB
Haskell
-- Allows to play a game using RPGEngine.
|
|
-- Includes all logic and rendering.
|
|
|
|
module RPGEngine
|
|
( playRPGEngine
|
|
) where
|
|
|
|
import RPGEngine.Config ( bgColor, winDimensions, winOffsets )
|
|
import RPGEngine.Render ( initWindow, render )
|
|
import RPGEngine.Input ( handleAllInput )
|
|
import RPGEngine.Input.Playing ( checkPlaying, spawnPlayer )
|
|
import RPGEngine.Data (Game (..), State (..), Layout, Level (..), Physical (..))
|
|
import RPGEngine.Data.Default (defaultLevel, defaultPlayer)
|
|
|
|
import Graphics.Gloss ( play )
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
-- This is the game loop.
|
|
-- It can receive input and update itself. It is rendered by a renderer.
|
|
playRPGEngine :: String -> Int -> IO()
|
|
playRPGEngine title fps = do
|
|
play window bgColor fps initGame render handleAllInput step
|
|
where window = initWindow title winDimensions winOffsets
|
|
step _ = checkPlaying -- TODO Do something with step? Check health etc.
|
|
|
|
-- TODO revert this
|
|
-- Initialize the game
|
|
initGame :: Game
|
|
-- initGame = Game {
|
|
-- state = Menu{ base = StateBase{
|
|
-- renderer = renderMenu,
|
|
-- inputHandler = handleInputMenu
|
|
-- }}
|
|
-- }
|
|
initGame = Game{
|
|
state = initState
|
|
}
|
|
where initState = Playing{
|
|
levels = [defaultLevel, otherLevel],
|
|
count = 0,
|
|
level = defaultLevel,
|
|
player = spawnPlayer defaultLevel defaultPlayer,
|
|
restart = initState
|
|
}
|
|
|
|
-- TODO remove this
|
|
otherLayout :: Layout
|
|
otherLayout = [
|
|
[Blocked, Blocked, Blocked],
|
|
[Blocked, Entrance, Blocked],
|
|
[Blocked, Walkable, Blocked],
|
|
[Blocked, Exit, Blocked],
|
|
[Blocked, Blocked, Blocked]
|
|
]
|
|
|
|
-- TODO remove this
|
|
otherLevel :: Level
|
|
otherLevel = Level {
|
|
layout = otherLayout,
|
|
index = [
|
|
(0, 0, Blocked),
|
|
(1, 0, Blocked),
|
|
(2, 0, Blocked),
|
|
(0, 1, Blocked),
|
|
(1, 1, Entrance),
|
|
(2, 1, Blocked),
|
|
(0, 2, Blocked),
|
|
(1, 2, Walkable),
|
|
(2, 2, Blocked),
|
|
(0, 3, Blocked),
|
|
(1, 3, Exit),
|
|
(2, 3, Blocked),
|
|
(0, 4, Blocked),
|
|
(1, 4, Blocked),
|
|
(2, 4, Blocked)
|
|
],
|
|
items = [],
|
|
entities = []
|
|
} |