From: Sam Smith Date: Tue, 10 Nov 2026 18:45:07 +0000 (-0700) Subject: Actual rendering!!!!! X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;ds=sidebyside;p=allbombson%2FPatchyCaster.git Actual rendering!!!!! --- diff --git a/makefile b/makefile new file mode 100644 index 0000000..246189e --- /dev/null +++ b/makefile @@ -0,0 +1,16 @@ +CFLAGS=-Wall -Wextra -Wpedantic -Wstrict-prototypes -Wold-style-definition -std=c89 -pedantic $(shell pkg-config sdl2 --cflags) +LDLIBS=$(shell pkg-config sdl2 --libs) -lm + +VPATH=src +OBJECTS=game.o sdl.o +TARGET=patchycaster + +.PHONY: all clean +all: $(TARGET) +clean: + $(RM) $(TARGET) $(OBJECTS) + +$(TARGET): $(OBJECTS) + $(LINK.c) $(OBJECTS) $(LOADLIBES) $(LDLIBS) -o $(TARGET) +game.o: game.c game.h sdl.h +sdl.o: sdl.c game.h sdl.h diff --git a/src/game.c b/src/game.c index 5607883..a5d8eb9 100644 --- a/src/game.c +++ b/src/game.c @@ -122,6 +122,8 @@ ray *castRay(player *PlayerC, bam bearing) { /* init */ Xray.wall_type = 0; Yray.wall_type = 0; + Xray.distance = 0; + Yray.distance = 0; /* TODO: force texture size to be a power of 2 and then have a macro for * the bits needed to do * and / */ @@ -147,11 +149,13 @@ ray *castRay(player *PlayerC, bam bearing) { while(y/TEXTURE_SIZE >= 0 && y/TEXTURE_SIZE < 10 && x/TEXTURE_SIZE >= 0 && x/TEXTURE_SIZE < 10) { if(map[9-(y/TEXTURE_SIZE)][x/TEXTURE_SIZE] != 0) { - /* TODO: actual fill out properly lol */ Xray.wall_type = map[9-(y/TEXTURE_SIZE)][x/TEXTURE_SIZE]; - setColour(0xff,0xff,0); + /* Debug */ + /* setColour(0xff,0xff,0); drawLine2(PlayerC->x, PlayerC->y, x, y); - setColour(0,0xff,0xff); + setColour(0,0xff,0xff); */ + + Xray.distance = fabs((y-PlayerC->y)/bam_sin(bearing)); break; } y+=dy; @@ -180,11 +184,13 @@ ray *castRay(player *PlayerC, bam bearing) { while(y/TEXTURE_SIZE >= 0 && y/TEXTURE_SIZE < 10 && x/TEXTURE_SIZE >= 0 && x/TEXTURE_SIZE < 10) { if(map[9-(y/TEXTURE_SIZE)][x/TEXTURE_SIZE] != 0) { - /* TODO: actual fill out properly lol */ Yray.wall_type = map[9-(y/TEXTURE_SIZE)][x/TEXTURE_SIZE]; - setColour(0xff,0xff,0); + /* Debug */ + /* setColour(0xff,0xff,0); drawLine2(PlayerC->x, PlayerC->y, x, y); - setColour(0,0xff,0xff); + setColour(0,0xff,0xff); */ + + Yray.distance = fabs((x-PlayerC->x)/bam_cos(bearing)); break; } y+=dy; @@ -192,11 +198,16 @@ ray *castRay(player *PlayerC, bam bearing) { } } - if(Xray.wall_type != 0) { - return &Xray; - } - if(Yray.wall_type != 0) { + if(Xray.wall_type !=0 && Yray.wall_type != 0) { + if (Xray.distance <= Yray.distance) { + return &Xray; + } else { + return &Yray; + } + } else if(Xray.wall_type != 0) { return &Xray; + } else if(Yray.wall_type != 0) { + return &Yray; } return NULL; @@ -205,6 +216,7 @@ ray *castRay(player *PlayerC, bam bearing) { void game_loop(void) { int scanVector = Player.bearing+(FOV/2); int i; + ray *Ray; /* debug */ int x, y; @@ -221,11 +233,10 @@ void game_loop(void) { for (i=0;idistance); } - //scanVector-=FOV/SCREEN_WIDTH; } /* Debug */ diff --git a/src/game.h b/src/game.h index bfa42b8..14b6af0 100644 --- a/src/game.h +++ b/src/game.h @@ -1,6 +1,6 @@ /* TODO: make adjustable */ -//#define SCREEN_WIDTH (320) -//#define SCREEN_HEIGHT (200) +/*#define SCREEN_WIDTH (320)*/ +/*#define SCREEN_HEIGHT (200)*/ #define SCREEN_WIDTH (1280) #define SCREEN_HEIGHT (720) #define TEXTURE_SIZE (64) diff --git a/src/sdl.c b/src/sdl.c index 00d207e..4c3ad11 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -6,12 +6,13 @@ SDL_Renderer *render; int w, h; -int drawLine(int x, int y, int y2) { - return SDL_RenderDrawLine(render, x, y, x, y2); -} int drawLine2(int x, int y, int x2, int y2) { return SDL_RenderDrawLine(render, x, h-y, x2, h-y2); } +int drawLine(int x, int height) { + int startY = (SCREEN_HEIGHT/2)-(height/2); + return drawLine2(x, startY, x, startY+height); +} int setColour(unsigned char r, unsigned char g, unsigned char b) { return SDL_SetRenderDrawColor(render, r,g,b, 255); @@ -23,6 +24,9 @@ int main(int argc, char *argv[]) { SDL_Event event; int quit = 0; + (void)argc; + (void)argv; + game_init(); /* SDL shit */ diff --git a/src/sdl.h b/src/sdl.h index 325afa5..9508c81 100644 --- a/src/sdl.h +++ b/src/sdl.h @@ -1,3 +1,3 @@ -int drawLine(int x, int y, int y2); +int drawLine(int x, int height); int drawLine2(int x, int y, int x2, int y2); int setColour(unsigned char r, unsigned char g, unsigned char b);