Compare commits
3
Commits
b8770d04e3
...
fcb067f5bd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcb067f5bd | ||
|
|
0d97dd896f | ||
|
|
3b0ee06adc |
No files matched your search
+9
-1
@@ -1,6 +1,5 @@
|
||||
|
||||
#+begin_src shell
|
||||
|
||||
gcc -lecl ecl_test.c -o test-game libtest-game.a
|
||||
#+end_src
|
||||
|
||||
@@ -10,3 +9,12 @@ 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
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,29 @@
|
||||
#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();
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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;
|
||||
}
|
||||
|
||||
File renamed without changes.
File renamed without changes.
@@ -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,33 +8,88 @@
|
||||
|
||||
(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)))
|
||||
(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)))
|
||||
|
||||
(defparameter *game-state* nil)
|
||||
(defparameter *textures* (make-hash-table))
|
||||
|
||||
(defun bind-texture (key path)
|
||||
(setf (gethash key (game-state-textures *game-state*)) (rl:load-texture (uiop:native-namestring path))))
|
||||
(setf (gethash key *textures*) (rl:load-texture (uiop:native-namestring path))))
|
||||
|
||||
(defun game-init ()
|
||||
(setf *game-state* (make-game-state))
|
||||
(setf *game-state* (make-instance 'game-state))
|
||||
;; (add-component (knight *game-state*) (make-instance 'transform))
|
||||
(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
|
||||
(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 ()
|
||||
(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-update (state) '())
|
||||
(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 get-tile-wrapped (n wrap-count) (if (> n 0) (1+ (mod (1- n) (- wrap-count 2))) 0))
|
||||
|
||||
@@ -51,21 +105,29 @@
|
||||
|
||||
(defun draw-ground ()
|
||||
(let ((size 32)
|
||||
(terrain-tex (gethash 'terrain (game-state-textures *game-state*))))
|
||||
(terrain-tex (gethash 'terrain *textures*)))
|
||||
(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 ())
|
||||
(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 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 *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-fps 10 5))
|
||||
|
||||
(defun game ()
|
||||
@@ -75,11 +137,9 @@
|
||||
(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*)))
|
||||
(loop for value being the hash-values of (game-state-textures *game-state*)
|
||||
(game-draw)))
|
||||
(loop for value being the hash-values of *textures*
|
||||
do (rl:unload-texture value)))))
|
||||
|
||||
(game)
|
||||
Reference in new issue
Block a user