From 1dd453bfb3f0ea1b83e50130531e1b21cbe59b0f Mon Sep 17 00:00:00 2001 From: attilavs2 Date: Sat, 9 Mar 2024 21:21:17 +0100 Subject: [PATCH] Fork en Copy 3D Engine --- CMakeLists.txt | 28 +++--- src/main.c | 190 ++++++++++++++++-------------------- src/{map_test.c => map.c} | 4 +- src/map.h | 10 ++ src/map_test.h | 10 -- src/moteur.c | 196 ++++++++++++++++++-------------------- src/moteur.h | 6 +- 7 files changed, 211 insertions(+), 233 deletions(-) rename src/{map_test.c => map.c} (99%) create mode 100644 src/map.h delete mode 100644 src/map_test.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 46d80ff..abb7d6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,33 +2,39 @@ # toolchain file and module path of the fxSDK cmake_minimum_required(VERSION 3.15) -project(Maze3D) +project(Copy3DEngine) include(GenerateG3A) include(Fxconv) find_package(Gint 2.9 REQUIRED) find_package(LibProf 2.1 REQUIRED) +# le nom de votre jeu +set(NAMEOFGAME "Test3D") +# Nom de l'auteur -> votre nom/pseudo +set(AUTHOR "Fcalva") + set(SOURCES src/main.c src/moteur.c - src/map_test.c + src/map.c ) -# Shared assets, fx-9860G-only assets and fx-CG-50-only assets + set(ASSETS assets-cg/textures/briques0.png assets-cg/textures/buisson1.png ) -fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA) +fxconv_declare_assets(${ASSETS} WITH_METADATA) -add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}}) -target_compile_options(myaddin PRIVATE -Wall -Wextra -Ofast -fira-region=all -flto -fno-math-errno -funsafe-math-optimizations -fassociative-math -freciprocal-math) -target_link_libraries(myaddin Gint::Gint ) -target_link_libraries(myaddin LibProf::LibProf) -target_link_options(myaddin PRIVATE -Wl,--print-memory-usage,-flto) +add_executable(Copy3DEngine ${SOURCES} ${ASSETS}) +target_compile_options(Copy3DEngine PRIVATE -Wall -Wextra -Ofast -fira-region=all -flto -fno-math-errno -funsafe-math-optimizations -fassociative-math -freciprocal-math) +target_compile_definitions(Copy3DEngine PRIVATE NAMEOFGAME="${NAMEOFGAME}" AUTHOR="${AUTHOR}") +target_link_libraries(Copy3DEngine Gint::Gint) +target_link_libraries(Copy3DEngine LibProf::LibProf) +target_link_options(Copy3DEngine PRIVATE -Wl,--print-memory-usage,-flto) if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) - generate_g3a(TARGET myaddin OUTPUT "Maze3D.g3a" - NAME "Maze3D" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) + generate_g3a(TARGET Copy3DEngine OUTPUT "${NAMEOFGAME}.g3a" + NAME "${NAMEOFGAME}" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) endif() diff --git a/src/main.c b/src/main.c index b021ffe..e9322cb 100644 --- a/src/main.c +++ b/src/main.c @@ -6,29 +6,18 @@ #include #include -//#define USB - -#ifdef USB -#include -#include -#endif - #include "fixed.h" #include "moteur.h" -#include "map_test.h" +#include "map.h" -//====== Maze3D V1.0.4 ===== -// Git du moteur : https://github.com/attilavs2/Raycaster_G90 -// Git du jeu : https://gitea.planet-casio.com/Fcalva/Maze3D +//====== Copy3DEngine ===== +// Git du moteur : TODO +// Git du jeu : [Rajoutez le vôtre ici] // -// Page du jeu : https://www.planet-casio.com/Fr/programmes/programme4355-1-maze3d-fcalva-jeux-reflexion.html +// Page du jeu : [La vôtre ici] // -// Tout le code de cette version est en GPL3 -// Game design : Fcalva (aka. fklv, Fcalva#6860, attilavs2) -// Programmation : Fcalva -// "Art" : Fcalva -// +// Voir README.md pour license précise, par Fcalva et est sous GPLv3 // // @@ -36,25 +25,21 @@ #error Ce code est pour FXCG50/G90+E uniquement, enlevez ce message a vos riques et périls #endif - -#ifdef USB -void USB_capture() { - if (usb_is_open()) usb_fxlink_screenshot(false); -} -#endif - //#define debug //pour afficher les infos de debug +image_t *tex_index[TINDEX_S]; + extern char map_test[map_w][map_h]; +//Vos images ici + extern image_t briques0; extern image_t buisson0; char exit_game = 0; char disp_frame_time = 0; -char first_frame = 1; +char first_frame = 0; int frame_time_timer = 1; -int capture_timer = 1; fixed_t posX; fixed_t posY; @@ -63,117 +48,104 @@ fixed_t dirY; fixed_t planeX; fixed_t planeY; -int frame_time = 0; +int frame_time = 1; void keys_get(){ - move(); - pollevent(); - if (keydown(KEY_F1) && frame_time_timer <= 0) { - if (disp_frame_time == 0) { - disp_frame_time = 1; - frame_time_timer = 10; - } - else { - disp_frame_time = 0; - frame_time_timer = 10; - } - } - frame_time_timer--; - if (keydown(KEY_F6)) exit_game = 1; + pollevent(); - #ifdef debug - if (keydown(KEY_TAN)) end_screen(); - #endif + move(); - #ifdef USB - if (keydown(KEY_0) && keydown(KEY_EXE) && capture_timer <= 0) { - USB_capture(); - capture_timer = 10; - } - capture_timer--; - #endif + if (keydown(KEY_F1) && frame_time_timer <= 0) { + if (disp_frame_time == 0) { + disp_frame_time = 1; + frame_time_timer = 10; + } + else { + disp_frame_time = 0; + frame_time_timer = 10; + } + } + frame_time_timer--; + if (keydown(KEY_EXIT)) exit_game = 1; + + #ifdef debug + if (keydown(KEY_TAN)) end_screen(); + #endif } void main_menu(){ - dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Maze 3D", -1); - dtext_opt(198, 120, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "De Fcalva", -1); - dtext_opt(198, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1); + dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, NAMEOFGAME, -1); + dtext_opt(198, 120, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "De Fcalva" /*AUTHOR*/, -1); + dtext_opt(198, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1); - dupdate(); - getkey(); + dupdate(); + getkey(); } int main(){ - dclear(C_WHITE); + dclear(C_WHITE); - //trucs de chargement + //trucs de chargement - load_map(); + load_map(); - image_t *frame_buffer = image_create_vram(); + image_t *frame_buffer = image_create_vram(); - image_t sky_tex = *image_alloc(64, 64, IMAGE_RGB565); - image_t WXOR_tex = *image_alloc(64, 64, IMAGE_RGB565); - image_t D_tex = *image_alloc(64, 64, IMAGE_RGB565); + extern image_t *tex_index[TINDEX_S]; - int i, j; - for (i = 0; i<= 64; i++){ - for (j = 0; j<= 64; j++){ - int c = (int)floor((float)(i ^ j) * 0.5); - unsigned short color = (c << 8) + (c << 4) + c; - image_set_pixel(&WXOR_tex, i, j, color); - } - } - image_fill(&D_tex, 0x4228); - image_fill(&sky_tex, 0x9dbd); + tex_index[1] = &buisson0; + tex_index[2] = &briques0; - prof_init(); + //Vos textures générées procéduralement - #ifdef USB - usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL}; - usb_open(interfaces, GINT_CALL_NULL); - #endif + tex_index[0] = image_alloc(64, 64, IMAGE_RGB565); + tex_index[3] = image_alloc(64, 64, IMAGE_RGB565); - while (exit_game == 0) { - prof_t frame = prof_make(); - prof_enter(frame); + image_fill(tex_index[0], 0x4228); + image_fill(tex_index[3], 0x9dbd); - drect(0, 0, 395, 112, 0x9dbd); - drect(0,112, 395, 243, 0xc4c9); + prof_init(); - draw_walls(&buisson0, &briques0, &sky_tex, &WXOR_tex, &D_tex, frame_buffer); + while (!exit_game) { + prof_t frame = prof_make(); + prof_enter(frame); - if(first_frame == 1) main_menu(); + drect(0, 0, 395, 112, 0x9dbd); + drect(0,112, 395, 243, 0xc4c9); - keys_get(); + draw_walls(frame_buffer); - logic(); + if(first_frame == 1){ + main_menu(); + first_frame = 0; + } - if (disp_frame_time == 1) dprint( 1, 10, C_BLACK, "Frame time : %d ms", frame_time); + keys_get(); - #ifdef debug - dprint( 1, 20, C_BLACK, "planeX : %d", planeX); - dprint( 1, 30, C_BLACK, "planeY : %d", planeY); - dprint( 1, 40, C_BLACK, "dirX : %d", dirX); - dprint( 1, 50, C_BLACK, "dirY : %d", dirY); - dprint( 1, 60, C_BLACK, "posX : %d", posX); - dprint( 1, 70, C_BLACK, "posY : %d", posY); - #endif + logic(); - dupdate(); - prof_leave(frame); - frame_time = (int)prof_time(frame)/1000; - first_frame = 0; - } + if (disp_frame_time == 1) dprint( 1, 10, C_BLACK, "Frame time : %d ms", frame_time); - prof_quit(); - #ifdef USB - usb_close(); - #endif + #ifdef debug + dprint( 1, 20, C_BLACK, "planeX : %d", planeX); + dprint( 1, 30, C_BLACK, "planeY : %d", planeY); + dprint( 1, 40, C_BLACK, "dirX : %d", dirX); + dprint( 1, 50, C_BLACK, "dirY : %d", dirY); + dprint( 1, 60, C_BLACK, "posX : %d", posX); + dprint( 1, 70, C_BLACK, "posY : %d", posY); + #endif - free(&sky_tex); - free(&WXOR_tex); - free(&D_tex); + dupdate(); + prof_leave(frame); + frame_time = (int)prof_time(frame)/1000; + } - return 1; + prof_quit(); + + //Libérez vos textures générées procéduralement + + image_free(tex_index[0]); + image_free(tex_index[3]); + + return 1; } diff --git a/src/map_test.c b/src/map.c similarity index 99% rename from src/map_test.c rename to src/map.c index 54c6266..6ac4ed8 100644 --- a/src/map_test.c +++ b/src/map.c @@ -1,4 +1,6 @@ -#include "map_test.h" +// Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3 + +#include "map.h" #include "moteur.h" char map_test[map_w][map_h] = { diff --git a/src/map.h b/src/map.h new file mode 100644 index 0000000..1f35d44 --- /dev/null +++ b/src/map.h @@ -0,0 +1,10 @@ +// Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3 + +#include "fixed.h" +#ifndef map_test_M +#define map_test_M + +#define map_w 64 +#define map_h 128 + +#endif /* map_test.h */ diff --git a/src/map_test.h b/src/map_test.h deleted file mode 100644 index 4dd08f5..0000000 --- a/src/map_test.h +++ /dev/null @@ -1,10 +0,0 @@ -#include "fixed.h" -#ifndef map_test_M -#define map_test_M - -#define map_w 64 -#define map_h 128 -//#define startpos_x (fixed_t) 1370352//exprimé en cases<<16 -//#define startpos_y (fixed_t) 1817445 - -#endif /* map_test.h */ \ No newline at end of file diff --git a/src/moteur.c b/src/moteur.c index ed10bbe..04d51ed 100644 --- a/src/moteur.c +++ b/src/moteur.c @@ -1,3 +1,5 @@ +// Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3 + #include #include #include @@ -10,7 +12,7 @@ #include "fixed.h" #include "moteur.h" -#include "map_test.h" +#include "map.h" // moteur.c : // ici se trouvent tout ce qui concerne les graphismes, mouvement et collisions @@ -39,13 +41,11 @@ void move() { int xtemp2; int ytemp2; - pollevent(); - - if (keydown(KEY_UP)) { - xtemp1 = f2int(posX + fmul(dirX, moveSpeed)); + if (keydown(KEY_UP)) { + xtemp1 = f2int(posX + fmul(dirX, moveSpeed)); ytemp1 = f2int(posY); - xtemp2 = f2int(posX); - ytemp2 = f2int(posY + fmul(dirY, moveSpeed)); + xtemp2 = f2int(posX); + ytemp2 = f2int(posY + fmul(dirY, moveSpeed)); if(map_test[xtemp1][ytemp1] == 0) posX += fmul(dirX, moveSpeed); if(map_test[xtemp2][ytemp2] == 0) posY += fmul(dirY, moveSpeed); @@ -53,9 +53,9 @@ void move() { //move backwards if no wall behind you if (keydown(KEY_DOWN)) { xtemp1 = f2int(posX - fmul(dirX, moveSpeed)); - ytemp1 = f2int(posY); - xtemp2 = f2int(posX); - ytemp2 = f2int(posY - fmul(dirY, moveSpeed)); + ytemp1 = f2int(posY); + xtemp2 = f2int(posX); + ytemp2 = f2int(posY - fmul(dirY, moveSpeed)); if(map_test[xtemp1][ytemp1] == 0) posX -= fmul(dirX, moveSpeed); if(map_test[xtemp2][ytemp2] == 0) posY -= fmul(dirY, moveSpeed); @@ -63,11 +63,11 @@ void move() { //rotate to the rightdouble sin_rotspeed; if (keydown(KEY_RIGHT)) { //both camera direction and camera plane must be rotated - oldDirX = dirX; + oldDirX = dirX; dirX = (fmul(dirX, c_rotSpeed)+1) - (fmul(dirY, -s_rotSpeed)+1); - dirY = (fmul(oldDirX, -s_rotSpeed)+1) + (fmul(dirY, c_rotSpeed)+1); - oldPlaneX = planeX; - planeX = (fmul(planeX, c_rotSpeed)+1) - (fmul(planeY, -s_rotSpeed)+1); + dirY = (fmul(oldDirX, -s_rotSpeed)+1) + (fmul(dirY, c_rotSpeed)+1); + oldPlaneX = planeX; + planeX = (fmul(planeX, c_rotSpeed)+1) - (fmul(planeY, -s_rotSpeed)+1); planeY = (fmul(oldPlaneX, -s_rotSpeed)+1) + (fmul(planeY, c_rotSpeed)+1); } //rotate to the left @@ -82,28 +82,28 @@ void move() { } if (dirX > 0xFFFF) dirX = 0xFFFF; - if (dirY > 0xFFFF) dirY = 0xFFFF; - if (dirX < -0xFFFF) dirX = -0xFFFF; - if (dirY < -0xFFFF) dirY = -0xFFFF; + if (dirY > 0xFFFF) dirY = 0xFFFF; + if (dirX < -0xFFFF) dirX = -0xFFFF; + if (dirY < -0xFFFF) dirY = -0xFFFF; } void end_screen(){ - int a; - - dtext_opt(198, 70, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Vous avez battu Maze3D !", -1); - dtext_opt(198, 90, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Optn - Rejouer", -1); - dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Menu - Quitter", -1); + int a; - dupdate(); + dtext_opt(198, 70, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Vous avez battu Maze3D !", -1); + dtext_opt(198, 90, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Optn - Rejouer", -1); + dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Menu - Quitter", -1); - while(true){ - a = getkey().key; - if (a == KEY_OPTN) { - load_map(); - break; - } - } + dupdate(); + + while(true){ + a = getkey().key; + if (a == KEY_OPTN) { + load_map(); + break; + } + } } void logic(){ @@ -128,81 +128,84 @@ void spawn_gen(){ int SeedSeed; time_t timeN; - time(&timeN); - SeedSeed = timeN; + time(&timeN); + SeedSeed = timeN; - srand(SeedSeed); + srand(SeedSeed); - while(1){ - seed = rand() * 0.5 + rand() * 0.5; - seed_x = seed & 0b1111111; - seed_y = (seed >> 8) & 0b111111; - if (seed_x < map_w && seed_y < map_h && (seed_x < 111 && seed_y > 15)){ - if(map_test[seed_x][seed_y] == 0){ - break; - } - } - } - fixed_t start_dirX, start_dirY; + while(1){ + seed = rand() * 0.5 + rand() * 0.5; + seed_x = seed & 0b1111111; + seed_y = (seed >> 8) & 0b111111; + if (seed_x < map_w && seed_y < map_h && (seed_x < 111 && seed_y > 15)){ + if(map_test[seed_x][seed_y] == 0){ + break; + } + } + } + fixed_t start_dirX, start_dirY; - int dirSeed = (seed >> 9) & 0b11 ; - switch(dirSeed){ - case 0: { - start_dirX = 0x0; - start_dirY = 0xFFFF; - planeX = fix(0.66); - planeY = 0; - break; - } - case 1: { - start_dirX = 0xFFFF; - start_dirY = 0x0; - planeX = 0; - planeY = fix(-0.66); - break; - } - case 2: { - start_dirX = -0xFFFF; - start_dirY = 0x0; - planeX = 0; - planeY = fix(0.66); - break; - } - case 3: { - start_dirX = 0x0; - start_dirY = -0xFFFF; - planeX = fix(-0.66); - planeY = 0; - break; - } - default : { - start_dirX = 0xFFFF; - start_dirY = 0x0; - planeX = 0; - planeY = fix(-0.66); - break; - } - } + int dirSeed = (seed >> 9) & 0b11 ; + switch(dirSeed){ + case 0: { + start_dirX = 0x0; + start_dirY = 0xFFFF; + planeX = fix(0.66); + planeY = 0; + break; + } + case 1: { + start_dirX = 0xFFFF; + start_dirY = 0x0; + planeX = 0; + planeY = fix(-0.66); + break; + } + case 2: { + start_dirX = -0xFFFF; + start_dirY = 0x0; + planeX = 0; + planeY = fix(0.66); + break; + } + case 3: { + start_dirX = 0x0; + start_dirY = -0xFFFF; + planeX = fix(-0.66); + planeY = 0; + break; + } + default : { + start_dirX = 0xFFFF; + start_dirY = 0x0; + planeX = 0; + planeY = fix(-0.66); + break; + } + } - posX = fix(seed_x) + 0x7FFF; - posY = fix(seed_y) + 0x7FFF; //x and y start position + posX = fix(seed_x) + 0x7FFF; + posY = fix(seed_y) + 0x7FFF; //x and y start position dirX = start_dirX; - dirY = start_dirY; //initial direction vector + dirY = start_dirY; //initial direction vector } + + void load_map(){ - dtext( 1, 1, C_BLACK, "Chargement..."); - dupdate(); + + spawn_gen(); } -void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, image_t *D_tex, image_t *frame_buffer){ +void draw_walls(image_t *frame_buffer){ extern fixed_t posX; extern fixed_t posY; extern fixed_t dirX; extern fixed_t dirY; extern fixed_t planeX; extern fixed_t planeY; + extern image_t *tex_index[TINDEX_S]; extern char map_test[map_w][map_h]; fixed_t cameraX; @@ -271,7 +274,7 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, if (rayDirY == 0) { stepY = 0; - sideDistY = 0; + sideDistY = 0; } else if (rayDirY < 0) { stepY = -1; @@ -324,10 +327,8 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, //x coordinate on the texture texX = fmul(wallX, 64); - while(texX >= 64 || texX < 0){ - if(texX >= 64) texX -= 64; - if(texX < 0) texX += 64; - } + texX = texX % 64; + if(side == 0 && rayDirX > 0) texX = 64 - texX - 1; if(side == 1 && rayDirY < 0) texX = 64 - texX - 1; @@ -347,15 +348,8 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, } image_t texStripe; - image_clear(&texStripe); - switch(map_test[mapX][mapY]){ - case 1 : texStripe = *image_sub(tex_1, texX, texSampleY, 1, texSample); break; - case 2 : texStripe = *image_sub(tex_2, texX, texSampleY, 1, texSample); break; - case 3 : texStripe = *image_sub(tex_3, texX, texSampleY, 1, texSample); break; - case 4 : texStripe = *image_sub(tex_4, texX, texSampleY, 1, texSample); break; - default : texStripe = *image_sub(D_tex, texX, texSampleY, 1, texSample); break; - } + texStripe = *image_sub(tex_index[map_test[mapX][mapY]], texX, texSampleY, 1, texSample); image_scale(&texStripe, 0xFFFF, texSize, &temp); image_linear(&texStripe, image_at(frame_buffer, x, (int)(viewport_h * 0.5 - lineHeight * 0.5) + v_offset), &temp); diff --git a/src/moteur.h b/src/moteur.h index 73187fd..04ea33b 100644 --- a/src/moteur.h +++ b/src/moteur.h @@ -1,3 +1,5 @@ +// Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3 + #ifndef moteur_h #define moteur_h @@ -10,10 +12,12 @@ #define viewport_h 224 #define max_dist 0x1FFFFF //en tuiles << 16, actuellement 32 +#define TINDEX_S 256 + void load_map(); void end_screen(); void logic(); -void draw_walls(image_t*, image_t*, image_t*, image_t*, image_t*, image_t*); +void draw_walls(image_t *frame_buffer); void move(); #endif /* moteur */