commit cd49fa382cffde2083d84f2e2d23c6e9c4c94c40 Author: attilavs2 Date: Thu Jul 20 12:31:08 2023 +0200 Commit initial diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1de3d31 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +# Configure with [fxsdk build-fx] or [fxsdk build-cg], which provide the +# toolchain file and module path of the fxSDK + +cmake_minimum_required(VERSION 3.15) +project(Maze3D) + +include(GenerateG3A) +include(Fxconv) +find_package(Gint 2.9 REQUIRED) +find_package(LibProf 2.1 REQUIRED) + +set(SOURCES + src/main.c + src/moteur.c + src/sprites.c + src/map_test.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) + +add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}}) +target_compile_options(myaddin PRIVATE -Wall -Wextra -Os) +target_link_libraries(myaddin Gint::Gint ) +target_link_libraries(myaddin LibProf::LibProf) +target_link_options(myaddin PRIVATE -Wl,--print-memory-usage) + +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) +endif() diff --git a/assets-cg/fxconv-metadata.txt b/assets-cg/fxconv-metadata.txt new file mode 100644 index 0000000..50fbc7f --- /dev/null +++ b/assets-cg/fxconv-metadata.txt @@ -0,0 +1,6 @@ +zombard1.png: + type: bopti-image + name: zombard +skybox0.png: + type: bopti-image + name: skybox_quarter diff --git a/assets-cg/icon-cg.xcf b/assets-cg/icon-cg.xcf new file mode 100644 index 0000000..5b854f0 Binary files /dev/null and b/assets-cg/icon-cg.xcf differ diff --git a/assets-cg/icon-sel.png b/assets-cg/icon-sel.png new file mode 100644 index 0000000..60ce63d Binary files /dev/null and b/assets-cg/icon-sel.png differ diff --git a/assets-cg/icon-uns.png b/assets-cg/icon-uns.png new file mode 100644 index 0000000..a0a0c6b Binary files /dev/null and b/assets-cg/icon-uns.png differ diff --git a/assets-cg/textures/briques0.png b/assets-cg/textures/briques0.png new file mode 100644 index 0000000..341313a Binary files /dev/null and b/assets-cg/textures/briques0.png differ diff --git a/assets-cg/textures/buisson1.png b/assets-cg/textures/buisson1.png new file mode 100644 index 0000000..ac9882a Binary files /dev/null and b/assets-cg/textures/buisson1.png differ diff --git a/assets-cg/textures/fxconv-metadata.txt b/assets-cg/textures/fxconv-metadata.txt new file mode 100644 index 0000000..2c4d125 --- /dev/null +++ b/assets-cg/textures/fxconv-metadata.txt @@ -0,0 +1,7 @@ +briques0.png: + type: bopti-image + name: briques0 + +buisson1.png: + type: bopti-image + name: buisson0 diff --git a/src/OldMoteur.c b/src/OldMoteur.c new file mode 100644 index 0000000..decbd8c --- /dev/null +++ b/src/OldMoteur.c @@ -0,0 +1,394 @@ +#include +#include +#include + +#include +#include + +#include "moteur.h" +#include "sprites.h" +#include "map_test.h" + +int angle_60; +int angle_30; +int angle_15; +int angle_90; +int angle_180; +int angle_270; +int angle_360; +int angle_5; +int angle_10; +int angle_45; + +int cos_table[ang_360p]; +int sin_table[ang_360p]; +int tan_table[ang_360p]; +int acos_table[ang_360p]; +int asin_table[ang_360p]; +int atan_table[ang_360p]; +float tab_mur_x[ang_360p]; +float tab_mur_y[ang_360p]; +int distors_table[ang_360p]; + +angle_60 = viewport_w; +angle_30 = floor(viewport_w * 0.5); +angle_15 = floor(viewport_w * 0.25); +angle_90 = floor(viewport_w * 1.5); +angle_180 = floor(viewport_w * 3); +angle_270 = floor(viewport_w * 4.5); +angle_360 = floor(viewport_w * 6); +angle_5 = floor(viewport_w / 12); +angle_10 = floor(viewport_w / 6); +angle_45 = floor(viewport_w * 0.75); + +unsigned short table_couleur[235] = { + 0x10a2,0x18a3,0x18a3,0x18c3,0x18c3,0x18c3,0x18c3, + 0x18e3,0x18e3,0x20e4,0x20e4,0x2104,0x2104,0x2104, + 0x2104,0x2124,0x2124,0x2124,0x2925,0x2945,0x2945, + 0x2945,0x2945,0x2965,0x2965,0x2965,0x3166,0x3186, + 0x3186,0x3186,0x3186,0x31a6,0x31a6,0x31a6,0x39a7, + 0x39c7,0x39c7,0x39c7,0x39c7,0x39e7,0x39e7,0x39e7, + 0x41e8,0x4208,0x4208,0x4208,0x4208,0x4228,0x4228, + 0x4228,0x4a29,0x4a49,0x4a49,0x4a49,0x4a49,0x4a69, + 0x4a69,0x4a69,0x4a69,0x528a,0x528a,0x528a,0x528a, + 0x52aa,0x52aa,0x52aa,0x52aa,0x5aab,0x5acb,0x5acb, + 0x5acb,0x5acb,0x5aeb,0x5aeb,0x5aeb,0x62ec,0x630c, + 0x630c,0x630c,0x630c,0x632c,0x632c,0x632c,0x6b2d, + 0x6b4d,0x6b4d,0x6b4d,0x6b4d,0x6b6d,0x6b6d,0x6b6d, + 0x6b6d,0x738e,0x738e,0x738e,0x738e,0x73ae,0x73ae, + 0x73ae,0x73ae,0x7bcf,0x7bcf,0x7bcf,0x7bcf,0x7bef, + 0x7bef,0x7bef,0x7bef,0x8410,0x8410,0x8410,0x8410, + 0x8430,0x8430,0x8430,0x8430,0x8c51,0x8c51,0x8c51, + 0x8c51,0x8c71,0x8c71,0x8c71,0x8c71,0x9492,0x9492, + 0x9492,0x9492,0x94b2,0x94b2,0x94b2,0x94b2,0x94d2, + 0x9cd3,0x9cd3,0x9cd3,0x9cf3,0x9cf3,0x9cf3,0x9cf3, + 0x9d13,0xa514,0xa514,0xa514,0xa534,0xa534,0xa534, + 0xa534,0xa554,0xad55,0xad55,0xad55,0xad55,0xad75, + 0xad75,0xad75,0xad75,0xb596,0xb596,0xb596,0xb596, + 0xb5b6,0xb5b6,0xb5b6,0xb5b6,0xb5d6,0xbdd7,0xbdd7, + 0xbdd7,0xbdf7,0xbdf7,0xbdf7,0xbdf7,0xbe17,0xc618, + 0xc618,0xc618,0xc638,0xc638,0xc638,0xc638,0xc658, + 0xce59,0xce59,0xce59,0xce79,0xce79,0xce79,0xce79, + 0xce99,0xd69a,0xd69a,0xd69a,0xd6ba,0xd6ba,0xd6ba, + 0xd6ba,0xd6da,0xdedb,0xdedb,0xdedb,0xdefb,0xdefb, + 0xdefb,0xdefb,0xdf1b,0xdf1b,0xe71c,0xe71c,0xe73c, + 0xe73c,0xe73c,0xe73c,0xe75c,0xe75c,0xef5d,0xef5d, + 0xef7d,0xef7d,0xef7d,0xef7d,0xef9d,0xef9d,0xf79e, + 0xf79e,0xf7be,0xf7be,0xf7be,0xf7be,0xf7de,0xf7de, + 0xffdf,0xffdf,0xffff,0xffff +}; + +float deg_to_rad(float angle_deg) { + return((angle_deg * pi) / 180); +} + +void compute_table() { + extern int angle_30;//il y en a des inutilisés + extern int angle_15; + extern int angle_90; + extern int angle_180; + extern int angle_270; + extern int angle_360; + extern int angle_5; + extern int angle_10; + extern int angle_45; + extern int cos_table[ang_360p]; + extern int sin_table[ang_360p]; + extern int tan_table[ang_360p]; + extern int acos_table[ang_360p]; + extern int asin_table[ang_360p]; + extern int atan_table[ang_360p]; + extern float tab_mur_x[ang_360p]; + extern float tab_mur_y[ang_360p]; + extern int distors_table[ang_360p]; + int i = 0; + float rad_i = 0; + while (i != angle_360) { + rad_i = deg_to_rad(i / viewport_w); + cos_table[i] = floor( 64 * cos(rad_i)); + sin_table[i] = floor( 64 * sin(rad_i)); + tan_table[i] = floor( 64 * tan(rad_i)); + acos_table[i] = floor( 64 * acos(rad_i)); + asin_table[i] = floor( 64 * asin(rad_i)); + atan_table[i] = floor( 64 * atan(rad_i)); + if (i >= 90 && i < angle_270) { + tab_mur_x[i] = tile_size / tan(rad_i); + if (tab_mur_x[i] > 0) { + tab_mur_x[i] = -tab_mur_x[i]; + } + } + else { + tab_mur_x[i] = tile_size / tan(rad_i); + if (tab_mur_x[i] < 0) { + tab_mur_x[i] = -tab_mur_x[i]; + } + } + if (i >= 0 && i < angle_180) { + tab_mur_y[i] = tile_size / tan(rad_i); + if (tab_mur_y[i] < 0) { + tab_mur_y[i] = -tab_mur_y[i]; + } + } + else { + tab_mur_y[i] = tile_size / tan(rad_i); + if (tab_mur_y[i] > 0) { + tab_mur_y[i] = -tab_mur_y[i]; + } + } + i++; + } + for (i = -30; i <= angle_30;) { + distors_table[i + angle_30] = floor(128*(1 / cos(deg_to_rad(i)))); + i++; + } +} + +void load_map(int){ + +} + +void draw_background(int){ + +} + + +void draw_walls(){ + int vertical_grid = 0; + int horizontal_grid = 0; + int dist_to_n_v_grid = 0; //distance to next vertical grid + int dist_to_n_h_grid = 0; + int x_intersect = 0; + int y_intersect = 0; + float dist_to_n_x_intersect = 0; + float dist_to_n_y_intersect = 0; + int x_raypos = 0; + int y_raypos = 0; + int dist_to_v_hit = 0; + int dist_to_h_hit = 0; + int castarc = 0; + int castcolumn = 0; + int wall_haut = 0; + int wall_bas = 0; + int half_viewport_h = viewport_h * 0.5; //Va y avoir besoin quand je vais + //réduire par deux la résolution horizontale du bouzin + int rgh_xdist = 1; + int rgh_ydist = 1; + int couleur = 0; + char wall_type = 1; //type de mur touché par le raycast + int wall_dist = 0; + int proj_wall_h = 0; + double wall_temp = 0; + extern int angle_30;//il y en a peut être des inutilisés, a voir + extern int angle_15; + extern int angle_90; + extern int angle_180; + extern int angle_270; + extern int angle_360; + extern int angle_5; + extern int angle_10; + extern int angle_45; + extern int cos_table[ang_360p]; + extern int sin_table[ang_360p]; + extern int tan_table[ang_360p]; + extern int acos_table[ang_360p]; + extern int asin_table[ang_360p]; + extern int atan_table[ang_360p]; + extern float tab_mur_x[ang_360p]; + extern float tab_mur_y[ang_360p]; + extern int distors_table[ang_360p]; + extern int player_x; + extern int player_y; + extern int player_dir; + extern char map_test[map_w][map_h]; + //Note : les dupdate() et dprint() en masse sont pour le debug + + castarc = player_dir - angle_30; + if (castarc < 0) { + castarc += angle_360; + } + if (castarc >= angle_360) { + castarc -= angle_360; + } + + for ( castcolumn = 0; castcolumn < viewport_w;) { + + dprint( 1, 1, C_BLACK, "castcolumn : %d", castcolumn); + dprint( 1, 10, C_BLACK, "castarc : %d", castarc); + + if (castarc > 0 && castarc < angle_180) { + horizontal_grid = floor(player_y / tile_size) * tile_size + tile_size; + dist_to_n_h_grid = tile_size; + x_intersect = floor((atan_table[castarc] * (horizontal_grid - player_y)) >> 6) + player_x; + + dprint( 1, 20, C_BLACK, "x_intersect : %d", x_intersect); + } + else { + horizontal_grid = floor(player_y / tile_size) * tile_size; + dist_to_n_h_grid = -tile_size; + x_intersect = floor((atan_table[castarc] * (horizontal_grid - player_y)) >> 6) + player_x; + horizontal_grid--; + + dprint( 1, 20, C_BLACK, "x_intersect : %d", x_intersect); + } + + if (castarc == 0 || castarc == angle_180) { + dist_to_h_hit = max_dist; + dprint( 1, 100, C_BLACK, "x_0/180"); + } + else { + dist_to_n_x_intersect = tab_mur_x[castarc]; + while (true) { + x_raypos = floor(x_intersect / tile_size); + y_raypos = floor(horizontal_grid / tile_size); + //rgh_xdist = abs(x_raypos - (tile_size * player_x)); + //rgh_ydist = abs(y_raypos- (tile_size * player_y)); + //Gros truc bien long pour vérifier que le rayon est pas trop loin + //Note : Si je remplace le <= par < avec les raypos, ça plante :/ + if (x_raypos >= map_w || y_raypos >= map_h || x_raypos <= 0 || y_raypos <= 0 + || rgh_xdist > max_dist || rgh_ydist > max_dist) { + dist_to_h_hit = max_dist; + + dprint( 200, 1, C_BLACK, "H : Max_dist"); + break; + } + else if (map_test[x_raypos][y_raypos] == 0) { + x_intersect += dist_to_n_x_intersect; + horizontal_grid += dist_to_n_h_grid; + } + else { + dist_to_h_hit = floor(((x_intersect - player_x) * acos_table[castarc]) >> 6); + wall_type = map_test[x_raypos][y_raypos]; + + dprint( 200, 10, C_BLACK, "H : Hit"); + dprint( 200, 20, C_BLACK, "x_intersect : %d", x_intersect); + dprint( 200, 30, C_BLACK, "horizontal_grid : %d", horizontal_grid); + dprint( 200, 40, C_BLACK, "wall_type : %d", wall_type); + + break; + } + } + + dprint( 1, 30, C_BLACK, "dist_to_h_hit : %d", dist_to_h_hit); + } + + if (castarc < angle_90 || castarc > angle_270) { + vertical_grid = tile_size + floor(player_x / tile_size) * tile_size; + dist_to_n_v_grid = tile_size; + y_intersect = floor((tan_table[castarc] * (vertical_grid - player_x)) >> 6 ) + player_y; + + dprint( 1, 40, C_BLACK, "y_intersect : %d", y_intersect); + } + else { + vertical_grid = floor(player_x / tile_size * tile_size); + dist_to_n_v_grid = -tile_size; + y_intersect = floor((tan_table[castarc] * (vertical_grid - player_x)) >> 6 ) + player_y; + vertical_grid--; + + dprint( 1, 40, C_BLACK, "y_intersect : %d", y_intersect); + } + + if (castarc == angle_90 || castarc == angle_270) { + dist_to_v_hit = max_dist; + dprint( 1, 80, C_BLACK, "y_90/270"); + } + else { + dist_to_n_y_intersect = tab_mur_y[castarc]; + while (true) { + x_raypos = floor(vertical_grid / tile_size); + y_raypos = floor(y_intersect / tile_size); + //rgh_xdist = abs(x_raypos - (tile_size * player_x)); + //rgh_ydist = abs(y_raypos - (tile_size * player_y)); + if (x_raypos >= map_w || y_raypos >= map_h || x_raypos <= 0 || y_raypos <= 0 + || rgh_xdist > max_dist || rgh_ydist > max_dist) { + dist_to_h_hit = max_dist; + + dprint( 200, 50, C_BLACK, "V : Max_dist"); + break; + } + else if (map_test[x_raypos][y_raypos] == 0) { + y_intersect += dist_to_n_y_intersect; + horizontal_grid += dist_to_n_h_grid; + } + else { + dist_to_v_hit = floor(((x_intersect - player_x) * acos_table[castarc]) >> 6); + wall_type = map_test[x_raypos][y_raypos]; + + dprint( 200, 60, C_BLACK, "V : Hit"); + dprint( 200, 70, C_BLACK, "y_intersect : %d", y_intersect); + dprint( 200, 80, C_BLACK, "horizontal_grid : %d", horizontal_grid); + dprint( 200, 90, C_BLACK, "wall_type : %d", wall_type); + break; + } + } + dprint( 1, 50, C_BLACK, "dist_to_v_hit : %d", dist_to_v_hit); + } + if (dist_to_h_hit <= dist_to_v_hit) { + wall_dist = dist_to_h_hit; + } + else { + wall_dist = dist_to_v_hit; + } + wall_temp = floor(wall_dist / distors_table[castcolumn]); + wall_dist = wall_temp; + wall_dist = wall_dist >> 7; + dprint( 1, 60, C_BLACK, "wall_dist : %d", wall_dist); + + if (wall_dist >= max_dist){ + wall_dist = max_dist; //devrait pas y en avoir besoin mais bon + } + if (wall_dist == 0){ + wall_dist += 1; + } + + proj_wall_h = floor((tile_size * player_pj_pl_dist / wall_dist)*0.5); + if (proj_wall_h >= half_viewport_h){ + proj_wall_h = half_viewport_h; + } + wall_bas = half_viewport_h - proj_wall_h; + wall_haut = half_viewport_h + proj_wall_h; + if (wall_haut < 0) { + wall_haut = 0; + } + if (wall_bas >= viewport_h) { + wall_bas = viewport_h - 1; + } + + wall_bas = (wall_bas - wall_haut) + 1; + /* + if (floor(wall_dist) < max_dist) { + couleur = floor(255 - (wall_dist / max_dist) * 255)-20; + if (couleur <= 0) { + couleur = 0; + } + if (couleur > 235) { + couleur = 235; + } + /* + switch (wall_type) { + case 1: { + drect(castcolumn, wall_haut, castcolumn, wall_bas, wall_color); + break; + } + case 2: { + drect(castcolumn, wall_haut, castcolumn, wall_bas, 0xFAFA); + break; + } + } + */ /* + drect( castcolumn, wall_haut, castcolumn, wall_bas, 0xAAAA); //nrmlnt : table_couleur[couleur] + } + else { + drect( castcolumn, wall_haut, castcolumn, wall_bas, 0x5ACB); + } + */ + dupdate(); + getkey(); + dclear(C_WHITE); + + castarc++; + castcolumn++; + if (castarc >= angle_360) { + castarc -= angle_360; + } + } +} diff --git a/src/fixed.h b/src/fixed.h new file mode 100644 index 0000000..7818697 --- /dev/null +++ b/src/fixed.h @@ -0,0 +1,87 @@ +//--- +// fixed: 16:16 fixed-point arithmetic +//--- +//vient de https://gitea.planet-casio.com/Slyvtt/OutRun/src/branch/master/src +// +#pragma once +#include + +typedef int32_t fixed_t; +/* Standard arithmetic. */ + +static inline fixed_t fmul(fixed_t left, fixed_t right) +{ + /* Generally optimized by the compiler to use dmuls.l and xtrct */ + int64_t p = (int64_t)left * (int64_t)right; + return (int32_t)(p >> 16); +} + +static inline fixed_t fdiv(fixed_t left, fixed_t right) +{ + /* Pretty slow */ + int64_t d = (int64_t)left << 16; + return d / right; +} + +#define fix(x) ((int)((x) * 65536)) + +static inline fixed_t fixdouble(double constant) +{ + return (fixed_t)(constant * 65536); +} + +static inline fixed_t fixfloat(float constant) +{ + return (fixed_t)(constant * 65536); +} + +static inline fixed_t fdec(fixed_t f) +{ + return f & 0xffff; +} + +static inline int ffloor(fixed_t f) +{ + return f >> 16; +} + +static inline int fceil(fixed_t f) +{ + return (f + 0xffff) >> 16; +} + +static inline int fround(fixed_t f) +{ + return (f + 0x8000) >> 16; +} + +static inline float f2float(fixed_t f) +{ + return (float)f / 65536; +} + +static inline double f2double(fixed_t f) +{ + return (double)f / 65536; +} + +static inline double f2int(fixed_t f) +{ + return (int)f / 65536; +} + +static inline fixed_t feasein(fixed_t x) +{ + return fmul(x, x); +} + +static inline fixed_t fease(fixed_t x) +{ + if(x <= fix(0.5)) { + return 2 * fmul(x, x); + } + else { + x = fix(1) - x; + return fix(1) - 2 * fmul(x, x); + } +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..fc4f118 --- /dev/null +++ b/src/main.c @@ -0,0 +1,210 @@ +#include +#include + +#include +#include +#include +#include + +#define USB + +#ifdef USB +#include +#include +#endif + +#include "fixed.h" + +#include "moteur.h" +#include "map_test.h" +#include "sprites.h" + +//====== Maze3D V0.2 ===== +// Git du moteur : https://github.com/attilavs2/Raycaster_prealpha +// Git du jeu : [a venir] +// +// Tout le code de cette version est en GPL3 +// Game design : Fcalva (aka. fklv, Fcalva#6860, attilavs2) +// Programmation : Fcalva +// "Art" : Fcalva +// +// +// TODO : +// -Écran de fin : +// *-Affichage du temps mis +// -Graphismes de fin +// -Finir le labyrinthe +// *-Compteur de temps +// +// + +#ifndef FXCG50 +#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 + +extern char map_test[map_w][map_h]; + +extern image_t briques0; +extern image_t buisson0; + +char exit_game = 0; +char disp_frame_time = 0; +char first_frame = 1; +int frame_time_timer = 1; +int capture_timer = 1; + +fixed_t posX; +fixed_t posY; +fixed_t dirX; +fixed_t dirY; +fixed_t planeX; +fixed_t planeY; + +int frame_time = 0; +int a; + +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; + + #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, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1); + + dtext( 1, 1, C_BLACK, "Version BETA"); + + dupdate(); + getkey(); +} + +void end_screen(){ + 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(); + + while(true){ + a = getkey().key; + if (a == KEY_OPTN) { + load_map(); + break; + } + } +} + +int main(){ + dclear(C_WHITE); + + //trucs de chargement + + load_map(); + + image_t frame_buffer = *image_alloc(viewport_w, viewport_h, IMAGE_RGB565A); + + 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); + + 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); + + prof_init(); + + #ifdef USB + usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL}; + usb_open(interfaces, GINT_CALL_NULL); + #endif + + posX = fix(13); posY = fix(111); + + + while (exit_game == 0) { + prof_t frame = prof_make(); + prof_enter(frame); + + drect(0, 0, 395, 112, 0x9dbd); + drect(0,112, 395, 243, 0xc4c9); + + image_clear(&frame_buffer); + + draw_walls(&buisson0, &briques0, &sky_tex, &WXOR_tex, &D_tex, &frame_buffer); + + dimage(0, 0, &frame_buffer); + + if(first_frame == 1) main_menu(); + + keys_get(); + + logic(&frame_buffer, &D_tex); + + if (disp_frame_time == 1) dprint( 1, 10, C_BLACK, "Frame time : %d ms", frame_time); + + #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 + + dupdate(); + prof_leave(frame); + frame_time = (int)prof_time(frame)/1000; + first_frame = 0; + } + + prof_quit(); + usb_close(); + + free(&sky_tex); + free(&WXOR_tex); + free(&D_tex); + free(&frame_buffer); + + return 1; +} \ No newline at end of file diff --git a/src/map_test.c b/src/map_test.c new file mode 100644 index 0000000..47cc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0,0,1}, + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} +}; \ No newline at end of file diff --git a/src/map_test.h b/src/map_test.h new file mode 100644 index 0000000..4dd08f5 --- /dev/null +++ b/src/map_test.h @@ -0,0 +1,10 @@ +#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 new file mode 100644 index 0000000..c01a28b --- /dev/null +++ b/src/moteur.c @@ -0,0 +1,610 @@ +#include +#include +#include +#include + +#include +#include + +#include "fixed.h" + +#include "moteur.h" +#include "sprites.h" +#include "map_test.h" + +// moteur.c : +// ici se trouvent tout ce qui concerne les graphismes, mouvement et collisions +// +// + +void move() { + extern int frame_time; + fixed_t moveSpeed = fmul(fix(frame_time), 0x148); //frame_time * fix(carrés/seconde/1000) là carrés/seconde = 5 + fixed_t rotSpeed = fmul(fix(frame_time), 0x83); //frame_time * fix(radians/seconde/1000) là radians/seconde = 2 + fixed_t c_rotSpeed = fix(cos(f2float(rotSpeed))); + fixed_t s_rotSpeed = fix(sin(f2float(rotSpeed))); + + extern char map_test[map_w][map_h]; + extern fixed_t planeX; + extern fixed_t planeY; + extern fixed_t dirX; + extern fixed_t dirY; + extern fixed_t posX; + extern fixed_t posY; + + fixed_t oldDirX; + fixed_t oldPlaneX; + int xtemp1; + int ytemp1; + int xtemp2; + int ytemp2; + + pollevent(); + + if (keydown(KEY_UP)) { + xtemp1 = f2int(posX + fmul(dirX, 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); + } + //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)); + + if(map_test[xtemp1][ytemp1] == 0) posX -= fmul(dirX, moveSpeed); + if(map_test[xtemp2][ytemp2] == 0) posY -= fmul(dirY, moveSpeed); + } + //rotate to the rightdouble sin_rotspeed; + if (keydown(KEY_RIGHT)) { + //both camera direction and camera plane must be rotated + 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); + planeY = (fmul(oldPlaneX, -s_rotSpeed)+1) + (fmul(planeY, c_rotSpeed)+1); + } + //rotate to the left + if (keydown(KEY_LEFT)) { + //both camera direction and camera plane must be rotated + 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); + planeY = (fmul(oldPlaneX, s_rotSpeed)+1) + (fmul(planeY, c_rotSpeed) + 1); + } + + if (dirX > 0xFFFF) dirX = 0xFFFF; + if (dirY > 0xFFFF) dirY = 0xFFFF; + if (dirX < -0xFFFF) dirX = -0xFFFF; + if (dirY < -0xFFFF) dirY = -0xFFFF; +} + +void draw_background(int background_id, image_t *skybox, image_t *skyboxSlice0, image_t *skyboxSlice1, image_t *frame_buffer){ //a revoir + extern fixed_t dirX; + + switch (background_id){ + default: { + break; + } + case 0: { + break; + } + case 1: { + int slice0_X = ffloor((dirX + 0xFFFF) * 450); + + image_clear(skyboxSlice0); + image_clear(skyboxSlice1); + skyboxSlice0 = image_sub(skybox, slice0_X, 0, viewport_w, (int)(viewport_h * 0.5)); + image_copy(skyboxSlice0, frame_buffer, true); + /* + if (slice0_X + viewport_h > 899){ + int slice1_X = 899 - slice0_X + viewport_w; + + skyboxSlice0 = image_sub(skybox, slice0_X, 0, viewport_w - slice1_X, (int)(viewport_h * 0.5)); + skyboxSlice1 = image_sub(skybox, 0, 0, slice1_X, (int)(viewport_h * 0.5)); + + image_copy(skyboxSlice1, image_at(frame_buffer, 0, 0), true); + image_copy(skyboxSlice0, image_at(frame_buffer, -(slice1_X - viewport_w), 0), true); + } + else { + + }*/ + break; + } + } +} + +void logic(image_t *frame_buffer, image_t *D_tex){ + extern fixed_t posX; + extern fixed_t posY; + + if (ffloor(posX) == 15 && ffloor(posY) == 113) { + end_screen(); + } +} + +void load_map(){ + dtext( 1, 1, C_BLACK, "Chargement..."); + dupdate(); + spawn_gen(); +} + +void spawn_gen(){ + 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 char map_test[map_w][map_h]; + + int seed, seed_x, seed_y; + int SeedSeed; + + time_t timeN; + time(&timeN); + SeedSeed = timeN; + + srand(SeedSeed); + + while(true){ + seed = rand() * 0.5 + rand() * 0.5; + seed_x = seed & 0b00000000000000000000000001111111; + seed_y = (seed >> 8) & 0b00000000000000000000000000111111; + 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) & 0b00000000000000000000000000000011 ; + 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 + dirX = start_dirX; + dirY = start_dirY; //initial direction vector +} + +void draw_f(image_t *floor_tex, image_t *frame_buffer){ //a refaire + extern fixed_t posX; + extern fixed_t posY; + extern fixed_t dirX; + extern fixed_t dirY; + extern fixed_t planeX; + extern fixed_t planeY; + + int x; + int y; + + for (y = 0; y < viewport_h; y++){ + fixed_t rayDirX0 = dirX - planeX; + fixed_t rayDirY0 = dirY - planeY; + fixed_t rayDirX1 = dirX + planeX; + fixed_t rayDirY1 = dirY + planeY; + + int p = y - (int) (viewport_h * 0.5); + + fixed_t posZ = fmul(fix(0.5), fix(viewport_h)); + + fixed_t rowDist = fdiv(posZ, fix(p)); + + fixed_t floorStepX = fdiv(fmul(rowDist, (rayDirX1 - rayDirX0)), viewport_w); + fixed_t floorStepY = fdiv(fmul(rowDist, (rayDirY1 - rayDirY0)), viewport_w); + + fixed_t floorX = posX + fmul(rowDist, rayDirX0); + fixed_t floorY = posY + fmul(rowDist, rayDirY0); + + for (x = 0; x < viewport_w; ++x){ + int cellX = f2int(floorX); + int cellY = f2int(floorY); + + int tx = (int)ffloor(64 * (floorX - cellX)) & 63; + int ty = (int)ffloor(64 * (floorX - cellX)) & 63; + + floorX += floorStepX; + floorY += floorStepY; + + unsigned short color = image_get_pixel(floor_tex, tx, ty); + //color = (color >> 1) & 0b0111111101111111; + image_set_pixel(frame_buffer, x, viewport_h - y - 1, color); + } + } + +} + +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){ + 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 char map_test[map_w][map_h]; + + unsigned short color; + fixed_t cameraX; + fixed_t rayDirX; + fixed_t rayDirY; + fixed_t sideDistX;//length of ray from current position to next x or y-side + fixed_t sideDistY; + fixed_t deltaDistX; + fixed_t deltaDistY; + fixed_t perpWallDist; + fixed_t texSize; + int x; + int mapX; + int mapY; + int stepX; //what direction to step in x or y-direction (either +1 or -1) + int stepY; + int hit = 0; //was there a wall hit? + int side; //was a NS or a EW wall hit? + int lineHeight; + int texX; + int texSample; + int texSampleY; + + int v_offset = 0; //(int)(sin(f2int(posX + posY)) * 5); //a raffiner un peu + fixed_t h_offset = 0; //fix(sin(f2int(posX - posY)) * 0.01); + + struct image_linear_map temp; + + for(x = 0; x < viewport_w; x++) { + + //calculate ray position and direction + cameraX = fdiv(fix(x*2), fix(viewport_w)) - 0xFFFF + h_offset; //x-coordinate in camera space + + rayDirX = dirX + fmul(planeX, cameraX); + rayDirY = dirY + fmul(planeY, cameraX); + + + //which box of the map we're in + mapX = f2int(posX); + mapY = f2int(posY); + + // length of ray from one x or y-side to next x or y-side + // these are derived as: + // deltaDistX = sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX)) + // deltaDistY = sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY)) + // which can be simplified to abs(|rayDir| / rayDirX) and abs(|rayDir| / rayDirY) + // where |rayDir| is the length of the vector (rayDirX, rayDirY). Its length, + // unlike (dirX, dirY) is not 1, however this does not matter, only the + // ratio between deltaDistX and deltaDistY matters, due to the way the DDA + // stepping further below works. So the values can be computed as below. + // Division through zero is prevented, even though technically that's not + // needed in C++ with IEEE 754 floating point values. + // Fcalva : removed the 0 div prevention + + deltaDistX = abs(fdiv(0xFFFF, rayDirX)); + deltaDistY = abs(fdiv(0xFFFF, rayDirY)); + + //calculate step and initial sideDist + if (rayDirX <= 0) { + stepX = -1; //true + sideDistX = fmul(posX - fix(mapX), deltaDistX); + } + else { + stepX = 1; + sideDistX = fmul( fix(mapX + 1) - posX, deltaDistX); + } + + if (rayDirY <= 0) { + stepY = -1; //true + sideDistY = fmul(posY - fix(mapY), deltaDistY); + } + else { + stepY = 1; + sideDistY = fmul( fix(mapY + 1) - posY, deltaDistY); + } + //perform DDA + while(true) { + //Check if the ray is out of range/bounds + if (sideDistX >= max_dist || sideDistY >= max_dist || mapX < 0 || mapY < 0 || mapX >= map_w || mapY >= map_h) { + hit = 0; + break; + } + //Otherwise check if ray has hit a wall + else if (map_test[mapX][mapY] != 0) { + hit = 1; + break; + } + //jump to next map square, either in x-direction, or in y-direction + if (sideDistX < sideDistY) { + sideDistX += deltaDistX; + mapX += stepX; + side = 0; + } + else { + sideDistY += deltaDistY; + mapY += stepY; + side = 1; + } + } + //Calculate distance projected on camera direction. This is the shortest distance from the point where the wall is + //hit to the camera plane. Euclidean to center camera point would give fisheye effect! + //This can be computed as (mapX - posX + (1 - stepX) / 2) / rayDirX for side == 0, or same formula with Y + //for size == 1, but can be simplified to the code below thanks to how sideDist and deltaDist are computed: + //because they were left scaled to |rayDir|. sideDist is the entire length of the ray above after the multiple + //steps, but we subtract deltaDist once because one step more into the wall was taken above. + + if (side == 0) perpWallDist = (sideDistX - deltaDistX); + else perpWallDist = (sideDistY - deltaDistY); + + //texturing calculations + //int texNum = test_map[mapX][mapY] - 1; //a voir plus tard + + //calculate value of wallX + fixed_t wallX; //where exactly the wall was hit + if (side == 0) wallX = posY + fmul(perpWallDist, rayDirY); + else wallX = posX + fmul(perpWallDist, rayDirX); + wallX -= fix(floor(f2int(wallX))); + + //x coordinate on the texture + texX = fmul(wallX, 64); + while(texX >= 64 || texX < 0){ + if(texX >= 64) texX -= 64; + if(texX < 0) texX += 64; + } + if(side == 0 && rayDirX > 0) texX = 64 - texX - 1; + if(side == 1 && rayDirY < 0) texX = 64 - texX - 1; + + lineHeight = f2int(fdiv(fix(viewport_h), perpWallDist)); //Taille en px de la ligne + if (lineHeight < 1) lineHeight = 1; + if (lineHeight > viewport_h) lineHeight = viewport_h - 1; + + fixed_t texSize = fix(lineHeight) / 64; //taille proportionelle de la ligne a la tex + if (texSize < 0x400) texSize = 0x400; //0x400 = 1/64 * 2^16 + if (texSize > 0x3D000) { //0x3D000 = 3.8125 * 2^16, 3.8125 = viewport_h/64 + texSample = ffloor(fdiv(fix(viewport_h), texSize)); + texSampleY = 32 - (int)texSample * 0.5; + } + else { + texSample = 64; + texSampleY = 0; + } + + 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; + } + + image_scale(&texStripe, 0xFFFF, texSize, &temp); + temp.src_stride = 1; + temp.dst_stride = 1; + image_linear(&texStripe, image_at(frame_buffer, x, (int)(viewport_h * 0.5 - lineHeight * 0.5) + v_offset), &temp); + } +} + +//Function using the same raycast logic returning distance (and without the same comments) +//Returns -1 if it didn't hit anything, -2 if incorrect type input +// ! a tester ! + +fixed_t raycast(fixed_t posX, fixed_t posY, fixed_t rayDirX, fixed_t rayDirY, fixed_t dist, char type){ + extern char map_test[map_w][map_h]; + extern char mob_index[map_w][map_h]; + + fixed_t sideDistX; + fixed_t sideDistY; + fixed_t deltaDistX; + fixed_t deltaDistY; + fixed_t wallDist; + + char side; + + int mapX; + int mapY; + int stepX; + + int stepY; + int hit = 0; + + mapX = f2int(posX); + mapY = f2int(posY); + + deltaDistX = abs(fdiv(0xFFFF, rayDirX)); + deltaDistY = abs(fdiv(0xFFFF, rayDirY)); + + if (rayDirX <= 0) { + stepX = -1; + sideDistX = fmul(posX - fix(mapX), deltaDistX); + } + else { + stepX = 1; + sideDistX = fmul( fix(mapX + 1) - posX, deltaDistX); + } + + if (rayDirY <= 0) { + stepY = -1; + sideDistY = fmul(posY - fix(mapY), deltaDistY); + } + else { + stepY = 1; + sideDistY = fmul( fix(mapY + 1) - posY, deltaDistY); + } + //perform DDA + switch(type){ + //Walls and mobs raycast + case 0 : { + while(true) { + //Check if the ray is out of range/bounds + if (sideDistX >= dist || sideDistY >= dist || mapX < 0 || mapY < 0) { + hit = 0; + break; + } + //Otherwise check if ray has hit a wall/mob + else if (map_test[mapX][mapY] != 0 || mob_index[mapX][mapY] != 0) { + hit = 1; + break; + } + if (sideDistX < sideDistY) { + sideDistX += deltaDistX; + mapX += stepX; + side = 0; + } + else { + sideDistY += deltaDistY; + mapY += stepY; + side = 1; + } + + } + break; + } + //Mobs only + case 1 : { + while(true) { + //Check if the ray is out of range/bounds + if (sideDistX >= dist || sideDistY >= dist || mapX < 0 || mapY < 0) { + hit = 0; + break; + } + //Otherwise check if ray has hit a wall/mob + else if (map_test[mapX][mapY] != 0) { + hit = 1; + break; + } + if (sideDistX < sideDistY) { + sideDistX += deltaDistX; + mapX += stepX; + side = 0; + } + else { + sideDistY += deltaDistY; + mapY += stepY; + side = 1; + } + } + break; + } + //Walls only + case 2 : { + while(true) { + //Check if the ray is out of range/bounds + if (sideDistX >= dist || sideDistY >= dist || mapX < 0 || mapY < 0) { + hit = 0; + break; + } + //Otherwise check if ray has hit a wall/mob + else if (mob_index[mapX][mapY] != 0) { + hit = 1; + break; + } + if (sideDistX < sideDistY) { + sideDistX += deltaDistX; + mapX += stepX; + side = 0; + } + else { + sideDistY += deltaDistY; + mapY += stepY; + side = 1; + } + } + break; + } + default : { + return -2; + break; + } + } + + if (hit == 0) wallDist = -1; + else if (side == 0) wallDist = (sideDistX - deltaDistX); + else wallDist = (sideDistY - deltaDistY); + + return wallDist; +} + + + + +// Je garde le bout en dessous pour des raisons (date d'avant la V 0.1.1) +//Problèmes : +//-L'affichage est très mauvais, a revoir +//-Le mouvement de la caméra ne marche pas +// +//A rajouter d'ici le 27 : +//-Que ça marche (logique) +// -collisions +// -Sol +// -Gestion de plusieurs maps +// -Interaction (Portes/boutons) +// -Textures +// -Sprites +// -PNJs ( a voir selon le théme) +// -Extérieur/intérieur (très probablement mais a voir selon le thème) +//La suite dépend surtout de ce qui aura été fait et du thème +//Avec le thème, maintenant il faudrait : +//-collisions +// -sol +// -Des bouts de map reliés entre eux +// -Sprites (ennemis + ambiance dans un second temps) +// -map générées aléatoirement +// -textures +// -Gameplay +// -PNJs +// -Sans de undertale (me demandez pas pourquoi, c'est un mec sur discord qui a propos�) +// +//================================================ +// au 03/06 : +// A faire là tout de suite : +// - Bien réparer correctement les murs +// - Sprites +// Plan : +// -Sol +// -Ennemis +// -Maps +// -Textures +// diff --git a/src/moteur.h b/src/moteur.h new file mode 100644 index 0000000..be7b0ae --- /dev/null +++ b/src/moteur.h @@ -0,0 +1,22 @@ +#ifndef moteur_h +#define moteur_h + +#include + +#define pi 3.1415 + +//param. graphiques +#define screen_w 396 +#define screen_h 224 +#define viewport_w 396 +#define viewport_h 224 +#define max_dist 0x1FFFFF //en tuiles << 16, actuellement 32 + +void draw_background(int, image_t*, image_t*, image_t*, image_t*); +void load_map(); +void logic(image_t*, image_t*); +void draw_f(image_t*, image_t*); +void draw_walls(image_t*, image_t*, image_t*, image_t*, image_t*, image_t*); +void move(); + +#endif /* moteur */ \ No newline at end of file diff --git a/src/sprites.c b/src/sprites.c new file mode 100644 index 0000000..f1f5318 --- /dev/null +++ b/src/sprites.c @@ -0,0 +1,74 @@ +#include +#include + +#include +#include +#include + +#include "fixed.h" + +#include "map_test.h" +#include "sprites.h" +#include "moteur.h" + +// 2 maps de sprites : Les sprites de la map (tonneaux, torches, cadavres...) qui vont être dans +// map_test.c dans le futur proche et dans les données tiled plus tard +// Et les sprites de PNJs, donc d'ennemis et amicaux si jamais il y en a, qui vont être +// répertoriés dans un tableau de structs, leur place dans le tableau étant leur ID +// le mob_index sert a garder une position plus facile a vérifier des mobs, le nombre dans la matrice +// étant leur ID +// + +char mob_index[map_w][map_h] = { + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //13;10 + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +}; //les pnjs (ennemis) + +void draw_sprites() { + // 1 - lister les sprites en render distance + // 2 - vérifier la distance/si c'est derrière un mur + // 3 - trier par distance + // 4 - passage a la moulinette de la perspective de la taille + // 5 - vérifier les recouvrement éventuels + // 6 - dessiner en commençant par derrière +} +/* +void test_sprite(fixed_t scale){ + extern bopti_image_t zombard; + struct image_linear_map temp_lin_map; + + int zombard_2 = image_create(52, 81, IMAGE_RGB565A); + image_scale(&zombard, scale, scale, &temp_lin_map); + zombard_2 = image_linear_alloc(&zombard, &temp_lin_map); + dimage(100, 100, &zombard_2); +}*/ \ No newline at end of file diff --git a/src/sprites.h b/src/sprites.h new file mode 100644 index 0000000..0f71f31 --- /dev/null +++ b/src/sprites.h @@ -0,0 +1,4 @@ +#ifndef sprites +#define sprites + +#endif /* sprites.h */ \ No newline at end of file