diff --git a/assets/numbers.png b/assets/numbers.png new file mode 100644 index 0000000..224b978 Binary files /dev/null and b/assets/numbers.png differ diff --git a/src/debug/grid_debug_layer.cpp b/src/debug/grid_debug_layer.cpp index 1722188..0c3ef8a 100644 --- a/src/debug/grid_debug_layer.cpp +++ b/src/debug/grid_debug_layer.cpp @@ -23,7 +23,7 @@ GridDebugLayer::GridDebugLayer(int minX, int maxX, int minY, int maxY) } auto gameObject = std::make_shared(DB_ISOPLANE_CORNER_RADIUS, color); - addChild(gameObject, WorldCoordinates(x, y)); + addChildWorldOffset(gameObject, WorldCoordinates(x, y)); } } } diff --git a/src/game/game_object.cpp b/src/game/game_object.cpp index 9165db7..ee7989a 100644 --- a/src/game/game_object.cpp +++ b/src/game/game_object.cpp @@ -44,10 +44,10 @@ void GameObject::lateUpdate() void GameObject::addChildScreenOffset(const std::shared_ptr &child, IsometricCoordinates offset) { auto worldOffset = CoordinateTransformer::isometricToWorld(offset); - addChild(child, worldOffset); + addChildWorldOffset(child, worldOffset); } -void GameObject::addChild(const std::shared_ptr &child, WorldCoordinates offset) +void GameObject::addChildWorldOffset(const std::shared_ptr &child, WorldCoordinates offset) { children.push_back(child); child->coordinates->setParent(coordinates, offset); diff --git a/src/game/game_object.h b/src/game/game_object.h index a476f1b..3bc490d 100644 --- a/src/game/game_object.h +++ b/src/game/game_object.h @@ -22,7 +22,7 @@ public: bool getActive() const { return isActive; } void addChildScreenOffset(const std::shared_ptr &child, IsometricCoordinates offset = {0, 0}); - void addChild(const std::shared_ptr &child, WorldCoordinates offset); + void addChildWorldOffset(const std::shared_ptr &child, WorldCoordinates offset); std::vector> getChildren() const { return children; } std::shared_ptr coordinates; diff --git a/src/game/player/player.cpp b/src/game/player/player.cpp index 671dd0b..7e63c0f 100644 --- a/src/game/player/player.cpp +++ b/src/game/player/player.cpp @@ -1,6 +1,8 @@ #include "player.hpp" #include "../../sprites/texture_manager.hpp" #include "../../sprites/single_sprite.hpp" +#include "../../sprites/animated_sprite.hpp" +#include "../../sprites/sprite_sheet.hpp" #include @@ -10,9 +12,14 @@ Player::Player(std::shared_ptr assignedInput, const std::string & input = std::move(assignedInput); - auto sprite = std::make_shared(TextureManager::getInstance()->getTexture(image), - sf::Vector2f{width, width}); - addChildScreenOffset(sprite, {-width / 2.f, -width / 2.f}); +// auto sprite = std::make_shared(TextureManager::getInstance()->getTexture(image), +// sf::Vector2f{width, width}); +// addChildScreenOffset(sprite, {-width / 2.f, -width / 2.f}); + + auto spriteSheet = std::make_shared(TextureManager::getInstance()->getTexture(image), 4, 2); + auto animatedSprite = spriteSheet->getAnimation(0, 8); + animatedSprite->setSize({width, width}); + addChildScreenOffset(animatedSprite, {-width / 2.f, -width / 2.f}); } sf::Vector2f Player::getTrackablePosition() const @@ -36,6 +43,8 @@ void Player::update() auto moveDirection = input->direction.asIsometricVector(); auto moveDelta = moveDirection * speed * FRAME_TIME.asSeconds(); coordinates->move(moveDelta); + + GameObject::update(); } TrackableState Player::getTrackableState() const diff --git a/src/game/player/player.hpp b/src/game/player/player.hpp index 231d0fb..b3fd4f3 100644 --- a/src/game/player/player.hpp +++ b/src/game/player/player.hpp @@ -24,7 +24,7 @@ public: private: std::shared_ptr input; - float width = 10; + float width = 50; }; diff --git a/src/sprites/animated_sprite.cpp b/src/sprites/animated_sprite.cpp index b1404ef..997b391 100644 --- a/src/sprites/animated_sprite.cpp +++ b/src/sprites/animated_sprite.cpp @@ -1,5 +1,6 @@ #include "animated_sprite.hpp" #include "../config.h" +#include "../logging/easylogging++.h" AnimatedSprite::AnimatedSprite(const std::vector &sprites, const sf::Vector2f& size) { diff --git a/src/sprites/animated_sprite.hpp b/src/sprites/animated_sprite.hpp index f314f4d..ea7a345 100644 --- a/src/sprites/animated_sprite.hpp +++ b/src/sprites/animated_sprite.hpp @@ -15,12 +15,14 @@ public: void draw(sf::RenderWindow *window) const override; sf::Time frameDuration = sf::seconds(0.1f); + + void setSize(const sf::Vector2f &size); + private: int currentFrame = 0; sf::Time timeSinceLastFrame = sf::Time::Zero; std::vector sprites; - void setSize(const sf::Vector2f &size); }; diff --git a/src/sprites/sprite_sheet.cpp b/src/sprites/sprite_sheet.cpp index cd80142..ddc77f6 100644 --- a/src/sprites/sprite_sheet.cpp +++ b/src/sprites/sprite_sheet.cpp @@ -29,7 +29,7 @@ sf::Sprite SpriteSheet::getSprite(int sequenceIndex) const std::shared_ptr SpriteSheet::getAnimation(int startingSequenceIndex, int numberOfFrames) const { - if (startingSequenceIndex < 0 || startingSequenceIndex + numberOfFrames >= sprites.size()) + if (startingSequenceIndex < 0 || startingSequenceIndex + numberOfFrames > sprites.size()) { throw std::runtime_error("Invalid starting sequence index"); } diff --git a/src/texture_config.h b/src/texture_config.h index 7538628..d63144c 100644 --- a/src/texture_config.h +++ b/src/texture_config.h @@ -7,7 +7,7 @@ #define PLAYER_TEXTURE "player" std::map const all_textures = { - {PLAYER_TEXTURE, "assets/64.png"} + {PLAYER_TEXTURE, "assets/numbers.png"} }; #endif //HOLESOME_TEXTURE_CONFIG_H