From 32c5a0c13b19c2d8891cfad467e0a3cc740b7d70 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Wed, 17 Nov 2021 14:51:05 +0100 Subject: [PATCH] the mess builds with raylib --- .gitignore | 1 + CMakeLists.txt | 21 ++++----------------- Makefile | 12 +++++++++++- README | 3 +++ lvl/fxconv-metadata.txt | 2 +- raygint | 2 +- src/anim.c | 26 +++++++++++++++++++++++++- src/level.c | 39 ++++++++++++++++++++++++++++++++++----- src/main.c | 23 ++++++++++++++++++++++- src/particles.c | 1 + src/player.c | 11 +++++++++-- src/results.c | 9 +++++++++ src/shatter.c | 7 +++++++ 13 files changed, 128 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index f23a08c..8ea1418 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +out/ build/ build-cg/ build-fx/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 270a847..64d05ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ project(CRYSTAL C) set(CMAKE_C_STANDARD 99) -include_directories(inc raygint/include) +include_directories(inc out raygint/include) set(SOURCES src/main.c @@ -21,20 +21,7 @@ set(SOURCES src/stars.c src/results.c raygint/src/display.c -) - -set(LEVELS - lvl/0.kble - lvl/1.kble - lvl/2.kble - lvl/3.kble - lvl/4.kble - lvl/5.kble - lvl/6.kble - lvl/7.kble - lvl/8.kble - lvl/9.kble - lvl/end.kble + raygint/src/keyboard.c ) set(ASSETS @@ -50,7 +37,7 @@ set(FLAGS -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Werror-implicit-function-declaration - -O3 + -O3 -Wno-incompatible-pointer-types ) if ("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) @@ -72,6 +59,6 @@ if ("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) ) else() add_executable(target ${SOURCES}) - target_compile_options(target PRIVATE ${FLAGS} -DRAYLIB) + target_compile_options(target PRIVATE ${FLAGS} -DRAYLIB -g) target_link_libraries(target raylib) endif() diff --git a/Makefile b/Makefile index 6999851..251da88 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,20 @@ -all: format +all: format out/levels_bin.h fxsdk build-cg +ray: clean format out/levels_bin.h + mkdir -p build + cmake -B build . + make -C build + +out/levels_bin.h: + mkdir -p out + cembed -o out/levels_bin.h lvl/*.kble + format: clang-format -style=file -i src/**.c inc/**.h clean: + rm -rf out/ rm -rf build-cg/ rm -f *.g3a diff --git a/README b/README index 85f903a..4b31851 100644 --- a/README +++ b/README @@ -4,6 +4,9 @@ Platforming game for the Casio fxCG50 BUILD ===== +Require cembed: +https://github.com/rxi/cembed + Run 'make' LICENSE diff --git a/lvl/fxconv-metadata.txt b/lvl/fxconv-metadata.txt index 7b61593..ccc9f33 100644 --- a/lvl/fxconv-metadata.txt +++ b/lvl/fxconv-metadata.txt @@ -1,3 +1,3 @@ *.kble: type: binary - name_regex: (.*)\.kble lvl_\1 + name_regex: (.*)\.kble lvl_\1_kble diff --git a/raygint b/raygint index 6511864..04cfbea 160000 --- a/raygint +++ b/raygint @@ -1 +1 @@ -Subproject commit 65118645095a7567087788d41ea7f22e4311e441 +Subproject commit 04cfbeac77bbe097d94566c4c3f345336318aca5 diff --git a/src/anim.c b/src/anim.c index 9e5eb25..8506289 100644 --- a/src/anim.c +++ b/src/anim.c @@ -2,6 +2,7 @@ #include "camera.h" #include "raygint/display.h" #include "vec.h" +#include struct Anim anim_new(bopti_image_t *texture, int x, int y, int frame_width, @@ -10,10 +11,16 @@ anim_new(bopti_image_t *texture, int x, int y, int frame_width, struct Anim anim; anim.texture = texture; anim.pos = VEC(x, y); +#ifdef GINT anim.frame_dim = VEC(frame_width, texture->height); + anim.life_ini = frame_duration * texture->width * frame_width; +#endif +#ifdef RAYLIB + anim.frame_dim = VEC(frame_width, frame_width); + anim.life_ini = frame_duration * anim.frame_dim.x * 8; +#endif anim.frame_duration = frame_duration; anim.frame = 0; - anim.life_ini = frame_duration * texture->width / frame_width; anim.life = anim.life_ini; anim.loop = loop; anim.callback = NULL; @@ -37,6 +44,7 @@ anim_update(struct Anim *a) } } +#ifdef GINT void anim_draw(struct Anim *a) { @@ -50,3 +58,19 @@ anim_draw(struct Anim *a) a->frame_dim.y, DIMAGE_NONE); } } +#endif + +#ifdef RAYLIB +void +anim_draw(struct Anim *a) +{ + if (a->life) { + const struct Vec off = camera_offset(); + const int x1 = a->pos.x + off.x; + const int y1 = a->pos.y + off.y; + const int x2 = x1 + a->frame_dim.x - 1; + const int y2 = y1 + a->frame_dim.y - 1; + drect(x1, y1, x2, y2, C_BLUE); + } +} +#endif diff --git a/src/level.c b/src/level.c index 2c9c976..4c92098 100644 --- a/src/level.c +++ b/src/level.c @@ -1,6 +1,7 @@ #include "level.h" #include "camera.h" #include "conf.h" +#include "levels_bin.h" #include "particles.h" #include "player.h" #include "raygint/display.h" @@ -9,11 +10,10 @@ #include static struct Level self; -extern struct LevelBin lvl_0, lvl_1, lvl_2, lvl_3, lvl_4, lvl_5, lvl_6, lvl_7, - lvl_8, lvl_9, lvl_end; -static const struct LevelBin *levels[] = {&lvl_0, &lvl_1, &lvl_2, &lvl_3, - &lvl_4, &lvl_5, &lvl_6, &lvl_7, - &lvl_8, &lvl_9, &lvl_end, NULL}; +static const struct LevelBin *levels[] = { + &lvl_0_kble, &lvl_1_kble, &lvl_2_kble, &lvl_3_kble, + &lvl_4_kble, &lvl_5_kble, &lvl_6_kble, &lvl_7_kble, + &lvl_8_kble, &lvl_9_kble, &lvl_end_kble}; void level_load(int id) @@ -55,6 +55,7 @@ level_free(void) free(self.data); } +#ifdef GINT void level_draw(void) { @@ -83,6 +84,34 @@ level_draw(void) } } } +#endif + +#ifdef RAYLIB +void +level_draw(void) +{ + const struct Vec off = camera_offset(); + int i; + int x = 0; + int y = 0; + + for (i = 0; i < self.size; i++) { + const int tile = self.data[i]; + if (tile && tile != TILE_THUNDER) { + const int sx1 = x * TILE_SIZE + off.x; + const int sy1 = y * TILE_SIZE + off.y; + const int sx2 = sx1 + TILE_SIZE - 1; + const int sy2 = sy1 + TILE_SIZE - 1; + drect(sx1, sy1, sx2, sy2, C_WHITE); + } + + if (++x >= self.width) { + x = 0; + y++; + } + } +} +#endif struct Vec level_find(enum Tile seek) diff --git a/src/main.c b/src/main.c index 8831ff2..5d25c7e 100644 --- a/src/main.c +++ b/src/main.c @@ -8,14 +8,18 @@ #include "results.h" #include "stars.h" #include "vec.h" +#ifdef GINT #include #include #include +#endif #include static void update(void); static void draw(void); +#ifdef GINT static int callback(volatile int *); +#endif int time = 0; int deaths = 0; @@ -30,16 +34,23 @@ main(void) extern bopti_image_t bimg_title; extern font_t font_georgia; + rDisplayInit(); srand(1337); +#ifdef GINT timer = timer_configure(TIMER_ANY, 1000000 / TARGET_FPS, GINT_CALL(callback, &has_ticked)); timer_start(timer); + dfont(&font_georgia); +#endif +#ifdef RAYLIB + SetTargetFPS(60); +#endif input_init(); stars_init(); level_load(0); camera_init(player_pos()); - dfont(&font_georgia); +#ifdef GINT dimage(0, 0, &bimg_title); dupdate(); getkey(); @@ -47,11 +58,13 @@ main(void) while (!has_ticked) ; has_ticked = 0; +#endif while (!input_down(K_EXIT)) { int i; draw(); for (i = 0; i < frameskip; i++) { +#ifdef GINT if (has_ticked > frameskip) { frameskip = has_ticked; } @@ -61,11 +74,15 @@ main(void) time += has_ticked; has_ticked = 0; } +#endif update(); } } + rDisplayDeinit(); +#ifdef GINT timer_stop(timer); +#endif level_free(); return 1; } @@ -83,6 +100,7 @@ update(void) static void draw(void) { + rDrawBegin(); dclear(C_BLACK); stars_draw(); level_draw(); @@ -91,11 +109,14 @@ draw(void) if (end) results_draw(); dupdate(); + rDrawEnd(); } +#ifdef GINT static int callback(volatile int *arg) { *arg += 1; return 0; } +#endif diff --git a/src/particles.c b/src/particles.c index 7a0212d..1fd6ff9 100644 --- a/src/particles.c +++ b/src/particles.c @@ -1,5 +1,6 @@ #include "particles.h" #include "anim.h" +#include static struct Anim particles[MAX_PARTICLES]; diff --git a/src/player.c b/src/player.c index 7016b39..95251bf 100644 --- a/src/player.c +++ b/src/player.c @@ -79,7 +79,7 @@ player_update(void) walljump(); /* unlock direction */ - if (self.lock_direction && abs(self.spd.x) < MAX_WALK_SPEED / 2) + if (self.lock_direction && absf(self.spd.x) < MAX_WALK_SPEED / 2) self.lock_direction = 0; /* death */ @@ -152,11 +152,18 @@ death(void) void player_draw(void) { - extern bopti_image_t bimg_player; const struct Vec off = camera_offset(); const int x = self.pos.x + off.x; const int y = self.pos.y + off.y; +#ifdef GINT + extern bopti_image_t bimg_player; dimage(x, y, &bimg_player); +#endif +#ifdef RAYLIB + const int x2 = x + PLAYER_WIDTH - 1; + const int y2 = y + PLAYER_HEIGHT - 1; + drect(x, y, x2, y2, C_RED); +#endif } struct Vec diff --git a/src/results.c b/src/results.c index a288f8a..ada40b4 100644 --- a/src/results.c +++ b/src/results.c @@ -2,6 +2,7 @@ #include "conf.h" #include "raygint/display.h" +#ifdef GINT void results_draw(void) { @@ -24,3 +25,11 @@ results_draw(void) dprint_opt(DWIDTH / 2, 88, C_WHITE, C_BLACK, DTEXT_CENTER, DTEXT_MIDDLE, "%d death%s", disp_deaths, (disp_deaths > 1) ? "s" : ""); } +#endif + +#ifdef RAYLIB +void +results_draw(void) +{ +} +#endif diff --git a/src/shatter.c b/src/shatter.c index 864bb9c..9ce633c 100644 --- a/src/shatter.c +++ b/src/shatter.c @@ -6,16 +6,23 @@ #include "raygint/display.h" #include "tile.h" #include "vec.h" +#include static void callback(struct Anim *); void shatter(int x, int y) { +#ifdef GINT extern bopti_image_t bimg_shatter; +#endif +#ifdef RAYLIB + bopti_image_t bimg_shatter = 0; +#endif const int ax = (int)(x / TILE_SIZE) * TILE_SIZE; const int ay = (int)(y / TILE_SIZE) * TILE_SIZE; struct Anim p = anim_new(&bimg_shatter, ax, ay, TILE_SIZE, 2, false); + p.callback = callback; if (level_get_px(ax, ay) == TILE_SOLID && !particles_here(ax, ay)) particles_add(p);