diff --git a/assets/armored_knight_1-256.png b/assets/armored_knight_1-256.png deleted file mode 100644 index 673affa..0000000 Binary files a/assets/armored_knight_1-256.png and /dev/null differ diff --git a/assets/armored_knight_1-512.png b/assets/armored_knight_1-512.png new file mode 100644 index 0000000..a8f780a Binary files /dev/null and b/assets/armored_knight_1-512.png differ diff --git a/assets/ceiling_test-256.png b/assets/ceiling_test-256.png deleted file mode 100644 index 8af78f4..0000000 Binary files a/assets/ceiling_test-256.png and /dev/null differ diff --git a/assets/ceiling_test-512.png b/assets/ceiling_test-512.png new file mode 100644 index 0000000..c1ad1f3 Binary files /dev/null and b/assets/ceiling_test-512.png differ diff --git a/assets/ceiling_worm-256.png b/assets/ceiling_worm-256.png deleted file mode 100644 index 805dafe..0000000 Binary files a/assets/ceiling_worm-256.png and /dev/null differ diff --git a/assets/cinqueda_1-512.png b/assets/cinqueda_1-512.png index 58b0da5..772abd2 100644 Binary files a/assets/cinqueda_1-512.png and b/assets/cinqueda_1-512.png differ diff --git a/assets/config.json b/assets/config.json index 1ab6e95..777e0bc 100644 --- a/assets/config.json +++ b/assets/config.json @@ -1,15 +1,17 @@ { "textures": [ - "assets/tile01.png", - "assets/tile16.png", - "assets/tile02.png", - "assets/tile03.png", - "assets/tile05.png", - "assets/tile17.png" + "assets/floor_tile_test-512.png", + "assets/wall_texture_test-512.png", + "assets/ceiling_test-512.png", + "assets/wood_wall-512.png" ], "sprites": [ - "assets/portal.png" + "assets/armored_knight_1-512.png", + "assets/cinqueda_1-512.png", + "assets/wood_barrel_large-512.png", + "assets/evil_eye_test-512.png", + "assets/undead_peasant-256.png" ], - "floor": "assets/tile32.png", - "ceiling": "assets/tile10.png" + "floor": "assets/floor_tile_test-512.png", + "ceiling": "assets/ceiling_test-512.png" } diff --git a/assets/evil_eye_test-256.png b/assets/evil_eye_test-256.png deleted file mode 100644 index c908752..0000000 Binary files a/assets/evil_eye_test-256.png and /dev/null differ diff --git a/assets/evil_eye_test-512.png b/assets/evil_eye_test-512.png new file mode 100644 index 0000000..0c9ee45 Binary files /dev/null and b/assets/evil_eye_test-512.png differ diff --git a/assets/evileye.png b/assets/evileye.png deleted file mode 100644 index 0ffd3b9..0000000 Binary files a/assets/evileye.png and /dev/null differ diff --git a/assets/floor_tile_test-256.png b/assets/floor_tile_test-256.png deleted file mode 100644 index b301fe4..0000000 Binary files a/assets/floor_tile_test-256.png and /dev/null differ diff --git a/assets/floor_tile_test-512.png b/assets/floor_tile_test-512.png new file mode 100644 index 0000000..26df65f Binary files /dev/null and b/assets/floor_tile_test-512.png differ diff --git a/assets/portal.png b/assets/portal.png deleted file mode 100644 index 5aa90ab..0000000 Binary files a/assets/portal.png and /dev/null differ diff --git a/assets/teleporter.png b/assets/teleporter.png deleted file mode 100644 index fe5e362..0000000 Binary files a/assets/teleporter.png and /dev/null differ diff --git a/assets/tile01.png b/assets/tile01.png deleted file mode 100644 index f671782..0000000 Binary files a/assets/tile01.png and /dev/null differ diff --git a/assets/tile02.png b/assets/tile02.png deleted file mode 100644 index af7a2aa..0000000 Binary files a/assets/tile02.png and /dev/null differ diff --git a/assets/tile03.png b/assets/tile03.png deleted file mode 100644 index 5d95c4d..0000000 Binary files a/assets/tile03.png and /dev/null differ diff --git a/assets/tile05.png b/assets/tile05.png deleted file mode 100644 index 5d4c2f9..0000000 Binary files a/assets/tile05.png and /dev/null differ diff --git a/assets/tile06.png b/assets/tile06.png deleted file mode 100644 index 2d6e09b..0000000 Binary files a/assets/tile06.png and /dev/null differ diff --git a/assets/tile07.png b/assets/tile07.png deleted file mode 100644 index c25c2c8..0000000 Binary files a/assets/tile07.png and /dev/null differ diff --git a/assets/tile08.png b/assets/tile08.png deleted file mode 100644 index a3fca51..0000000 Binary files a/assets/tile08.png and /dev/null differ diff --git a/assets/tile09.png b/assets/tile09.png deleted file mode 100644 index d6ce855..0000000 Binary files a/assets/tile09.png and /dev/null differ diff --git a/assets/tile10.png b/assets/tile10.png deleted file mode 100644 index 8af78f4..0000000 Binary files a/assets/tile10.png and /dev/null differ diff --git a/assets/tile11.png b/assets/tile11.png deleted file mode 100644 index cc426e8..0000000 Binary files a/assets/tile11.png and /dev/null differ diff --git a/assets/tile12.png b/assets/tile12.png deleted file mode 100644 index e4b478c..0000000 Binary files a/assets/tile12.png and /dev/null differ diff --git a/assets/tile13.png b/assets/tile13.png deleted file mode 100644 index 997a1b0..0000000 Binary files a/assets/tile13.png and /dev/null differ diff --git a/assets/tile15.png b/assets/tile15.png deleted file mode 100644 index 8263a7d..0000000 Binary files a/assets/tile15.png and /dev/null differ diff --git a/assets/tile16.png b/assets/tile16.png deleted file mode 100644 index d343c2a..0000000 Binary files a/assets/tile16.png and /dev/null differ diff --git a/assets/tile17.png b/assets/tile17.png deleted file mode 100644 index 9199b16..0000000 Binary files a/assets/tile17.png and /dev/null differ diff --git a/assets/tile30.png b/assets/tile30.png deleted file mode 100644 index 891a37d..0000000 Binary files a/assets/tile30.png and /dev/null differ diff --git a/assets/tile31.png b/assets/tile31.png deleted file mode 100644 index c702c42..0000000 Binary files a/assets/tile31.png and /dev/null differ diff --git a/assets/tile32.png b/assets/tile32.png deleted file mode 100644 index b301fe4..0000000 Binary files a/assets/tile32.png and /dev/null differ diff --git a/assets/wall_texture_test-256.png b/assets/wall_texture_test-256.png deleted file mode 100644 index f671782..0000000 Binary files a/assets/wall_texture_test-256.png and /dev/null differ diff --git a/assets/wall_texture_test-512.png b/assets/wall_texture_test-512.png new file mode 100644 index 0000000..e68dd88 Binary files /dev/null and b/assets/wall_texture_test-512.png differ diff --git a/assets/wood_barrel_large-256.png b/assets/wood_barrel_large-256.png deleted file mode 100644 index 2c2efb7..0000000 Binary files a/assets/wood_barrel_large-256.png and /dev/null differ diff --git a/assets/wood_barrel_large-512.png b/assets/wood_barrel_large-512.png new file mode 100644 index 0000000..37b1898 Binary files /dev/null and b/assets/wood_barrel_large-512.png differ diff --git a/assets/wood_wall-256.png b/assets/wood_wall-256.png deleted file mode 100644 index ffdf813..0000000 Binary files a/assets/wood_wall-256.png and /dev/null differ diff --git a/assets/wood_wall-512.png b/assets/wood_wall-512.png new file mode 100644 index 0000000..8924713 Binary files /dev/null and b/assets/wood_wall-512.png differ diff --git a/constants.hpp b/constants.hpp index 6c2b429..b2a140e 100644 --- a/constants.hpp +++ b/constants.hpp @@ -1,7 +1,7 @@ #pragma once -constexpr const int TEXTURE_WIDTH=256; -constexpr const int TEXTURE_HEIGHT=256; +constexpr const int TEXTURE_WIDTH=512; +constexpr const int TEXTURE_HEIGHT=512; 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 2f5a775..5ab9f55 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -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; } } diff --git a/texture.cpp b/texture.cpp index 22e5fa4..f63d232 100644 --- a/texture.cpp +++ b/texture.cpp @@ -3,16 +3,12 @@ #include "dbc.hpp" #include #include "config.hpp" +#include "constants.hpp" -Image TexturePack::load_image(std::string filename) { - Image texture(TEXTURE_WIDTH * TEXTURE_HEIGHT); - sf::Image img; - bool good = img.loadFromFile(filename); +sf::Image TexturePack::load_image(std::string filename) { + sf::Image texture; + bool good = texture.loadFromFile(filename); dbc::check(good, fmt::format("failed to load {}", filename)); - - uint32_t *pixbuf = (uint32_t *)img.getPixelsPtr(); - std::copy_n(pixbuf, texture.size(), texture.begin()); - return texture; } @@ -29,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-256.png"); + sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-512.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}); @@ -39,8 +35,8 @@ void TexturePack::load_textures() { sword.sprite = new sf::Sprite(*sword.sprite_texture); } -Image& TexturePack::get_texture(size_t num) { - return images[num]; +const uint32_t* TexturePack::get_texture(size_t num) { + return (const uint32_t *)images[num].getPixelsPtr(); } Sprite &TexturePack::get_sprite(size_t sprite_num) { diff --git a/texture.hpp b/texture.hpp index fa651ac..eec6c45 100644 --- a/texture.hpp +++ b/texture.hpp @@ -17,21 +17,17 @@ struct Sprite { int vDiv=1; }; -using Image = std::vector; - struct TexturePack { int NUM_SPRITES=1; - constexpr static const int TEXTURE_WIDTH=256; // must be power of two - constexpr static const int TEXTURE_HEIGHT=256; // must be power of two - std::vector images; + std::vector images; std::vector sprites; - Image floor; - Image ceiling; + sf::Image floor; + sf::Image ceiling; Sprite sword; void load_textures(); - std::vector load_image(std::string filename); + sf::Image load_image(std::string filename); Sprite& get_sprite(size_t sprite_num); - Image& get_texture(size_t num); + const uint32_t* get_texture(size_t num); };