From c7075d6251c44c4e9782ebc5330cda96e8a33f60 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 11 Nov 2024 18:53:18 +0700 Subject: [PATCH] Draw tiled ground texture with nested for loop --- game.lisp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/game.lisp b/game.lisp index 7fc8f06..6d76b3b 100644 --- a/game.lisp +++ b/game.lisp @@ -34,8 +34,24 @@ (defun game-update (state) '()) +(defun draw-tile (tilemap size col row) + (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)) + +(defun draw-ground () + (let ((size 32) + (terrain-tex (gethash 'terrain (game-state-textures *game-state*)))) + (loop for row from 0 to 16 + do (loop for col from 0 to 32 + do (draw-tile terrain-tex size col row))))) + (defun game-draw (state) - (rl:draw-texture-v (gethash 'terrain (game-state-textures state)) (vec 50 50) :white) + (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-fps 10 5)) (defun main () @@ -48,7 +64,6 @@ :do (game-input *game-state*) (game-update *game-state*) (rl:with-drawing - (rl:clear-background :raywhite) (game-draw *game-state*))) (loop for value being the hash-values of (game-state-textures *game-state*) do (rl:unload-texture value)))))