mirror of
https://git.planet-casio.com/Fcalva/Copy3DEngine.git
synced 2025-06-07 07:55:03 +02:00
201 lines
3.7 KiB
C
201 lines
3.7 KiB
C
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
|
|
#include <gint/display.h>
|
|
#include <gint/keyboard.h>
|
|
#include <gint/image.h>
|
|
#include <gint/gray.h>
|
|
#include <gint/dma.h>
|
|
#include <gint/gdb.h>
|
|
#include <libprof.h>
|
|
|
|
#include "C3D/fixed.h"
|
|
|
|
#include "C3D/game.h"
|
|
#include "C3D/sprites.h"
|
|
#include "C3D/moteur.h"
|
|
#include "C3D/map.h"
|
|
#include "C3D/config.h"
|
|
|
|
//====== Copy3DEngine =====
|
|
// Git du moteur : https://git.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
|
|
//
|
|
//
|
|
|
|
bopti_image_t *tex_index[TINDEX_S];
|
|
|
|
extern uint8_t map_test[map_w][map_h];
|
|
|
|
//Vos images ici
|
|
|
|
extern bopti_image_t briques0;
|
|
extern bopti_image_t buisson0;
|
|
extern bopti_image_t sprite_tst;
|
|
|
|
char disp_frame_time = 0;
|
|
char first_frame = 0;
|
|
int frame_time_timer = 1;
|
|
|
|
RcMap map0 = {
|
|
.w = 128,
|
|
.h = 64,
|
|
.dat = (void*)&map_test
|
|
};
|
|
|
|
RcGame game = {
|
|
.player = {
|
|
.pos = {fix(3.1), fix(3.1)},
|
|
.dir = {fix(0), fix(1)},
|
|
.plane = {fix(0.66), fix(0)}
|
|
},
|
|
.current_map = &map0,
|
|
.flags = {0}
|
|
};
|
|
|
|
int frame_time = 1;
|
|
|
|
void keys_get(){
|
|
pollevent();
|
|
|
|
move(&game);
|
|
|
|
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)) game.flags.exit = 1;
|
|
|
|
if(keydown(KEY_F2)){
|
|
dprint(0,0,3,"%d",raycast(&game, &game.player, NULL));
|
|
}
|
|
|
|
#ifdef debug
|
|
//if (keydown(KEY_TAN)) end_screen();
|
|
#endif
|
|
}
|
|
|
|
void main_menu(){
|
|
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 "AUTHOR, -1);
|
|
dtext_opt(198, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1);
|
|
|
|
dupdate();
|
|
getkey();
|
|
}
|
|
|
|
Sprite tsprite = {
|
|
.pos = {200000, 300000},
|
|
.tex = 4
|
|
};
|
|
|
|
int movdir = 1;
|
|
|
|
int test_logic(RcGame *game){
|
|
tsprite.pos.x += movdir*500;
|
|
if(tsprite.pos.x > fix(4) || tsprite.pos.x < fix(2))
|
|
movdir = -movdir;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main(){
|
|
dclear(C_WHITE);
|
|
|
|
//trucs de chargement
|
|
|
|
load_map();
|
|
|
|
tex_index[1] = &buisson0;
|
|
tex_index[2] = &briques0;
|
|
|
|
//Vos textures générées procéduralement (TODO)
|
|
|
|
tex_index[0] = &briques0;
|
|
tex_index[3] = &briques0;
|
|
|
|
tex_index[4] = &sprite_tst;
|
|
|
|
prof_init();
|
|
|
|
if(dgray(DGRAY_ON))
|
|
goto c3d_abort;
|
|
dupdate();
|
|
|
|
dclear(0);
|
|
|
|
#if debug
|
|
EngineTimers timers;
|
|
//gdb_start_on_exception();
|
|
#endif
|
|
|
|
add_sprite(&tsprite);
|
|
|
|
add_logic_hook((RcLogicFunc*)&test_logic);
|
|
|
|
while (!game.flags.exit) {
|
|
prof_t frame = prof_make();
|
|
prof_enter(frame);
|
|
|
|
dclear(C_WHITE);
|
|
|
|
if(first_frame){
|
|
main_menu();
|
|
}
|
|
|
|
keys_get();
|
|
|
|
do_logic(&game, frame_time);
|
|
|
|
draw_walls(
|
|
#if debug
|
|
&timers,
|
|
#endif
|
|
&game
|
|
);
|
|
|
|
draw_sprites(tex_index, &game.player);
|
|
|
|
if (disp_frame_time == 1) dprint( 0, 0, C_BLACK, "%d ms", frame_time/1000);
|
|
|
|
#if debug
|
|
dprint( 1, 27, C_BLACK, "pX %d", game.player.pos.x);
|
|
dprint( 1, 36, C_BLACK, "pY %d", game.player.pos.y);
|
|
dprint( 1, 9, C_BLACK, "Rct %d", prof_time(timers.raycast_time));
|
|
dprint( 1, 18, C_BLACK, "Dt %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);
|
|
first_frame = 0;
|
|
}
|
|
|
|
c3d_abort:
|
|
|
|
dgray(DGRAY_OFF);
|
|
|
|
prof_quit();
|
|
|
|
//Libérez vos textures générées procéduralement
|
|
|
|
//bopti_free(tex_index[0]);
|
|
//bopti_free(tex_index[3]);
|
|
|
|
return 1;
|
|
}
|