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