diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4b1df4c --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +build: + g++ -g *.cpp -lSDL3 -o wolf diff --git a/jdebug.cpp b/jdebug.cpp index 5cb0d2c..0a7c94f 100644 --- a/jdebug.cpp +++ b/jdebug.cpp @@ -59,6 +59,14 @@ namespace debug newline(); } + void println(const char *label, float value) + { + print(label); + print(" "); + print(value); + newline(); + } + void print(int value) { char temp[20]; diff --git a/main.cpp b/main.cpp index 6f74499..3d53542 100644 --- a/main.cpp +++ b/main.cpp @@ -22,6 +22,7 @@ SDL_Texture *sdl_texture; Uint32 *palette; Uint8 *gif; +Uint8 *spr; Uint8 screen[320*240]; float depth_buffer[320*240]; @@ -105,7 +106,7 @@ void putpd(int x, int y, Uint8 color, float depth) void putps(int x, int y, Uint8 color, float depth) { - if (x<0 || y<0 || x>=320 || y>=240) return; + if (x<0 || y<0 || x>=320 || y>=240 || color==0) return; if (depth_buffer[x+y*320]>=depth) { screen[x+y*320]=color; @@ -429,6 +430,16 @@ int main(int argc, char *argv[]) palette = LoadPalette(buffer); free(buffer); + f = fopen("player1.gif", "rb"); + fseek(f, 0, SEEK_END); + filesize = ftell(f); + fseek(f, 0, SEEK_SET); + buffer = (Uint8*)malloc(filesize); + fread(buffer, filesize, 1, f); + fclose(f); + spr = LoadGif(buffer, &w, &h); + free(buffer); + // [DEBUG] Paleta per al depth buffer //for(int i=0;i<256;++i) palette[i] = (255-i) | ((255-i)<<8) | ((255-i)<<16); @@ -535,7 +546,9 @@ int main(int argc, char *argv[]) const float d = distance(position, enemy);// * SDL_cosf(a_inc*DEG_TO_RAD); float dist = d * SDL_cosf(angle_to_enemy*DEG_TO_RAD); float wall_height = (32.0f*277)/dist; - debug::print("enemy in fov: "); debug::print(angle_to_enemy); debug::newline(); + float wall_start = 120-(wall_height/32.0f)*(32.0f-(height-sectors[0].floor_height)); + debug::println("enemy height: ", wall_height); + debug::println("enemy start: ", wall_start); int column = int((angle_to_enemy+32.0f)/0.2f); for (int i=0; i