Make game-state global, implement hash-table for textures, free them at the end
This commit is contained in:
parent
97fd389f9e
commit
55f875cb44
32
game.lisp
32
game.lisp
@ -7,15 +7,22 @@
|
||||
|
||||
(in-package :raylib-user)
|
||||
|
||||
(defparameter *terrain-txt*
|
||||
(rl:load-texture (uiop:native-namestring (asdf:system-relative-pathname
|
||||
'cl-raylib
|
||||
"assets/Terrain/Ground/Tilemap_Flat.png"))))
|
||||
(defparameter *move-speed* 2.0)
|
||||
|
||||
(defstruct game-state
|
||||
(textures (make-hash-table))
|
||||
(player-pos (vec 100 100)))
|
||||
|
||||
(defparameter *game-state* nil)
|
||||
|
||||
(defun bind-texture (state key path)
|
||||
(setf (gethash key (game-state-textures state)) (rl:load-texture (uiop:native-namestring path))))
|
||||
|
||||
(defun game-init ()
|
||||
(let ((state (make-game-state)))
|
||||
(bind-texture state 'terrain "~/Development/tinyswords/assets/Terrain/Ground/Tilemap_Flat.png")
|
||||
state))
|
||||
|
||||
(defun game-input (state)
|
||||
(with-slots ((pos player-pos)) state
|
||||
(let ((dx 0.0) (dy 0.0))
|
||||
@ -28,23 +35,22 @@
|
||||
(defun game-update (state) '())
|
||||
|
||||
(defun game-draw (state)
|
||||
(rl:draw-rectangle-v (game-state-player-pos state)
|
||||
(vec 100 100)
|
||||
:skyblue)
|
||||
(rl:draw-texture-v *terrain-txt* (vec 500 400) (rl:make-color 1.0 1.0 1.0 1.0))
|
||||
(rl:draw-texture-v (gethash 'terrain (game-state-textures state)) (vec 50 50) :white)
|
||||
(rl:draw-fps 10 5))
|
||||
|
||||
(defun main ()
|
||||
(let* ((screen-width 900)
|
||||
(screen-height 700)
|
||||
(game-state (make-game-state)))
|
||||
(screen-height 500))
|
||||
(rl:with-window (screen-width screen-height "RTS")
|
||||
(rl:set-target-fps 60)
|
||||
(setf *game-state* (game-init))
|
||||
(loop :until (rl:window-should-close)
|
||||
:do (game-input game-state)
|
||||
(game-update game-state)
|
||||
:do (game-input *game-state*)
|
||||
(game-update *game-state*)
|
||||
(rl:with-drawing
|
||||
(rl:clear-background :raywhite)
|
||||
(game-draw game-state))))))
|
||||
(game-draw *game-state*)))
|
||||
(loop for value being the hash-values of (game-state-textures *game-state*)
|
||||
do (rl:unload-texture value)))))
|
||||
|
||||
(main)
|
||||
|
Loading…
x
Reference in New Issue
Block a user