Copy3DEngine/src/main.c
2024-09-01 16:38:23 +02:00

161 lines
3.3 KiB
C

#include <stdlib.h>
#include <math.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/image.h>
#include <gint/dma.h>
#include <gint/gdb.h>
#include <libprof.h>
#include "fixed.h"
#include "moteur.h"
#include "map.h"
//====== Copy3DEngine =====
// Git du moteur : https://gitea.planet-casio.com/Fcalva/Copy3DEngine
// Git du jeu : [Rajoutez le vôtre ici]
//
// Page du jeu : [La vôtre ici]
//
// Voir README.md pour license précise, par Fcalva et est sous GPLv3
//
//
#ifndef FXCG50
#error Ce code est pour FXCG50/G90+E uniquement, enlevez ce message a vos riques et périls
#endif
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 = 0;
int frame_time_timer = 1;
fixed_t posX;
fixed_t posY;
fixed_t dirX;
fixed_t dirY;
fixed_t planeX;
fixed_t planeY;
int frame_time = 1;
void keys_get(){
pollevent();
move();
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, "Demo 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);
dupdate();
getkey();
}
int main(){
dclear(C_WHITE);
//trucs de chargement
load_map();
extern image_t *tex_index[TINDEX_S];
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();
#if debug
EngineTimers timers;
#endif
while (!exit_game) {
prof_t frame = prof_make();
prof_enter(frame);
//Big brain drect()
dma_memset(gint_vram, 0x9dbd9dbd, viewport_w*viewport_h);
dma_memset((void*)((uint32_t)gint_vram + viewport_w*viewport_h),
0xc4c9c4c9, viewport_w*viewport_h);
if(first_frame){
main_menu();
}
keys_get();
draw_walls(
#if debug
&timers
#endif
);
if (disp_frame_time == 1) dprint( 1, 10, C_BLACK, "Frame time : %d ms", frame_time);
#if 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);
dprint( 1, 80, C_BLACK, "Raycast time : %d", prof_time(timers.raycast_time));
dprint( 1, 90, C_BLACK, "Draw time : %d", prof_time(timers.draw_time));
timers.raycast_time = prof_make();
timers.draw_time = prof_make();
#endif
dupdate();
prof_leave(frame);
frame_time = (int)prof_time(frame)/1000;
first_frame = 0;
}
prof_quit();
//Libérez vos textures générées procéduralement
image_free(tex_index[0]);
image_free(tex_index[3]);
return 1;
}