diff --git a/constants.hpp b/constants.hpp index 4e4b2eb..3ca14a6 100644 --- a/constants.hpp +++ b/constants.hpp @@ -10,6 +10,8 @@ constexpr const int SCREEN_HEIGHT=720; constexpr const int SCREEN_WIDTH=1280; constexpr const bool VSYNC=false; constexpr const int FRAME_LIMIT=60; +constexpr const int NUM_SPRITES=1; + #ifdef NDEBUG constexpr const bool DEBUG_BUILD=false; #else diff --git a/raycaster.cpp b/raycaster.cpp index 4c1dd30..9d2ad28 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -34,8 +34,8 @@ Raycaster::Raycaster(sf::RenderWindow& window, Matrix &map, int width, int heigh $width(width), $height(height), $window(window), $map(map), - spriteOrder($textures.NUM_SPRITES), - spriteDistance($textures.NUM_SPRITES), + spriteOrder(NUM_SPRITES), + spriteDistance(NUM_SPRITES), ZBuffer(width) { $view_sprite.setPosition({0, 0}); @@ -72,7 +72,7 @@ void Raycaster::sprite_casting() { const int halfHeight = TEXTURE_HEIGHT / 2; // sort sprites from far to close - for(int i = 0; i < $textures.NUM_SPRITES; i++) { + for(int i = 0; i < NUM_SPRITES; i++) { auto& sprite = $textures.get_sprite(i); spriteOrder[i] = i; // this is just the distance calculation @@ -82,10 +82,10 @@ void Raycaster::sprite_casting() { ($posY - sprite.y)); } - sort_sprites(spriteOrder, spriteDistance, $textures.NUM_SPRITES); + sort_sprites(spriteOrder, spriteDistance, NUM_SPRITES); // after sorting the sprites, do the projection - for(int i = 0; i < $textures.NUM_SPRITES; i++) { + for(int i = 0; i < NUM_SPRITES; i++) { int sprite_index = spriteOrder[i]; Sprite& sprite_rec = $textures.get_sprite(sprite_index); // TODO: this must die @@ -110,11 +110,11 @@ void Raycaster::sprite_casting() { // calculate the height of the sprite on screen //using "transformY" instead of the real distance prevents fisheye - int spriteHeight = abs(int($height / transformY)) / sprite_rec.vDiv; + int spriteHeight = abs(int($height / transformY)); // calculate width the the sprite // same as height of sprite, given that it's square - int spriteWidth = abs(int($height / transformY)) / sprite_rec.uDiv; + int spriteWidth = abs(int($height / transformY)); int drawStartX = -spriteWidth / 2 + spriteScreenX; if(drawStartX < 0) drawStartX = 0; @@ -132,11 +132,10 @@ void Raycaster::sprite_casting() { 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); //calculate lowest and highest pixel to fill in current stripe - int drawStartY = -spriteHeight / 2 + $height / 2 + vMoveScreen; + int drawStartY = -spriteHeight / 2 + $height / 2; if(drawStartY < 0) drawStartY = 0; - int drawEndY = spriteHeight / 2 + $height / 2 + vMoveScreen; + int drawEndY = spriteHeight / 2 + $height / 2; if(drawEndY >= $height) drawEndY = $height - 1; int texX = int(textureWidth * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / textureWidth; @@ -146,7 +145,7 @@ void Raycaster::sprite_casting() { float sprite_w = float(spriteWidth) / float(textureWidth); float sprite_h = float(spriteHeight) / float(textureHeight); - int d = (y - vMoveScreen) * textureHeight - $height * halfHeight + spriteHeight * halfHeight; + int d = y * textureHeight - $height * halfHeight + spriteHeight * halfHeight; int texY = ((d * textureHeight) / spriteHeight) / textureHeight; sf_sprite->setScale({sprite_w, sprite_h}); diff --git a/texture.hpp b/texture.hpp index 7832c22..bd4619d 100644 --- a/texture.hpp +++ b/texture.hpp @@ -16,14 +16,9 @@ struct Sprite { double x; double y; SpriteTexture sprite; - double elevation=0; - int uDiv=1; - int vDiv=1; }; struct TexturePack { - int NUM_SPRITES=1; - std::vector images; std::vector sprites; std::unordered_map sprite_textures;