Compare commits
No commits in common. "97fd389f9e6970c8bc8176e31d451818a9a2a5eb" and "d260da4c250e5234b42d254469a004a3820db5a1" have entirely different histories.
97fd389f9e
...
d260da4c25
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,4 +7,3 @@
|
|||||||
/boids
|
/boids
|
||||||
/boids_main
|
/boids_main
|
||||||
/libboids.so
|
/libboids.so
|
||||||
/game.fasl
|
|
||||||
|
@ -39,7 +39,6 @@ static GameState *init() {
|
|||||||
SetTargetFPS(TARGET_FPS);
|
SetTargetFPS(TARGET_FPS);
|
||||||
|
|
||||||
GameState *state = malloc(sizeof(struct GameApi));
|
GameState *state = malloc(sizeof(struct GameApi));
|
||||||
state->target_pos = (PointOption){ .tag = NONE };
|
|
||||||
state->num_boids = 16;
|
state->num_boids = 16;
|
||||||
state->max_speed = 5.0f;
|
state->max_speed = 5.0f;
|
||||||
state->max_force = 0.05;
|
state->max_force = 0.05;
|
||||||
@ -81,7 +80,7 @@ static void unload(GameState *state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We need this so all the raylib state is in the right place
|
// We need this so all the raylib state is in the right place
|
||||||
static bool window_should_close() {
|
static bool should_close() {
|
||||||
return WindowShouldClose();
|
return WindowShouldClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,5 +131,5 @@ const struct GameApi GAME_API = {
|
|||||||
.step = step,
|
.step = step,
|
||||||
.unload = unload,
|
.unload = unload,
|
||||||
.finalize = finalize,
|
.finalize = finalize,
|
||||||
.window_should_close = window_should_close,
|
.should_close = should_close,
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@ struct GameState;
|
|||||||
|
|
||||||
typedef struct GameApi {
|
typedef struct GameApi {
|
||||||
struct GameState *(*init)();
|
struct GameState *(*init)();
|
||||||
bool (*window_should_close)();
|
bool (*should_close)();
|
||||||
void (*finalize) (struct GameState *state);
|
void (*finalize) (struct GameState *state);
|
||||||
void (*reload) (struct GameState *state);
|
void (*reload) (struct GameState *state);
|
||||||
void (*unload) (struct GameState *state);
|
void (*unload) (struct GameState *state);
|
||||||
|
@ -17,6 +17,8 @@ struct Game {
|
|||||||
struct GameState* state;
|
struct GameState* state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MAX_EVENTS 1
|
||||||
|
|
||||||
void load_game(struct Game* game) {
|
void load_game(struct Game* game) {
|
||||||
struct stat attr;
|
struct stat attr;
|
||||||
if ((stat(GAME_LIB, &attr) == 0) && (game->gamelib_id != attr.st_ino)) {
|
if ((stat(GAME_LIB, &attr) == 0) && (game->gamelib_id != attr.st_ino)) {
|
||||||
@ -53,7 +55,7 @@ int main(void) {
|
|||||||
struct Game game = {0};
|
struct Game game = {0};
|
||||||
while (1) {
|
while (1) {
|
||||||
load_game(&game);
|
load_game(&game);
|
||||||
if (game.api.window_should_close()) {
|
if (game.api.should_close()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
game.api.step(game.state);
|
game.api.step(game.state);
|
||||||
|
50
game.lisp
50
game.lisp
@ -1,50 +0,0 @@
|
|||||||
(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)
|
|
Loading…
x
Reference in New Issue
Block a user