From 0d97dd896f0fa8ae6da2f4a6276d7ad005a8b22e Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 15 Nov 2024 21:46:35 +0700 Subject: [PATCH] Render the archer, animation function --- game.lisp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/game.lisp b/game.lisp index d8bd840..dc26d1e 100644 --- a/game.lisp +++ b/game.lisp @@ -1,6 +1,5 @@ -(load "~/quicklisp/setup.lisp") - (eval-when (:compile-toplevel :load-toplevel :execute) + (load "~/.local/share/quicklisp/setup.lisp") (ql:quickload :cl-raylib)) (defpackage :raylib-user @@ -9,11 +8,12 @@ (in-package :raylib-user) -(defparameter *move-speed* 2.0) +(defparameter *move-speed* 5.0) (defstruct game-state (textures (make-hash-table)) - (player-pos (vec 100 100))) + (knight-pos (vec 150.0 250.0)) + (archer-pos (vec 50.0 122.0))) (defparameter *game-state* nil) @@ -24,10 +24,11 @@ (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 'archer "~/Development/tinyswords/assets/Factions/Knights/Troops/Archer/Blue/Archer_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 +(defun game-input () + (with-slots ((pos archer-pos)) *game-state* (let ((dx 0.0) (dy 0.0)) (when (rl:is-key-down :key-right) (incf dx 1)) (when (rl:is-key-down :key-left) (decf dx 1)) @@ -35,7 +36,7 @@ (when (rl:is-key-down :key-down) (incf dy 1)) (setf pos (v+ pos (v* (vunit* (vec dx dy)) *move-speed*)))))) -(defun game-update (state) '()) +(defun game-update () '()) (defun get-tile-wrapped (n wrap-count) (if (> n 0) (1+ (mod (1- n) (- wrap-count 2))) 0)) @@ -56,16 +57,19 @@ do (loop for col from 0 to 32 do (draw-tile terrain-tex size col row))))) -(defun animate-sprite ()) +(defun animate-sprite (tex-key row pos) + (let ((time-interval (coerce (mod (truncate (/ (rl:get-time) 0.1)) 6) 'single-float))) + (rl:draw-texture-rec (gethash tex-key (game-state-textures *game-state*)) + (rl:make-rectangle :x (* time-interval 192.0) :y (* row 192) + :width 192.0 :height 192.0) + pos :white))) -(defun game-draw (state) +(defun game-draw () (rl:clear-background (rl:make-rgba 71 171 169 1)) (draw-ground) - (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-texture-v (gethash 'tower (game-state-textures *game-state*)) (vec 80 150) :white) + (animate-sprite 'knight 0 (game-state-knight-pos *game-state*)) + (animate-sprite 'archer 0 (game-state-archer-pos *game-state*)) (rl:draw-fps 10 5)) (defun game () @@ -75,10 +79,10 @@ (rl:set-target-fps 60) (game-init) (loop :until (rl:window-should-close) - :do (game-input *game-state*) - (game-update *game-state*) + :do (game-input) + (game-update) (rl:with-drawing - (game-draw *game-state*))) + (game-draw))) (loop for value being the hash-values of (game-state-textures *game-state*) do (rl:unload-texture value)))))