diff --git a/assets/config.json b/assets/config.json index 664f6f0..c70b0c6 100644 --- a/assets/config.json +++ b/assets/config.json @@ -1,7 +1,7 @@ { "textures": [ - "assets/floor_tile_test-256.png", "assets/wall_texture_test-256.png", + "assets/floor_tile_test-256.png", "assets/ceiling_test-256.png", "assets/wood_wall-256.png" ], diff --git a/assets/undead_peasant-spritesheet.png b/assets/undead_peasant-spritesheet.png new file mode 100644 index 0000000..9da3fc6 Binary files /dev/null and b/assets/undead_peasant-spritesheet.png differ diff --git a/constants.hpp b/constants.hpp index 6c2b429..4e4b2eb 100644 --- a/constants.hpp +++ b/constants.hpp @@ -8,7 +8,7 @@ constexpr const int RAY_VIEW_X=(1280 - RAY_VIEW_WIDTH); constexpr const int RAY_VIEW_Y=0; constexpr const int SCREEN_HEIGHT=720; constexpr const int SCREEN_WIDTH=1280; -constexpr const bool VSYNC=true; +constexpr const bool VSYNC=false; constexpr const int FRAME_LIMIT=60; #ifdef NDEBUG constexpr const bool DEBUG_BUILD=false; diff --git a/raycaster.cpp b/raycaster.cpp index e665dca..6612b98 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -148,7 +148,9 @@ void Raycaster::sprite_casting() { int texY = ((d * textureHeight) / spriteHeight) / textureHeight; sf_sprite->setScale({sprite_w, sprite_h}); - sf_sprite->setTextureRect(sf::IntRect({texX, texY}, {texX_end - texX, textureHeight})); + auto time = $clock.getElapsedTime(); + int frame = int(time.asMicroseconds() / 200.0) % 4; + sf_sprite->setTextureRect(sf::IntRect({texX + (textureWidth * frame), texY}, {texX_end - texX, textureHeight})); sf_sprite->setPosition({x, y}); $window.draw(*sf_sprite); } diff --git a/raycaster.hpp b/raycaster.hpp index d802956..f1d4e64 100644 --- a/raycaster.hpp +++ b/raycaster.hpp @@ -11,12 +11,14 @@ #include "dbc.hpp" #include #include "texture.hpp" +#include using matrix::Matrix; using RGBA = uint32_t; struct Raycaster { int $pitch=0; + sf::Clock $clock; TexturePack $textures; double $posX = 0; diff --git a/texture.cpp b/texture.cpp index 4320d72..3fc9282 100644 --- a/texture.cpp +++ b/texture.cpp @@ -14,6 +14,7 @@ sf::Image TexturePack::load_image(std::string filename) { void TexturePack::load_textures() { Config assets("assets/config.json"); + for(string tile_path : assets["textures"]) { images.emplace_back(load_image(tile_path)); } @@ -25,7 +26,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/undead_peasant-spritesheet.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});