Tried out 512px tiles and sprites and they actually look like crap. They just look like bad textures not better painted. With 256 they look nicely pixelated.

This commit is contained in:
Zed A. Shaw 2025-01-25 07:46:57 -05:00
parent d397c02d38
commit 5e6f95513c
42 changed files with 41 additions and 44 deletions

View file

@ -65,8 +65,8 @@ void Raycaster::clear() {
}
void Raycaster::sprite_casting() {
const int textureWidth = $textures.TEXTURE_WIDTH;
const int textureHeight = $textures.TEXTURE_HEIGHT;
const int textureWidth = TEXTURE_WIDTH;
const int textureHeight = TEXTURE_HEIGHT;
// sort sprites from far to close
for(int i = 0; i < $textures.NUM_SPRITES; i++) {
@ -126,7 +126,7 @@ void Raycaster::sprite_casting() {
if(!(transformY > 0 && transformY < ZBuffer[stripe])) break;
}
int texX_end = int(256 * (stripe - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 256;
int texX_end = int(512 * (stripe - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 512;
if(drawStartX < drawEndX && transformY > 0 && transformY < ZBuffer[drawStartX]) {
int vMoveScreen = int(sprite_rec.elevation * -1 / transformY);
@ -136,15 +136,15 @@ void Raycaster::sprite_casting() {
int drawEndY = spriteHeight / 2 + $height / 2 + vMoveScreen;
if(drawEndY >= $height) drawEndY = $height - 1;
int texX = int(256 * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 256;
int texX = int(512 * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 512;
float x = float(drawStartX + RAY_VIEW_X);
float y = float(drawStartY + RAY_VIEW_Y);
float sprite_w = float(spriteWidth) / float(textureWidth);
float sprite_h = float(spriteHeight) / float(textureHeight);
int d = (y - vMoveScreen) * 256 - $height * 128 + spriteHeight * 128;
int texY = ((d * textureHeight) / spriteHeight) / 256;
int d = (y - vMoveScreen) * 512 - $height * 256 + spriteHeight * 256;
int texY = ((d * textureHeight) / spriteHeight) / 512;
sf_sprite->setScale({sprite_w, sprite_h});
sf_sprite->setTextureRect(sf::IntRect({texX, texY}, {texX_end - texX, textureHeight}));
@ -155,8 +155,8 @@ void Raycaster::sprite_casting() {
}
void Raycaster::cast_rays() {
constexpr static const int textureWidth = $textures.TEXTURE_WIDTH;
constexpr static const int textureHeight = $textures.TEXTURE_HEIGHT;
constexpr static const int textureWidth = TEXTURE_WIDTH;
constexpr static const int textureHeight = TEXTURE_HEIGHT;
double perpWallDist;
// WALL CASTING
@ -229,7 +229,7 @@ void Raycaster::cast_rays() {
int drawEnd = lineHeight / 2 + $height / 2 + $pitch;
if(drawEnd >= $height) drawEnd = $height - 1;
auto &texture = $textures.get_texture($map[mapY][mapX] - 1);
auto texture = $textures.get_texture($map[mapY][mapX] - 1);
// calculate value of wallX
double wallX; // where exactly the wall was hit
@ -265,8 +265,8 @@ void Raycaster::cast_rays() {
}
void Raycaster::draw_ceiling_floor() {
constexpr static const int textureWidth = $textures.TEXTURE_WIDTH;
constexpr static const int textureHeight = $textures.TEXTURE_HEIGHT;
constexpr static const int textureWidth = TEXTURE_WIDTH;
constexpr static const int textureHeight = TEXTURE_HEIGHT;
for(int y = $height / 2 + 1; y < $height; ++y) {
// rayDir for leftmost ray (x=0) and rightmost (x = w)
@ -300,6 +300,9 @@ void Raycaster::draw_ceiling_floor() {
float floorX = $posX + rowDistance * rayDirX0;
float floorY = $posY + rowDistance * rayDirY0;
auto floor_texture = (const uint32_t *)$textures.floor.getPixelsPtr();
auto ceiling_texture = (const uint32_t *)$textures.ceiling.getPixelsPtr();
for(int x = 0; x < $width; ++x) {
// the cell coord is simply taken from the int parts of
// floorX and floorY.
@ -319,11 +322,11 @@ void Raycaster::draw_ceiling_floor() {
// floorX cellX to find the texture x/y. How?
// FLOOR
color = $textures.floor[textureWidth * ty + tx];
color = floor_texture[textureWidth * ty + tx];
$pixels[pixcoord(x, y)] = color;
// CEILING
color = $textures.ceiling[textureWidth * ty + tx];
color = ceiling_texture[textureWidth * ty + tx];
$pixels[pixcoord(x, $height - y - 1)] = color;
}
}