add back player input
This commit is contained in:
1 parent
00970d2bd6
commit
b40217f70a
1 file changed
+12
-2
+12
-2
@@ -10,6 +10,8 @@ structure EngineState where
|
||||
deltaTime : Float
|
||||
lastTime : UInt32
|
||||
running : Bool
|
||||
playerX : Int32
|
||||
playerY : Int32
|
||||
|
||||
def SCREEN_WIDTH : Int32 := 1280
|
||||
def SCREEN_HEIGHT : Int32 := 720
|
||||
@@ -36,7 +38,7 @@ def renderScene (state : EngineState) : IO Unit := do
|
||||
let _ ← SDL.renderClear
|
||||
|
||||
setColor { r := 255, g := 0, b := 0 }
|
||||
fillRect 100 100 200 200
|
||||
fillRect state.playerX state.playerY 100 100
|
||||
|
||||
let _ ← SDL.renderTexture 500 150 64 64
|
||||
|
||||
@@ -48,7 +50,14 @@ private def updateEngineState (engineState : IO.Ref EngineState) : IO Unit := do
|
||||
let state ← engineState.get
|
||||
let currentTime ← SDL.getTicks
|
||||
let deltaTime := (currentTime - state.lastTime).toFloat / 1000.0
|
||||
engineState.set { state with deltaTime, lastTime := currentTime }
|
||||
|
||||
let mut playerX := state.playerX
|
||||
let mut playerY := state.playerY
|
||||
if ← isKeyDown .A then playerX := playerX - 1
|
||||
if ← isKeyDown .D then playerX := playerX + 1
|
||||
if ← isKeyDown .W then playerY := playerY - 1
|
||||
if ← isKeyDown .S then playerY := playerY + 1
|
||||
engineState.set { state with deltaTime, lastTime := currentTime, playerX, playerY }
|
||||
|
||||
partial def gameLoop (engineState : IO.Ref EngineState) : IO Unit := do
|
||||
updateEngineState engineState
|
||||
@@ -93,6 +102,7 @@ partial def run : IO Unit := do
|
||||
|
||||
let initialState : EngineState := {
|
||||
deltaTime := 0.0, lastTime := 0, running := true
|
||||
playerX := (SCREEN_WIDTH / 2), playerY := (SCREEN_HEIGHT / 2)
|
||||
}
|
||||
|
||||
let engineState ← IO.mkRef initialState
|
||||
|
||||
Reference in new issue
Block a user