mirror of
https://git.planet-casio.com/Fcalva/Copy3DEngine.git
synced 2024-12-28 04:23:44 +01:00
Fork en Copy 3D Engine
This commit is contained in:
parent
0e30bad97d
commit
1dd453bfb3
7 changed files with 211 additions and 233 deletions
|
@ -2,33 +2,39 @@
|
||||||
# toolchain file and module path of the fxSDK
|
# toolchain file and module path of the fxSDK
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
project(Maze3D)
|
project(Copy3DEngine)
|
||||||
|
|
||||||
include(GenerateG3A)
|
include(GenerateG3A)
|
||||||
include(Fxconv)
|
include(Fxconv)
|
||||||
find_package(Gint 2.9 REQUIRED)
|
find_package(Gint 2.9 REQUIRED)
|
||||||
find_package(LibProf 2.1 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
|
set(SOURCES
|
||||||
src/main.c
|
src/main.c
|
||||||
src/moteur.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
|
set(ASSETS
|
||||||
assets-cg/textures/briques0.png
|
assets-cg/textures/briques0.png
|
||||||
assets-cg/textures/buisson1.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}})
|
add_executable(Copy3DEngine ${SOURCES} ${ASSETS})
|
||||||
target_compile_options(myaddin PRIVATE -Wall -Wextra -Ofast -fira-region=all -flto -fno-math-errno -funsafe-math-optimizations -fassociative-math -freciprocal-math)
|
target_compile_options(Copy3DEngine 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_compile_definitions(Copy3DEngine PRIVATE NAMEOFGAME="${NAMEOFGAME}" AUTHOR="${AUTHOR}")
|
||||||
target_link_libraries(myaddin LibProf::LibProf)
|
target_link_libraries(Copy3DEngine Gint::Gint)
|
||||||
target_link_options(myaddin PRIVATE -Wl,--print-memory-usage,-flto)
|
target_link_libraries(Copy3DEngine LibProf::LibProf)
|
||||||
|
target_link_options(Copy3DEngine PRIVATE -Wl,--print-memory-usage,-flto)
|
||||||
|
|
||||||
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
||||||
generate_g3a(TARGET myaddin OUTPUT "Maze3D.g3a"
|
generate_g3a(TARGET Copy3DEngine OUTPUT "${NAMEOFGAME}.g3a"
|
||||||
NAME "Maze3D" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
|
NAME "${NAMEOFGAME}" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
|
||||||
endif()
|
endif()
|
||||||
|
|
190
src/main.c
190
src/main.c
|
@ -6,29 +6,18 @@
|
||||||
#include <gint/image.h>
|
#include <gint/image.h>
|
||||||
#include <libprof.h>
|
#include <libprof.h>
|
||||||
|
|
||||||
//#define USB
|
|
||||||
|
|
||||||
#ifdef USB
|
|
||||||
#include <gint/usb-ff-bulk.h>
|
|
||||||
#include <gint/usb.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "fixed.h"
|
#include "fixed.h"
|
||||||
|
|
||||||
#include "moteur.h"
|
#include "moteur.h"
|
||||||
#include "map_test.h"
|
#include "map.h"
|
||||||
|
|
||||||
//====== Maze3D V1.0.4 =====
|
//====== Copy3DEngine =====
|
||||||
// Git du moteur : https://github.com/attilavs2/Raycaster_G90
|
// Git du moteur : TODO
|
||||||
// Git du jeu : https://gitea.planet-casio.com/Fcalva/Maze3D
|
// 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
|
// Voir README.md pour license précise, par Fcalva et est sous GPLv3
|
||||||
// Game design : Fcalva (aka. fklv, Fcalva#6860, attilavs2)
|
|
||||||
// Programmation : Fcalva
|
|
||||||
// "Art" : Fcalva
|
|
||||||
//
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -36,25 +25,21 @@
|
||||||
#error Ce code est pour FXCG50/G90+E uniquement, enlevez ce message a vos riques et périls
|
#error Ce code est pour FXCG50/G90+E uniquement, enlevez ce message a vos riques et périls
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef USB
|
|
||||||
void USB_capture() {
|
|
||||||
if (usb_is_open()) usb_fxlink_screenshot(false);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//#define debug //pour afficher les infos de debug
|
//#define debug //pour afficher les infos de debug
|
||||||
|
|
||||||
|
image_t *tex_index[TINDEX_S];
|
||||||
|
|
||||||
extern char map_test[map_w][map_h];
|
extern char map_test[map_w][map_h];
|
||||||
|
|
||||||
|
//Vos images ici
|
||||||
|
|
||||||
extern image_t briques0;
|
extern image_t briques0;
|
||||||
extern image_t buisson0;
|
extern image_t buisson0;
|
||||||
|
|
||||||
char exit_game = 0;
|
char exit_game = 0;
|
||||||
char disp_frame_time = 0;
|
char disp_frame_time = 0;
|
||||||
char first_frame = 1;
|
char first_frame = 0;
|
||||||
int frame_time_timer = 1;
|
int frame_time_timer = 1;
|
||||||
int capture_timer = 1;
|
|
||||||
|
|
||||||
fixed_t posX;
|
fixed_t posX;
|
||||||
fixed_t posY;
|
fixed_t posY;
|
||||||
|
@ -63,117 +48,104 @@ fixed_t dirY;
|
||||||
fixed_t planeX;
|
fixed_t planeX;
|
||||||
fixed_t planeY;
|
fixed_t planeY;
|
||||||
|
|
||||||
int frame_time = 0;
|
int frame_time = 1;
|
||||||
|
|
||||||
void keys_get(){
|
void keys_get(){
|
||||||
move();
|
pollevent();
|
||||||
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;
|
|
||||||
|
|
||||||
#ifdef debug
|
move();
|
||||||
if (keydown(KEY_TAN)) end_screen();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USB
|
if (keydown(KEY_F1) && frame_time_timer <= 0) {
|
||||||
if (keydown(KEY_0) && keydown(KEY_EXE) && capture_timer <= 0) {
|
if (disp_frame_time == 0) {
|
||||||
USB_capture();
|
disp_frame_time = 1;
|
||||||
capture_timer = 10;
|
frame_time_timer = 10;
|
||||||
}
|
}
|
||||||
capture_timer--;
|
else {
|
||||||
#endif
|
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(){
|
void main_menu(){
|
||||||
dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Maze 3D", -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", -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);
|
dtext_opt(198, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1);
|
||||||
|
|
||||||
dupdate();
|
dupdate();
|
||||||
getkey();
|
getkey();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
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);
|
extern image_t *tex_index[TINDEX_S];
|
||||||
image_t WXOR_tex = *image_alloc(64, 64, IMAGE_RGB565);
|
|
||||||
image_t D_tex = *image_alloc(64, 64, IMAGE_RGB565);
|
|
||||||
|
|
||||||
int i, j;
|
tex_index[1] = &buisson0;
|
||||||
for (i = 0; i<= 64; i++){
|
tex_index[2] = &briques0;
|
||||||
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);
|
|
||||||
|
|
||||||
prof_init();
|
//Vos textures générées procéduralement
|
||||||
|
|
||||||
#ifdef USB
|
tex_index[0] = image_alloc(64, 64, IMAGE_RGB565);
|
||||||
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
|
tex_index[3] = image_alloc(64, 64, IMAGE_RGB565);
|
||||||
usb_open(interfaces, GINT_CALL_NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (exit_game == 0) {
|
image_fill(tex_index[0], 0x4228);
|
||||||
prof_t frame = prof_make();
|
image_fill(tex_index[3], 0x9dbd);
|
||||||
prof_enter(frame);
|
|
||||||
|
|
||||||
drect(0, 0, 395, 112, 0x9dbd);
|
prof_init();
|
||||||
drect(0,112, 395, 243, 0xc4c9);
|
|
||||||
|
|
||||||
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
|
logic();
|
||||||
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
|
|
||||||
|
|
||||||
dupdate();
|
if (disp_frame_time == 1) dprint( 1, 10, C_BLACK, "Frame time : %d ms", frame_time);
|
||||||
prof_leave(frame);
|
|
||||||
frame_time = (int)prof_time(frame)/1000;
|
|
||||||
first_frame = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
prof_quit();
|
#ifdef debug
|
||||||
#ifdef USB
|
dprint( 1, 20, C_BLACK, "planeX : %d", planeX);
|
||||||
usb_close();
|
dprint( 1, 30, C_BLACK, "planeY : %d", planeY);
|
||||||
#endif
|
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);
|
dupdate();
|
||||||
free(&WXOR_tex);
|
prof_leave(frame);
|
||||||
free(&D_tex);
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
#include "moteur.h"
|
||||||
|
|
||||||
char map_test[map_w][map_h] = {
|
char map_test[map_w][map_h] = {
|
10
src/map.h
Normal file
10
src/map.h
Normal 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 */
|
|
@ -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 */
|
|
196
src/moteur.c
196
src/moteur.c
|
@ -1,3 +1,5 @@
|
||||||
|
// Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -10,7 +12,7 @@
|
||||||
#include "fixed.h"
|
#include "fixed.h"
|
||||||
|
|
||||||
#include "moteur.h"
|
#include "moteur.h"
|
||||||
#include "map_test.h"
|
#include "map.h"
|
||||||
|
|
||||||
// moteur.c :
|
// moteur.c :
|
||||||
// ici se trouvent tout ce qui concerne les graphismes, mouvement et collisions
|
// ici se trouvent tout ce qui concerne les graphismes, mouvement et collisions
|
||||||
|
@ -39,13 +41,11 @@ void move() {
|
||||||
int xtemp2;
|
int xtemp2;
|
||||||
int ytemp2;
|
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);
|
ytemp1 = f2int(posY);
|
||||||
xtemp2 = f2int(posX);
|
xtemp2 = f2int(posX);
|
||||||
ytemp2 = f2int(posY + fmul(dirY, moveSpeed));
|
ytemp2 = f2int(posY + fmul(dirY, moveSpeed));
|
||||||
|
|
||||||
if(map_test[xtemp1][ytemp1] == 0) posX += fmul(dirX, moveSpeed);
|
if(map_test[xtemp1][ytemp1] == 0) posX += fmul(dirX, moveSpeed);
|
||||||
if(map_test[xtemp2][ytemp2] == 0) posY += fmul(dirY, moveSpeed);
|
if(map_test[xtemp2][ytemp2] == 0) posY += fmul(dirY, moveSpeed);
|
||||||
|
@ -53,9 +53,9 @@ void move() {
|
||||||
//move backwards if no wall behind you
|
//move backwards if no wall behind you
|
||||||
if (keydown(KEY_DOWN)) {
|
if (keydown(KEY_DOWN)) {
|
||||||
xtemp1 = f2int(posX - fmul(dirX, moveSpeed));
|
xtemp1 = f2int(posX - fmul(dirX, moveSpeed));
|
||||||
ytemp1 = f2int(posY);
|
ytemp1 = f2int(posY);
|
||||||
xtemp2 = f2int(posX);
|
xtemp2 = f2int(posX);
|
||||||
ytemp2 = f2int(posY - fmul(dirY, moveSpeed));
|
ytemp2 = f2int(posY - fmul(dirY, moveSpeed));
|
||||||
|
|
||||||
if(map_test[xtemp1][ytemp1] == 0) posX -= fmul(dirX, moveSpeed);
|
if(map_test[xtemp1][ytemp1] == 0) posX -= fmul(dirX, moveSpeed);
|
||||||
if(map_test[xtemp2][ytemp2] == 0) posY -= fmul(dirY, moveSpeed);
|
if(map_test[xtemp2][ytemp2] == 0) posY -= fmul(dirY, moveSpeed);
|
||||||
|
@ -63,11 +63,11 @@ void move() {
|
||||||
//rotate to the rightdouble sin_rotspeed;
|
//rotate to the rightdouble sin_rotspeed;
|
||||||
if (keydown(KEY_RIGHT)) {
|
if (keydown(KEY_RIGHT)) {
|
||||||
//both camera direction and camera plane must be rotated
|
//both camera direction and camera plane must be rotated
|
||||||
oldDirX = dirX;
|
oldDirX = dirX;
|
||||||
dirX = (fmul(dirX, c_rotSpeed)+1) - (fmul(dirY, -s_rotSpeed)+1);
|
dirX = (fmul(dirX, c_rotSpeed)+1) - (fmul(dirY, -s_rotSpeed)+1);
|
||||||
dirY = (fmul(oldDirX, -s_rotSpeed)+1) + (fmul(dirY, c_rotSpeed)+1);
|
dirY = (fmul(oldDirX, -s_rotSpeed)+1) + (fmul(dirY, c_rotSpeed)+1);
|
||||||
oldPlaneX = planeX;
|
oldPlaneX = planeX;
|
||||||
planeX = (fmul(planeX, c_rotSpeed)+1) - (fmul(planeY, -s_rotSpeed)+1);
|
planeX = (fmul(planeX, c_rotSpeed)+1) - (fmul(planeY, -s_rotSpeed)+1);
|
||||||
planeY = (fmul(oldPlaneX, -s_rotSpeed)+1) + (fmul(planeY, c_rotSpeed)+1);
|
planeY = (fmul(oldPlaneX, -s_rotSpeed)+1) + (fmul(planeY, c_rotSpeed)+1);
|
||||||
}
|
}
|
||||||
//rotate to the left
|
//rotate to the left
|
||||||
|
@ -82,28 +82,28 @@ void move() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirX > 0xFFFF) dirX = 0xFFFF;
|
if (dirX > 0xFFFF) dirX = 0xFFFF;
|
||||||
if (dirY > 0xFFFF) dirY = 0xFFFF;
|
if (dirY > 0xFFFF) dirY = 0xFFFF;
|
||||||
if (dirX < -0xFFFF) dirX = -0xFFFF;
|
if (dirX < -0xFFFF) dirX = -0xFFFF;
|
||||||
if (dirY < -0xFFFF) dirY = -0xFFFF;
|
if (dirY < -0xFFFF) dirY = -0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void end_screen(){
|
void end_screen(){
|
||||||
int a;
|
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);
|
|
||||||
|
|
||||||
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){
|
dupdate();
|
||||||
a = getkey().key;
|
|
||||||
if (a == KEY_OPTN) {
|
while(true){
|
||||||
load_map();
|
a = getkey().key;
|
||||||
break;
|
if (a == KEY_OPTN) {
|
||||||
}
|
load_map();
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void logic(){
|
void logic(){
|
||||||
|
@ -128,81 +128,84 @@ void spawn_gen(){
|
||||||
int SeedSeed;
|
int SeedSeed;
|
||||||
|
|
||||||
time_t timeN;
|
time_t timeN;
|
||||||
time(&timeN);
|
time(&timeN);
|
||||||
SeedSeed = timeN;
|
SeedSeed = timeN;
|
||||||
|
|
||||||
srand(SeedSeed);
|
srand(SeedSeed);
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
seed = rand() * 0.5 + rand() * 0.5;
|
seed = rand() * 0.5 + rand() * 0.5;
|
||||||
seed_x = seed & 0b1111111;
|
seed_x = seed & 0b1111111;
|
||||||
seed_y = (seed >> 8) & 0b111111;
|
seed_y = (seed >> 8) & 0b111111;
|
||||||
if (seed_x < map_w && seed_y < map_h && (seed_x < 111 && seed_y > 15)){
|
if (seed_x < map_w && seed_y < map_h && (seed_x < 111 && seed_y > 15)){
|
||||||
if(map_test[seed_x][seed_y] == 0){
|
if(map_test[seed_x][seed_y] == 0){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fixed_t start_dirX, start_dirY;
|
fixed_t start_dirX, start_dirY;
|
||||||
|
|
||||||
int dirSeed = (seed >> 9) & 0b11 ;
|
int dirSeed = (seed >> 9) & 0b11 ;
|
||||||
switch(dirSeed){
|
switch(dirSeed){
|
||||||
case 0: {
|
case 0: {
|
||||||
start_dirX = 0x0;
|
start_dirX = 0x0;
|
||||||
start_dirY = 0xFFFF;
|
start_dirY = 0xFFFF;
|
||||||
planeX = fix(0.66);
|
planeX = fix(0.66);
|
||||||
planeY = 0;
|
planeY = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
start_dirX = 0xFFFF;
|
start_dirX = 0xFFFF;
|
||||||
start_dirY = 0x0;
|
start_dirY = 0x0;
|
||||||
planeX = 0;
|
planeX = 0;
|
||||||
planeY = fix(-0.66);
|
planeY = fix(-0.66);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
start_dirX = -0xFFFF;
|
start_dirX = -0xFFFF;
|
||||||
start_dirY = 0x0;
|
start_dirY = 0x0;
|
||||||
planeX = 0;
|
planeX = 0;
|
||||||
planeY = fix(0.66);
|
planeY = fix(0.66);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: {
|
case 3: {
|
||||||
start_dirX = 0x0;
|
start_dirX = 0x0;
|
||||||
start_dirY = -0xFFFF;
|
start_dirY = -0xFFFF;
|
||||||
planeX = fix(-0.66);
|
planeX = fix(-0.66);
|
||||||
planeY = 0;
|
planeY = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default : {
|
default : {
|
||||||
start_dirX = 0xFFFF;
|
start_dirX = 0xFFFF;
|
||||||
start_dirY = 0x0;
|
start_dirY = 0x0;
|
||||||
planeX = 0;
|
planeX = 0;
|
||||||
planeY = fix(-0.66);
|
planeY = fix(-0.66);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
posX = fix(seed_x) + 0x7FFF;
|
posX = fix(seed_x) + 0x7FFF;
|
||||||
posY = fix(seed_y) + 0x7FFF; //x and y start position
|
posY = fix(seed_y) + 0x7FFF; //x and y start position
|
||||||
dirX = start_dirX;
|
dirX = start_dirX;
|
||||||
dirY = start_dirY; //initial direction vector
|
dirY = start_dirY; //initial direction vector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void load_map(){
|
void load_map(){
|
||||||
dtext( 1, 1, C_BLACK, "Chargement...");
|
|
||||||
dupdate();
|
|
||||||
spawn_gen();
|
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 posX;
|
||||||
extern fixed_t posY;
|
extern fixed_t posY;
|
||||||
extern fixed_t dirX;
|
extern fixed_t dirX;
|
||||||
extern fixed_t dirY;
|
extern fixed_t dirY;
|
||||||
extern fixed_t planeX;
|
extern fixed_t planeX;
|
||||||
extern fixed_t planeY;
|
extern fixed_t planeY;
|
||||||
|
extern image_t *tex_index[TINDEX_S];
|
||||||
extern char map_test[map_w][map_h];
|
extern char map_test[map_w][map_h];
|
||||||
|
|
||||||
fixed_t cameraX;
|
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) {
|
if (rayDirY == 0) {
|
||||||
stepY = 0;
|
stepY = 0;
|
||||||
sideDistY = 0;
|
sideDistY = 0;
|
||||||
}
|
}
|
||||||
else if (rayDirY < 0) {
|
else if (rayDirY < 0) {
|
||||||
stepY = -1;
|
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
|
//x coordinate on the texture
|
||||||
texX = fmul(wallX, 64);
|
texX = fmul(wallX, 64);
|
||||||
while(texX >= 64 || texX < 0){
|
texX = texX % 64;
|
||||||
if(texX >= 64) texX -= 64;
|
|
||||||
if(texX < 0) texX += 64;
|
|
||||||
}
|
|
||||||
if(side == 0 && rayDirX > 0) texX = 64 - texX - 1;
|
if(side == 0 && rayDirX > 0) texX = 64 - texX - 1;
|
||||||
if(side == 1 && rayDirY < 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_t texStripe;
|
||||||
image_clear(&texStripe);
|
|
||||||
|
|
||||||
switch(map_test[mapX][mapY]){
|
texStripe = *image_sub(tex_index[map_test[mapX][mapY]], texX, texSampleY, 1, texSample);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
image_scale(&texStripe, 0xFFFF, texSize, &temp);
|
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);
|
image_linear(&texStripe, image_at(frame_buffer, x, (int)(viewport_h * 0.5 - lineHeight * 0.5) + v_offset), &temp);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3
|
||||||
|
|
||||||
#ifndef moteur_h
|
#ifndef moteur_h
|
||||||
#define moteur_h
|
#define moteur_h
|
||||||
|
|
||||||
|
@ -10,10 +12,12 @@
|
||||||
#define viewport_h 224
|
#define viewport_h 224
|
||||||
#define max_dist 0x1FFFFF //en tuiles << 16, actuellement 32
|
#define max_dist 0x1FFFFF //en tuiles << 16, actuellement 32
|
||||||
|
|
||||||
|
#define TINDEX_S 256
|
||||||
|
|
||||||
void load_map();
|
void load_map();
|
||||||
void end_screen();
|
void end_screen();
|
||||||
void logic();
|
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();
|
void move();
|
||||||
|
|
||||||
#endif /* moteur */
|
#endif /* moteur */
|
||||||
|
|
Loading…
Reference in a new issue