Lisp version

This commit is contained in:
Joseph Ferano 2024-11-10 11:13:40 +07:00
parent 5de48b7507
commit 97fd389f9e
2 changed files with 51 additions and 0 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@
/boids
/boids_main
/libboids.so
/game.fasl

50
game.lisp Normal file
View File

@ -0,0 +1,50 @@
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload :cl-raylib))
(defpackage :raylib-user
(:use :cl :3d-vectors)
(:local-nicknames (:rl :raylib)))
(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
(player-pos (vec 100 100)))
(defun game-input (state)
(with-slots ((pos player-pos)) 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))
(when (rl:is-key-down :key-up) (decf dy 1))
(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-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-fps 10 5))
(defun main ()
(let* ((screen-width 900)
(screen-height 700)
(game-state (make-game-state)))
(rl:with-window (screen-width screen-height "RTS")
(rl:set-target-fps 60)
(loop :until (rl:window-should-close)
:do (game-input game-state)
(game-update game-state)
(rl:with-drawing
(rl:clear-background :raywhite)
(game-draw game-state))))))
(main)