add player walking on map
This commit is contained in:
30
game.sex
30
game.sex
@@ -13,6 +13,11 @@
|
|||||||
#+emscripten (define WIN-WIDTH 960)
|
#+emscripten (define WIN-WIDTH 960)
|
||||||
#+emscripten (define WIN-HEIGHT 600)
|
#+emscripten (define WIN-HEIGHT 600)
|
||||||
|
|
||||||
|
(var TILE-SIZE float 1.0f)
|
||||||
|
|
||||||
|
(defmacro (clamp-to-grid v)
|
||||||
|
`(* (/ (cast ,v i64) TILE-SIZE) TILE-SIZE))
|
||||||
|
|
||||||
(pub record game-state
|
(pub record game-state
|
||||||
((app-state (* app-state))
|
((app-state (* app-state))
|
||||||
(map (* tmx-map))
|
(map (* tmx-map))
|
||||||
@@ -37,6 +42,9 @@
|
|||||||
(= (. state cam target y) 0.0)
|
(= (. state cam target y) 0.0)
|
||||||
(return (page/game state))))
|
(return (page/game state))))
|
||||||
|
|
||||||
|
;; Assume width = height (true for our map)
|
||||||
|
(= TILE-SIZE (. map tile-width))
|
||||||
|
|
||||||
(var object-count int (tmx-object-count map "FIH"))
|
(var object-count int (tmx-object-count map "FIH"))
|
||||||
(TraceLog LOG-INFO "FIH has %d object(s)" object-count)
|
(TraceLog LOG-INFO "FIH has %d object(s)" object-count)
|
||||||
|
|
||||||
@@ -53,9 +61,11 @@
|
|||||||
(var player-width float (tmx-object-width map "FIH" 0))
|
(var player-width float (tmx-object-width map "FIH" 0))
|
||||||
(var player-height float (tmx-object-height map "FIH" 0))
|
(var player-height float (tmx-object-height map "FIH" 0))
|
||||||
|
|
||||||
(var player (* TmxObject)
|
(var fih (* TmxObject)
|
||||||
(tmx-find-object-by-name (. state map handle) "FIH" "Player"))
|
(tmx-find-object-by-name (. state map handle) "FIH" "Player"))
|
||||||
(= (. state fih) player)
|
(= (. state fih) fih)
|
||||||
|
(= (. state fih x) (clamp-to-grid (. state fih x)))
|
||||||
|
(= (. state fih y) (clamp-to-grid (. state fih y)))
|
||||||
|
|
||||||
(TraceLog LOG-INFO
|
(TraceLog LOG-INFO
|
||||||
"FIH[0]: \"%s\" type \"%s\" at %.1f, %.1f (%.1f x %.1f)"
|
"FIH[0]: \"%s\" type \"%s\" at %.1f, %.1f (%.1f x %.1f)"
|
||||||
@@ -102,14 +112,14 @@
|
|||||||
(do
|
(do
|
||||||
(var speed float (* 300.0 (GetFrameTime)))
|
(var speed float (* 300.0 (GetFrameTime)))
|
||||||
|
|
||||||
(if (|| (IsKeyDown KEY-LEFT) (IsKeyDown KEY-A))
|
(if (|| (IsKeyPressed KEY-LEFT) (IsKeyPressed KEY-A))
|
||||||
(-= (. state cam target x) speed))
|
(-= (. state fih x) TILE-SIZE))
|
||||||
(if (|| (IsKeyDown KEY-RIGHT) (IsKeyDown KEY-D))
|
(if (|| (IsKeyPressed KEY-RIGHT) (IsKeyPressed KEY-D))
|
||||||
(+= (. state cam target x) speed))
|
(+= (. state fih x) TILE-SIZE))
|
||||||
(if (|| (IsKeyDown KEY-UP) (IsKeyDown KEY-W))
|
(if (|| (IsKeyPressed KEY-UP) (IsKeyPressed KEY-W))
|
||||||
(-= (. state cam target y) speed))
|
(-= (. state fih y) TILE-SIZE))
|
||||||
(if (|| (IsKeyDown KEY-DOWN) (IsKeyDown KEY-S))
|
(if (|| (IsKeyPressed KEY-DOWN) (IsKeyPressed KEY-S))
|
||||||
(+= (. state cam target y) speed))
|
(+= (. state fih y) TILE-SIZE))
|
||||||
|
|
||||||
(var map-width float (cast (tmx-pixel-width (. state map)) float))
|
(var map-width float (cast (tmx-pixel-width (. state map)) float))
|
||||||
(var map-height float (cast (tmx-pixel-height (. state map)) float))
|
(var map-height float (cast (tmx-pixel-height (. state map)) float))
|
||||||
|
|||||||
Reference in New Issue
Block a user