From 6ed57cd4a82ab7092fa42f6e27c9eed666ca83b1 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 25 Jan 2025 12:19:14 -0500 Subject: [PATCH] Closer to what I want for sprite loading but still needs more work. --- assets/config.json | 19 ++++++++++--------- raycaster.cpp | 4 +--- texture.cpp | 7 ++++--- texture.hpp | 10 ++++++++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/assets/config.json b/assets/config.json index c70b0c6..b1485fe 100644 --- a/assets/config.json +++ b/assets/config.json @@ -5,13 +5,14 @@ "assets/ceiling_test-256.png", "assets/wood_wall-256.png" ], - "sprites": [ - "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-256.png", - "ceiling": "assets/ceiling_test-256.png" + "sprites": { + "armored_knight": "assets/armored_knight_1-256.png", + "sword": "assets/cinqueda_1-256.png", + "barrel": "assets/wood_barrel_large-256.png", + "evil_eye": "assets/evil_eye_test-256.png", + "peasant_girl": "assets/undead_peasant-256.png", + "floor": "assets/floor_tile_test-256.png", + "ceiling": "assets/ceiling_test-256.png", + "weapon": "assets/cinqueda_1-256.png" + } } diff --git a/raycaster.cpp b/raycaster.cpp index 6612b98..e665dca 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -148,9 +148,7 @@ void Raycaster::sprite_casting() { int texY = ((d * textureHeight) / spriteHeight) / textureHeight; sf_sprite->setScale({sprite_w, sprite_h}); - 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->setTextureRect(sf::IntRect({texX, texY}, {texX_end - texX, textureHeight})); sf_sprite->setPosition({x, y}); $window.draw(*sf_sprite); } diff --git a/texture.cpp b/texture.cpp index 3fc9282..9b98a71 100644 --- a/texture.cpp +++ b/texture.cpp @@ -23,12 +23,13 @@ void TexturePack::load_textures() { images.emplace_back(load_image(tile_path)); } - floor = load_image(assets["floor"]); - ceiling = load_image(assets["ceiling"]); + floor = load_image(assets["sprites"]["floor"]); + ceiling = load_image(assets["sprites"]["ceiling"]); - sf::Texture* sprite_texture = new sf::Texture("assets/undead_peasant-spritesheet.png"); + sf::Texture* sprite_texture = new sf::Texture(assets["sprites"]["evil_eye"]); 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}); sword.sprite_texture = new sf::Texture("assets/cinqueda_1-512.png"); diff --git a/texture.hpp b/texture.hpp index eec6c45..cd1739a 100644 --- a/texture.hpp +++ b/texture.hpp @@ -4,6 +4,7 @@ #include #include #include +#include struct Sprite { double x; @@ -11,20 +12,25 @@ struct Sprite { int texture; sf::Sprite *sprite = nullptr; sf::Texture *sprite_texture = nullptr; - // ZED: this should be a separate transform parameter double elevation=0; int uDiv=1; int vDiv=1; }; +struct SpriteTexture { + sf::Sprite *sprite = nullptr; + sf::Texture *sprite_texture = nullptr; +}; + struct TexturePack { int NUM_SPRITES=1; std::vector images; std::vector sprites; + std::unordered_map sprite_sheets; sf::Image floor; sf::Image ceiling; - Sprite sword; + SpriteTexture sword; void load_textures(); sf::Image load_image(std::string filename);