Fork en Copy 3D Engine

This commit is contained in:
attilavs2 2024-03-09 21:21:17 +01:00
parent 0e30bad97d
commit 1dd453bfb3
7 changed files with 211 additions and 233 deletions

View file

@ -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()

View file

@ -6,29 +6,18 @@
#include <gint/image.h>
#include <libprof.h>
//#define USB
#ifdef USB
#include <gint/usb-ff-bulk.h>
#include <gint/usb.h>
#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
//
// Tout le code de cette version est en GPL3
// Game design : Fcalva (aka. fklv, Fcalva#6860, attilavs2)
// Programmation : Fcalva
// "Art" : Fcalva
// Page du jeu : [La vôtre ici]
//
// 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,11 +48,13 @@ fixed_t dirY;
fixed_t planeX;
fixed_t planeY;
int frame_time = 0;
int frame_time = 1;
void keys_get(){
move();
pollevent();
move();
if (keydown(KEY_F1) && frame_time_timer <= 0) {
if (disp_frame_time == 0) {
disp_frame_time = 1;
@ -79,24 +66,16 @@ void keys_get(){
}
}
frame_time_timer--;
if (keydown(KEY_F6)) exit_game = 1;
if (keydown(KEY_EXIT)) exit_game = 1;
#ifdef debug
if (keydown(KEY_TAN)) end_screen();
#endif
#ifdef USB
if (keydown(KEY_0) && keydown(KEY_EXE) && capture_timer <= 0) {
USB_capture();
capture_timer = 10;
}
capture_timer--;
#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, 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();
@ -112,38 +91,34 @@ int main(){
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;
//Vos textures générées procéduralement
tex_index[0] = image_alloc(64, 64, IMAGE_RGB565);
tex_index[3] = image_alloc(64, 64, IMAGE_RGB565);
image_fill(tex_index[0], 0x4228);
image_fill(tex_index[3], 0x9dbd);
prof_init();
#ifdef USB
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
usb_open(interfaces, GINT_CALL_NULL);
#endif
while (exit_game == 0) {
while (!exit_game) {
prof_t frame = prof_make();
prof_enter(frame);
drect(0, 0, 395, 112, 0x9dbd);
drect(0,112, 395, 243, 0xc4c9);
draw_walls(&buisson0, &briques0, &sky_tex, &WXOR_tex, &D_tex, frame_buffer);
draw_walls(frame_buffer);
if(first_frame == 1) main_menu();
if(first_frame == 1){
main_menu();
first_frame = 0;
}
keys_get();
@ -163,17 +138,14 @@ int main(){
dupdate();
prof_leave(frame);
frame_time = (int)prof_time(frame)/1000;
first_frame = 0;
}
prof_quit();
#ifdef USB
usb_close();
#endif
free(&sky_tex);
free(&WXOR_tex);
free(&D_tex);
//Libérez vos textures générées procéduralement
image_free(tex_index[0]);
image_free(tex_index[3]);
return 1;
}

View file

@ -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] = {

10
src/map.h Normal file
View file

@ -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 */

View file

@ -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 */

View file

@ -1,3 +1,5 @@
// Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3
#include <math.h>
#include <stdlib.h>
#include <string.h>
@ -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,8 +41,6 @@ void move() {
int xtemp2;
int ytemp2;
pollevent();
if (keydown(KEY_UP)) {
xtemp1 = f2int(posX + fmul(dirX, moveSpeed));
ytemp1 = f2int(posY);
@ -190,19 +190,22 @@ void spawn_gen(){
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;
@ -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);

View file

@ -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 */