- debug::println(char*, float)

- Gràfic del balunet
- Paleta afegida
- sprite en altura correcta
- sprite amb diferent textura
- transparencies en el sprite
- Makefile pa que JDes no haja de fer search en el chat cada volta
This commit is contained in:
2025-09-29 14:16:56 +02:00
parent 8c20e2a6c4
commit 7102535deb
5 changed files with 285 additions and 3 deletions

View File

@@ -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<wall_height;++i)
{
@@ -545,7 +558,7 @@ int main(int argc, char *argv[])
for (int j=0;j<wall_height;++j)
{
int ty = j * 32 / wall_height;
putps(c, 120-(wall_height/2)+j, gif[tx+ty*64], d);
putps(c, wall_start+j, spr[tx+ty*32], d); //120-(wall_height/2)
}
}
}