diff --git a/assets/armored_knight_1-256.png b/assets/armored_knight_1-256.png new file mode 100644 index 0000000..b8617eb Binary files /dev/null and b/assets/armored_knight_1-256.png differ diff --git a/assets/ceiling_test-256.png b/assets/ceiling_test-256.png new file mode 100644 index 0000000..4bcac90 Binary files /dev/null and b/assets/ceiling_test-256.png differ diff --git a/assets/ceiling_worm-256.png b/assets/ceiling_worm-256.png new file mode 100644 index 0000000..805dafe Binary files /dev/null and b/assets/ceiling_worm-256.png differ diff --git a/assets/cinqueda_1-256.png b/assets/cinqueda_1-256.png new file mode 100644 index 0000000..f40dd84 Binary files /dev/null and b/assets/cinqueda_1-256.png differ diff --git a/assets/config.json b/assets/config.json index 777e0bc..664f6f0 100644 --- a/assets/config.json +++ b/assets/config.json @@ -1,17 +1,17 @@ { "textures": [ - "assets/floor_tile_test-512.png", - "assets/wall_texture_test-512.png", - "assets/ceiling_test-512.png", - "assets/wood_wall-512.png" + "assets/floor_tile_test-256.png", + "assets/wall_texture_test-256.png", + "assets/ceiling_test-256.png", + "assets/wood_wall-256.png" ], "sprites": [ - "assets/armored_knight_1-512.png", - "assets/cinqueda_1-512.png", - "assets/wood_barrel_large-512.png", - "assets/evil_eye_test-512.png", + "assets/armored_knight_1-256.png", + "assets/cinqueda_1-256.png", + "assets/wood_barrel_large-256.png", + "assets/evil_eye_test-256.png", "assets/undead_peasant-256.png" ], - "floor": "assets/floor_tile_test-512.png", - "ceiling": "assets/ceiling_test-512.png" + "floor": "assets/floor_tile_test-256.png", + "ceiling": "assets/ceiling_test-256.png" } diff --git a/assets/evil_eye_test-256.png b/assets/evil_eye_test-256.png new file mode 100644 index 0000000..c6364c3 Binary files /dev/null and b/assets/evil_eye_test-256.png differ diff --git a/assets/floor_tile_test-256.png b/assets/floor_tile_test-256.png new file mode 100644 index 0000000..56a2c5e Binary files /dev/null and b/assets/floor_tile_test-256.png differ diff --git a/assets/undead_peasant-256.png b/assets/undead_peasant-256.png index 10fc965..eed23a3 100644 Binary files a/assets/undead_peasant-256.png and b/assets/undead_peasant-256.png differ diff --git a/assets/wall_texture_test-256.png b/assets/wall_texture_test-256.png new file mode 100644 index 0000000..217c625 Binary files /dev/null and b/assets/wall_texture_test-256.png differ diff --git a/assets/wood_barrel_large-256.png b/assets/wood_barrel_large-256.png new file mode 100644 index 0000000..6cf2732 Binary files /dev/null and b/assets/wood_barrel_large-256.png differ diff --git a/assets/wood_wall-256.png b/assets/wood_wall-256.png new file mode 100644 index 0000000..6851bdc Binary files /dev/null and b/assets/wood_wall-256.png differ diff --git a/constants.hpp b/constants.hpp index b2a140e..6c2b429 100644 --- a/constants.hpp +++ b/constants.hpp @@ -1,7 +1,7 @@ #pragma once -constexpr const int TEXTURE_WIDTH=512; -constexpr const int TEXTURE_HEIGHT=512; +constexpr const int TEXTURE_WIDTH=256; +constexpr const int TEXTURE_HEIGHT=256; constexpr const int RAY_VIEW_WIDTH=960; constexpr const int RAY_VIEW_HEIGHT=720; constexpr const int RAY_VIEW_X=(1280 - RAY_VIEW_WIDTH); diff --git a/raycaster.cpp b/raycaster.cpp index 5ab9f55..e665dca 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -67,6 +67,7 @@ void Raycaster::clear() { void Raycaster::sprite_casting() { const int textureWidth = TEXTURE_WIDTH; const int textureHeight = TEXTURE_HEIGHT; + const int halfHeight = TEXTURE_HEIGHT / 2; // sort sprites from far to close for(int i = 0; i < $textures.NUM_SPRITES; i++) { @@ -126,7 +127,7 @@ void Raycaster::sprite_casting() { if(!(transformY > 0 && transformY < ZBuffer[stripe])) break; } - int texX_end = int(512 * (stripe - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 512; + int texX_end = int(textureWidth * (stripe - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / textureWidth; if(drawStartX < drawEndX && transformY > 0 && transformY < ZBuffer[drawStartX]) { int vMoveScreen = int(sprite_rec.elevation * -1 / transformY); @@ -136,15 +137,15 @@ void Raycaster::sprite_casting() { int drawEndY = spriteHeight / 2 + $height / 2 + vMoveScreen; if(drawEndY >= $height) drawEndY = $height - 1; - int texX = int(512 * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 512; + int texX = int(textureWidth * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / textureWidth; 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) * 512 - $height * 256 + spriteHeight * 256; - int texY = ((d * textureHeight) / spriteHeight) / 512; + int d = (y - vMoveScreen) * textureHeight - $height * halfHeight + spriteHeight * halfHeight; + int texY = ((d * textureHeight) / spriteHeight) / textureHeight; sf_sprite->setScale({sprite_w, sprite_h}); sf_sprite->setTextureRect(sf::IntRect({texX, texY}, {texX_end - texX, textureHeight})); diff --git a/texture.cpp b/texture.cpp index f63d232..4320d72 100644 --- a/texture.cpp +++ b/texture.cpp @@ -25,7 +25,7 @@ void TexturePack::load_textures() { floor = load_image(assets["floor"]); ceiling = load_image(assets["ceiling"]); - sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-512.png"); + sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-256.png"); sprite_texture->setSmooth(false); sf::Sprite* sf_sprite = new sf::Sprite(*sprite_texture); sprites.push_back({4.0, 3.55, 6, sf_sprite, sprite_texture});