Compare commits

..

No commits in common. "fcb067f5bda5a450916494e752532588b59e89ae" and "b8770d04e34e087680a7975d1e5a958c83cee859" have entirely different histories.

20 changed files with 36 additions and 133 deletions

View File

@ -1,5 +1,6 @@
#+begin_src shell
gcc -lecl ecl_test.c -o test-game libtest-game.a
#+end_src
@ -9,12 +10,3 @@ gcc -lecl ecl_test.c -o test-game libtest-game.a
(compile-file "game.lisp" :system-p t)
(c:build-static-library "test-game" :lisp-files '("game.o") :init-name "game")
#+end_src
#+begin_src shell
emcc -o ecl_test.html ecl_test.c -Os -Wall USE_GLFW=3 --shell-file ~/Repositories/raylib/src/minshell.html -DPLATFORM_WEB
emcc -lecl -o ecl_test.html ecl_test.c -Os -Wall --shell-file ~/Repositories/raylib/src/minshell.html -DPLATFORM_WEB
emcc -I -o why.html ecl_test.c -Os -Wall --shell-file ~/Repositories/raylib/src/minshell.html -DPLATFORM_WEB
#+end_src

View File

@ -1,29 +0,0 @@
#include "include/raylib.h"
#include "include/raymath.h"
#include <stdio.h>
#include "lib.h"
#define SCREEN_WIDTH 1300
#define SCREEN_HEIGHT 1000
#define TARGET_FPS 60
int main(void) {
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Boids");
SetTargetFPS(TARGET_FPS);
while (!WindowShouldClose()) {
float dt = GetFrameTime();
// Update
BeginDrawing();
{
ClearBackground(RAYWHITE);
}
EndDrawing();
}
CloseWindow();
}

122
game.lisp
View File

@ -1,5 +1,6 @@
(load "~/quicklisp/setup.lisp")
(eval-when (:compile-toplevel :load-toplevel :execute)
(load "~/.local/share/quicklisp/setup.lisp")
(ql:quickload :cl-raylib))
(defpackage :raylib-user
@ -8,88 +9,33 @@
(in-package :raylib-user)
(defparameter *move-speed* 5.0)
(defparameter *move-speed* 2.0)
(defclass health ()
((current-amount :initform 100.0 :accessor current-amount)
(max-amount :initform 100.0 :accessor max-amount)))
(defclass animation ()
((current-amount :initform 100.0 :accessor current-amount)
(max-amount :initform 100.0 :accessor max-amount)))
(defclass knight ()
((pos :initform (vec 270 360) :accessor pos)
(anim-state :initform 0 :accessor anim-state)
(velocity :initform (vec 0 0) :accessor velocity)
(health :initform 100.0 :accessor health)))
(defclass archer ()
((pos :initform (vec 145.0 253.0) :accessor pos)
(velocity :initform (vec 0 0) :accessor velocity)
(health :initform 100.0 :accessor health)))
(defclass goblin ()
((health :initform 100.0 :accessor health)))
(defclass tower ()
((health :initform 100.0 :accessor health)))
(defparameter knight1 (make-instance 'knight))
(defparameter archer1 (make-instance 'archer))
(defparameter goblin1 (make-instance 'goblin))
(defun deal-damage (obj damage)
(with-accessors ((h health)) obj
(setf h (- h damage))))
(mapcar (lambda (go) (deal-damage go 10)) (list knight1 archer1 goblin1))
(defclass game-state ()
((click-pos :initform nil :accessor click-pos)))
(defstruct game-state
(textures (make-hash-table))
(player-pos (vec 100 100)))
(defparameter *game-state* nil)
(defparameter *textures* (make-hash-table))
(defun bind-texture (key path)
(setf (gethash key *textures*) (rl:load-texture (uiop:native-namestring path))))
(setf (gethash key (game-state-textures *game-state*)) (rl:load-texture (uiop:native-namestring path))))
(defun game-init ()
(setf *game-state* (make-instance 'game-state))
;; (add-component (knight *game-state*) (make-instance 'transform))
(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 ()
(when (rl:is-mouse-button-pressed 0)
(print (rl:get-mouse-position))
(setf (click-pos *game-state*) (rl:get-mouse-position))))
;; (with-slots ((pos archer-pos) (kpos knight-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))
;; (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-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 ()
(with-accessors ((click-pos click-pos)) *game-state*
(when click-pos
(setf (anim-state knight1) 1)
(with-accessors ((kpos pos)) knight1
(let* ((dist (v- click-pos kpos))
(mag (vsqrlength dist)))
(if (<= mag 10.0)
(progn
(setf (anim-state knight1) 0)
(setf kpos click-pos)
;; (setf (velocity knight1) (vec 0 0))
(setf click-pos nil))
(let ((vel (v* 3.0 (vunit* dist))))
(setf (velocity knight1) vel)
(setf kpos (v+ kpos vel)))))))))
(defun game-update (state) '())
(defun get-tile-wrapped (n wrap-count) (if (> n 0) (1+ (mod (1- n) (- wrap-count 2))) 0))
@ -105,29 +51,21 @@
(defun draw-ground ()
(let ((size 32)
(terrain-tex (gethash 'terrain *textures*)))
(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 animate-sprite (tex-key row pos vel)
(let ((time-interval (coerce (mod (truncate (/ (rl:get-time) 0.1)) 6) 'single-float))
(side (if (< (vx vel) 0) -1 1)))
(rl:draw-texture-pro (gethash tex-key *textures*)
(rl:make-rectangle :x (* time-interval 192.0) :y (* row 192)
:width (* side 192.0) :height 192.0)
(rl:make-rectangle :x (vx pos) :y (vy pos)
:width 192.0 :height 192.0)
(vec 95.0 128.0)
0.0
:white)))
(defun animate-sprite ())
(defun game-draw ()
(defun game-draw (state)
(rl:clear-background (rl:make-rgba 71 171 169 1))
(draw-ground)
(rl:draw-texture-v (gethash 'tower *textures*) (vec 80 150) :white)
(animate-sprite 'knight (anim-state knight1) (pos knight1) (velocity knight1))
(animate-sprite 'archer 0 (pos archer1) (velocity archer1))
(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 game ()
@ -137,9 +75,11 @@
(rl:set-target-fps 60)
(game-init)
(loop :until (rl:window-should-close)
:do (game-input)
(game-update)
:do (game-input *game-state*)
(game-update *game-state*)
(rl:with-drawing
(game-draw)))
(loop for value being the hash-values of *textures*
(game-draw *game-state*)))
(loop for value being the hash-values of (game-state-textures *game-state*)
do (rl:unload-texture value)))))
(game)

View File

@ -75,11 +75,11 @@ Assets Init() {
Assets assets = {0};
assets.textures = malloc(sizeof(Texture2D) * TEXTURES_BUF_SIZE);
assets.textures[TEX_GROUND] = LoadTexture(../"assets/Terrain/Ground/Tilemap_Flat.png");
assets.textures[TEX_GROUND] = LoadTexture("assets/Terrain/Ground/Tilemap_Flat.png");
assets.textures[TEX_KNIGHT] =
LoadTexture("../assets/Factions/Knights/Troops/Warrior/Blue/Warrior_Blue.png");
assets.textures[TEX_MOUSE_CURSOR] = LoadTexture("../assets/UI/Pointers/01.png");
assets.textures[TEX_TARGET_RETICLE] = LoadTexture("../assets/UI/Pointers/02.png");
LoadTexture("assets/Factions/Knights/Troops/Warrior/Blue/Warrior_Blue.png");
assets.textures[TEX_MOUSE_CURSOR] = LoadTexture("assets/UI/Pointers/01.png");
assets.textures[TEX_TARGET_RETICLE] = LoadTexture("assets/UI/Pointers/02.png");
return assets;
}