Draw the terrain properly, draw a tower and a knight

This commit is contained in:
Joseph Ferano 2024-11-12 08:42:31 +07:00
parent c7075d6251
commit 90e927ced2

View File

@ -15,13 +15,14 @@
(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 bind-texture (key path)
(setf (gethash key (game-state-textures *game-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))
(setf *game-state* (make-game-state))
(bind-texture 'terrain "~/Development/tinyswords/assets/Terrain/Ground/Tilemap_Flat.png")
(bind-texture 'knight "~/Development/tinyswords/assets/Factions/Knights/Troops/Warrior/Blue/Warrior_Blue.png")
(bind-texture 'tower "~/Development/tinyswords/assets/Factions/Knights/Buildings/Tower/Tower_Blue.png"))
(defun game-input (state)
(with-slots ((pos player-pos)) state
@ -34,12 +35,17 @@
(defun game-update (state) '())
(defun get-tile-wrapped (n wrap-count) (if (> n 0) (1+ (mod (1- n) (- wrap-count 2))) 0))
(defun draw-tile (tilemap size col row)
(let* ((tile-count 6))
(rl:draw-texture-rec
tilemap
(rl:make-rectangle :x (* size (mod col 5)) :y (* size (mod row 5)) :width size :height size)
(vec (* col size) (* row size))
:white))
(rl:make-rectangle :x (* size (get-tile-wrapped col tile-count))
:y (* size (get-tile-wrapped row tile-count))
:width size :height size)
(v+ (vec 15 150) (vec (* col size) (* row size)))
:white)))
(defun draw-ground ()
(let ((size 32)
@ -48,10 +54,16 @@
do (loop for col from 0 to 32
do (draw-tile terrain-tex size col row)))))
(defun animate-sprite ())
(defun game-draw (state)
(rl:clear-background (rl:make-rgba 71 171 169 1))
(draw-ground)
;; (rl:draw-texture-v (gethash 'terrain (game-state-textures state)) (vec 50 50) :white)
(rl:draw-texture-v (gethash 'tower (game-state-textures state)) (vec 80 150) :white)
(rl:draw-texture-rec (gethash 'knight (game-state-textures state))
(rl:make-rectangle :x 0.0 :y 0.0 :width 192.0 :height 192.0)
(vec 0 0)
:white)
(rl:draw-fps 10 5))
(defun main ()
@ -59,7 +71,7 @@
(screen-height 500))
(rl:with-window (screen-width screen-height "RTS")
(rl:set-target-fps 60)
(setf *game-state* (game-init))
(game-init)
(loop :until (rl:window-should-close)
:do (game-input *game-state*)
(game-update *game-state*)