From cefe66cdbb8786dc455657376e36f0ff8785d5bc Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 8 Feb 2018 12:34:42 -0500 Subject: Introduced animated sprites Also restyled a lot of the code. --- CMakeLists.txt | 2 +- src/animation.cpp | 35 +++++++++++ src/animation.h | 100 ++++++++++++++++++++++++++++++ src/components/animatable.cpp | 27 --------- src/components/animatable.h | 75 ++++++++++++++++------- src/components/orientable.h | 24 ++++++++ src/components/ponderable.h | 13 ++++ src/game.cpp | 73 +++++++++++++--------- src/game.h | 36 ++++++++--- src/system.h | 12 +++- src/systems/animating.cpp | 38 ++++++++++++ src/systems/animating.h | 20 ++++++ src/systems/controlling.cpp | 138 +++++++++++++++++++++++++++--------------- src/systems/controlling.h | 36 ++++++----- src/systems/pondering.cpp | 10 +-- src/systems/pondering.h | 10 +-- src/systems/rendering.cpp | 40 ++++++++---- src/systems/rendering.h | 15 +++-- 18 files changed, 521 insertions(+), 183 deletions(-) create mode 100644 src/animation.cpp create mode 100644 src/animation.h delete mode 100644 src/components/animatable.cpp create mode 100644 src/components/orientable.h create mode 100644 src/systems/animating.cpp create mode 100644 src/systems/animating.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e43b056..0ac3a38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,10 +61,10 @@ add_executable(Aromatherapy src/entity_manager.cpp src/game.cpp src/animation.cpp - src/components/animatable.cpp src/systems/rendering.cpp src/systems/controlling.cpp src/systems/pondering.cpp + src/systems/animating.cpp ) target_link_libraries(Aromatherapy ${ALL_LIBS}) install(TARGETS Aromatherapy RUNTIME DESTINATION ${BIN_DIR}) diff --git a/src/animation.cpp b/src/animation.cpp new file mode 100644 index 0000000..31ba21f --- /dev/null +++ b/src/animation.cpp @@ -0,0 +1,35 @@ +#include "animation.h" + +AnimationSet::AnimationSet( + Texture texture, + int frameWidth, + int frameHeight, + int framesAcross) : + texture_(std::move(texture)), + frameWidth_(frameWidth), + frameHeight_(frameHeight), + framesAcross_(framesAcross) +{ +} + +void AnimationSet::emplaceAnimation( + std::string animation, + size_t firstFrame, + size_t numFrames, + size_t delay) +{ + animations_.emplace( + std::piecewise_construct, + std::make_tuple(animation), + std::make_tuple(firstFrame, numFrames, delay)); +} + +Rectangle AnimationSet::getFrameRect(int frame) const +{ + return { + frameWidth_ * (frame % framesAcross_), + frameHeight_ * (frame / framesAcross_), + frameWidth_, + frameHeight_ + }; +} diff --git a/src/animation.h b/src/animation.h new file mode 100644 index 0000000..50446d0 --- /dev/null +++ b/src/animation.h @@ -0,0 +1,100 @@ +#ifndef ANIMATION_H_74EB0901 +#define ANIMATION_H_74EB0901 + +#include "renderer.h" +#include +#include +#include + +class Animation { +public: + + Animation( + size_t firstFrame, + size_t numFrames, + size_t delay) : + firstFrame_(firstFrame), + numFrames_(numFrames), + delay_(delay) + { + } + + inline size_t getFirstFrame() const + { + return firstFrame_; + } + + inline size_t getNumFrames() const + { + return numFrames_; + } + + inline size_t getDelay() const + { + return delay_; + } + +private: + + size_t firstFrame_; + size_t numFrames_; + size_t delay_; +}; + +class AnimationSet { +public: + + AnimationSet( + Texture texture, + int frameWidth, + int frameHeight, + int framesAcross); + + void emplaceAnimation( + std::string animation, + size_t firstFrame, + size_t numFrames, + size_t delay); + + inline const Animation& getAnimation(std::string animation) const + { + if (!animations_.count(animation)) + { + throw std::invalid_argument("Animation does not exist"); + } + + return animations_.at(animation); + } + + inline const Texture& getTexture() const + { + return texture_; + } + + inline int getFrameWidth() const + { + return frameWidth_; + } + + inline int getFrameHeight() const + { + return frameHeight_; + } + + inline int getFramesAcross() const + { + return framesAcross_; + } + + Rectangle getFrameRect(int frame) const; + +private: + + std::map animations_; + Texture texture_; + int frameWidth_; + int frameHeight_; + int framesAcross_; +}; + +#endif /* end of include guard: ANIMATION_H_74EB0901 */ diff --git a/src/components/animatable.cpp b/src/components/animatable.cpp deleted file mode 100644 index fcd277c..0000000 --- a/src/components/animatable.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "animatable.h" - -AnimatableComponent::AnimatableComponent(const char* filename, int frame_width, int frame_height, int frames_across) - : texture(filename), frame_width(frame_width), frame_height(frame_height), frames_across(frames_across) -{ - -} - -int AnimatableComponent::getFrame() const -{ - return frame; -} - -void AnimatableComponent::setFrame(int frame) -{ - this->frame = frame; -} - -const Texture& AnimatableComponent::getTexture() const -{ - return texture; -} - -Rectangle AnimatableComponent::getFrameRect() const -{ - return {frame_width * (frame % frames_across), frame_height * (frame / frames_across), frame_width, frame_height}; -} diff --git a/src/components/animatable.h b/src/components/animatable.h index cf6ee54..ed0133e 100644 --- a/src/components/animatable.h +++ b/src/components/animatable.h @@ -2,30 +2,61 @@ #define SPRITE_RENDERABLE_H_D3AACBBF #include "component.h" -#include "renderer.h" -#include "direction.h" +#include "animation.h" +#include class AnimatableComponent : public Component { - public: - AnimatableComponent(const char* filename, int frame_width, int frame_height, int frames_across); - - int getFrame() const; - void setFrame(int frame); - - const Texture& getTexture() const; - Rectangle getFrameRect() const; - - void setDirection(Direction dir) {}; - void setWalking(bool w) {}; - void setJumping(bool w) {}; - void setCrouching(bool w) {}; - - private: - Texture texture; - int frame_width; - int frame_height; - int frames_across; - int frame = 0; +public: + + AnimatableComponent( + AnimationSet animationSet, + std::string animation) : + animationSet_(std::move(animationSet)), + animation_(std::move(animation)) + { + } + + inline size_t getFrame() const + { + return frame_; + } + + inline void setFrame(size_t v) + { + frame_ = v; + } + + inline size_t getCountdown() const + { + return countdown_; + } + + inline void setCountdown(size_t v) + { + countdown_ = v; + } + + inline const AnimationSet& getAnimationSet() const + { + return animationSet_; + } + + inline const Animation& getAnimation() const + { + return animationSet_.getAnimation(animation_); + } + + inline void setAnimation(std::string animation) + { + animation_ = std::move(animation); + } + +private: + + AnimationSet animationSet_; + std::string animation_; + size_t frame_ = 0; + size_t countdown_ = 0; }; #endif /* end of include guard: SPRITE_RENDERABLE_H_D3AACBBF */ diff --git a/src/components/orientable.h b/src/components/orientable.h new file mode 100644 index 0000000..8f56912 --- /dev/null +++ b/src/components/orientable.h @@ -0,0 +1,24 @@ +#ifndef ORIENTABLE_H_EDB6C4A1 +#define ORIENTABLE_H_EDB6C4A1 + +#include "component.h" + +class OrientableComponent : public Component { +public: + + inline bool isFacingRight() const + { + return facingRight_; + } + + inline void setFacingRight(bool v) + { + facingRight_ = v; + } + +private: + + bool facingRight_ = false; +}; + +#endif /* end of include guard: ORIENTABLE_H_EDB6C4A1 */ diff --git a/src/components/ponderable.h b/src/components/ponderable.h index 80100d7..dfbf908 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h @@ -6,6 +6,13 @@ class PonderableComponent : public Component { public: + enum class state { + grounded, + jumping, + falling, + dropping + }; + inline double getVelocityX() const { return velX_; @@ -51,12 +58,18 @@ public: return state_; } + inline void setState(state arg) + { + state_ = arg; + } + private: double velX_ = 0.0; double velY_ = 0.0; double accelX_ = 0.0; double accelY_ = 0.0; + state state_ = state::grounded; }; #endif /* end of include guard: TANGIBLE_H_746DB3EE */ diff --git a/src/game.cpp b/src/game.cpp index 5d1ec18..492e4d0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4,40 +4,59 @@ #include "components/controllable.h" #include "components/droppable.h" #include "components/ponderable.h" +#include "components/orientable.h" #include "systems/rendering.h" #include "systems/controlling.h" #include "systems/pondering.h" +#include "systems/animating.h" +#include "animation.h" void key_callback(GLFWwindow* window, int key, int, int action, int) { Game& game = *((Game*) glfwGetWindowUserPointer(window)); - + if ((action == GLFW_PRESS) && (key == GLFW_KEY_ESCAPE)) { - game.shouldQuit = true; - + game.shouldQuit_ = true; + return; } - - game.systemManager.getSystem().input(key, action); + + game.systemManager_.getSystem().input(key, action); } -Game::Game(GLFWwindow* window) : window(window) +Game::Game(GLFWwindow* window) : window_(window) { - systemManager.emplaceSystem(*this); - systemManager.emplaceSystem(*this); - systemManager.emplaceSystem(*this); - - int player = entityManager.emplaceEntity(); - entityManager.emplaceComponent(player, "res/Starla.png", 10, 12, 6); - entityManager.emplaceComponent(player, 203, 44, 10, 12); - entityManager.emplaceComponent(player); - entityManager.emplaceComponent(player); - entityManager.emplaceComponent(player); - + systemManager_.emplaceSystem(*this); + systemManager_.emplaceSystem(*this); + systemManager_.emplaceSystem(*this); + systemManager_.emplaceSystem(*this); + + int player = entityManager_.emplaceEntity(); + + AnimationSet playerGraphics {"res/Starla2.bmp", 10, 12, 6}; + playerGraphics.emplaceAnimation("stillLeft", 3, 1, 1); + playerGraphics.emplaceAnimation("stillRight", 0, 1, 1); + playerGraphics.emplaceAnimation("walkingLeft", 4, 2, 10); + playerGraphics.emplaceAnimation("walkingRight", 1, 2, 10); + + entityManager_.emplaceComponent( + player, + std::move(playerGraphics), + "stillLeft"); + + entityManager_.emplaceComponent( + player, + 203, 44, 10, 12); + + entityManager_.emplaceComponent(player); + entityManager_.emplaceComponent(player); + entityManager_.emplaceComponent(player); + entityManager_.emplaceComponent(player); + glfwSwapInterval(1); - glfwSetWindowUserPointer(window, this); - glfwSetKeyCallback(window, key_callback); + glfwSetWindowUserPointer(window_, this); + glfwSetKeyCallback(window_, key_callback); } void Game::execute() @@ -46,7 +65,7 @@ void Game::execute() const double dt = 0.01; double accumulator = 0.0; - while (!(shouldQuit || glfwWindowShouldClose(window))) + while (!(shouldQuit_ || glfwWindowShouldClose(window_))) { double currentTime = glfwGetTime(); double frameTime = currentTime - lastTime; @@ -57,19 +76,13 @@ void Game::execute() accumulator += frameTime; while (accumulator >= dt) { - systemManager.getSystem().tick(dt); - systemManager.getSystem().tick(dt); + systemManager_.getSystem().tick(dt); + systemManager_.getSystem().tick(dt); + systemManager_.getSystem().tick(dt); accumulator -= dt; } - systemManager.getSystem().tick(frameTime); + systemManager_.getSystem().tick(frameTime); } } - -EntityManager& Game::getEntityManager() -{ - return entityManager; -} - - diff --git a/src/game.h b/src/game.h index ec667c8..7bd038e 100644 --- a/src/game.h +++ b/src/game.h @@ -6,19 +6,35 @@ #include "system_manager.h" class Game { - public: - Game(GLFWwindow* window); +public: - void execute(); - EntityManager& getEntityManager(); + Game(GLFWwindow* window); - friend void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); + void execute(); - private: - EntityManager entityManager; - SystemManager systemManager; - GLFWwindow* const window; - bool shouldQuit = false; + inline EntityManager& getEntityManager() + { + return entityManager_; + } + + inline SystemManager& getSystemManager() + { + return systemManager_; + } + + friend void key_callback( + GLFWwindow* window, + int key, + int scancode, + int action, + int mods); + +private: + + EntityManager entityManager_; + SystemManager systemManager_; + GLFWwindow* const window_; + bool shouldQuit_ = false; }; #endif /* end of include guard: GAME_H_1014DDC9 */ diff --git a/src/system.h b/src/system.h index 489afd0..6a3cd14 100644 --- a/src/system.h +++ b/src/system.h @@ -1,12 +1,18 @@ #ifndef SYSTEM_H_B61A8CEA #define SYSTEM_H_B61A8CEA +#include "entity_manager.h" + class Game; class System { public: - System(Game& game) - : game(game) {} + + using id_type = EntityManager::id_type; + + System(Game& game) : game_(game) + { + } virtual ~System() = default; @@ -14,7 +20,7 @@ public: protected: - Game& game; + Game& game_; }; #endif /* end of include guard: SYSTEM_H_B61A8CEA */ diff --git a/src/systems/animating.cpp b/src/systems/animating.cpp new file mode 100644 index 0000000..fcbfca5 --- /dev/null +++ b/src/systems/animating.cpp @@ -0,0 +1,38 @@ +#include "animating.h" +#include "game.h" +#include "components/animatable.h" + +void AnimatingSystem::tick(double) +{ + std::set spriteEntities = + game_.getEntityManager().getEntitiesWithComponents(); + + for (id_type entity : spriteEntities) + { + auto& sprite = game_.getEntityManager(). + getComponent(entity); + + sprite.setCountdown(sprite.getCountdown() + 1); + + const Animation& anim = sprite.getAnimation(); + if (sprite.getCountdown() >= anim.getDelay()) + { + sprite.setFrame(sprite.getFrame() + 1); + sprite.setCountdown(0); + + if (sprite.getFrame() >= anim.getFirstFrame() + anim.getNumFrames()) + { + sprite.setFrame(anim.getFirstFrame()); + } + } + } +} + +void AnimatingSystem::startAnimation(id_type entity, std::string animation) +{ + auto& sprite = game_.getEntityManager(). + getComponent(entity); + + sprite.setAnimation(animation); + sprite.setFrame(sprite.getAnimation().getFirstFrame()); +} diff --git a/src/systems/animating.h b/src/systems/animating.h new file mode 100644 index 0000000..150a74a --- /dev/null +++ b/src/systems/animating.h @@ -0,0 +1,20 @@ +#ifndef ANIMATING_H_5BBF0094 +#define ANIMATING_H_5BBF0094 + +#include "system.h" +#include + +class AnimatingSystem : public System { +public: + + AnimatingSystem(Game& game) : System(game) + { + } + + void tick(double dt); + + void startAnimation(id_type entity, std::string animation); + +}; + +#endif /* end of include guard: ANIMATING_H_5BBF0094 */ diff --git a/src/systems/controlling.cpp b/src/systems/controlling.cpp index ec62e9a..3647ff8 100644 --- a/src/systems/controlling.cpp +++ b/src/systems/controlling.cpp @@ -4,21 +4,30 @@ #include "components/ponderable.h" #include "components/animatable.h" #include "components/droppable.h" +#include "components/orientable.h" +#include "systems/animating.h" #include "direction.h" #include "muxer.h" #include "consts.h" -void ControllingSystem::tick(double dt) +void ControllingSystem::tick(double) { - while (!actions.empty()) + while (!actions_.empty()) { - int key = actions.front().first; - int action = actions.front().second; + int key = actions_.front().first; + int action = actions_.front().second; + + auto entities = game_.getEntityManager().getEntitiesWithComponents< + ControllableComponent, + PonderableComponent, + AnimatableComponent, + DroppableComponent, + OrientableComponent>(); - auto entities = game.getEntityManager().getEntitiesWithComponents(); for (auto entity : entities) { - auto& controllable = game.getEntityManager().getComponent(entity); + auto& controllable = game_.getEntityManager(). + getComponent(entity); if (action == GLFW_PRESS) { @@ -95,74 +104,107 @@ void ControllingSystem::tick(double dt) } } - actions.pop(); + actions_.pop(); } } void ControllingSystem::input(int key, int action) { - actions.push(std::make_pair(key, action)); + actions_.push(std::make_pair(key, action)); } -void ControllingSystem::walkLeft(int entity) +void ControllingSystem::walkLeft(id_type entity) { - auto& ponderable = game.getEntityManager().getComponent(entity); - auto& animatable = game.getEntityManager().getComponent(entity); - + auto& ponderable = game_.getEntityManager().getComponent(entity); + auto& orientable = game_.getEntityManager().getComponent(entity); + + orientable.setFacingRight(false); ponderable.setVelocityX(-90); - - animatable.setDirection(Direction::Left); - animatable.setWalking(true); + + auto& animating = game_.getSystemManager().getSystem(); + + if (ponderable.getState() == PonderableComponent::state::grounded) + { + animating.startAnimation(entity, "walkingLeft"); + } else { + animating.startAnimation(entity, "stillLeft"); + } } -void ControllingSystem::walkRight(int entity) +void ControllingSystem::walkRight(id_type entity) { - auto& ponderable = game.getEntityManager().getComponent(entity); - auto& animatable = game.getEntityManager().getComponent(entity); - + auto& ponderable = game_.getEntityManager().getComponent(entity); + auto& orientable = game_.getEntityManager().getComponent(entity); + + orientable.setFacingRight(true); ponderable.setVelocityX(90); - animatable.setDirection(Direction::Right); - animatable.setWalking(true); + auto& animating = game_.getSystemManager().getSystem(); + + if (ponderable.getState() == PonderableComponent::state::grounded) + { + animating.startAnimation(entity, "walkingRight"); + } else { + animating.startAnimation(entity, "stillRight"); + } } -void ControllingSystem::stopWalking(int entity) +void ControllingSystem::stopWalking(id_type entity) { - auto& ponderable = game.getEntityManager().getComponent(entity); - auto& animatable = game.getEntityManager().getComponent(entity); - + auto& ponderable = game_.getEntityManager().getComponent(entity); + auto& orientable = game_.getEntityManager().getComponent(entity); + ponderable.setVelocityX(0); - - animatable.setWalking(false); + + if (ponderable.getState() == PonderableComponent::state::grounded) + { + auto& animating = game_.getSystemManager().getSystem(); + + if (orientable.isFacingRight()) + { + animating.startAnimation(entity, "stillRight"); + } else { + animating.startAnimation(entity, "stillLeft"); + } + } } -void ControllingSystem::jump(int entity) +void ControllingSystem::jump(id_type entity) { - auto& ponderable = game.getEntityManager().getComponent(entity); - auto& animatable = game.getEntityManager().getComponent(entity); - - playSound("res/Randomize87.wav", 0.25); - - ponderable.setVelocityY(JUMP_VELOCITY(TILE_HEIGHT*4.5, 0.3)); - ponderable.setAccelY(JUMP_GRAVITY(TILE_HEIGHT*4.5, 0.3)); - - animatable.setJumping(true); + auto& ponderable = game_.getEntityManager().getComponent(entity); + + if (ponderable.getState() == PonderableComponent::state::grounded) + { + playSound("res/Randomize87.wav", 0.25); + + ponderable.setVelocityY(JUMP_VELOCITY(TILE_HEIGHT*4.5, 0.3)); + ponderable.setAccelY(JUMP_GRAVITY(TILE_HEIGHT*4.5, 0.3)); + ponderable.setState(PonderableComponent::state::jumping); + } } -void ControllingSystem::stopJumping(int entity) +void ControllingSystem::stopJumping(id_type entity) { - auto& ponderable = game.getEntityManager().getComponent(entity); - auto& animatable = game.getEntityManager().getComponent(entity); - - ponderable.setAccelY(JUMP_GRAVITY(TILE_HEIGHT*3.5, 0.233)); - animatable.setJumping(false); + auto& ponderable = game_.getEntityManager().getComponent(entity); + + if (ponderable.getState() == PonderableComponent::state::jumping) + { + ponderable.setAccelY(JUMP_GRAVITY(TILE_HEIGHT*3.5, 0.233)); + ponderable.setState(PonderableComponent::state::falling); + } } -void ControllingSystem::drop(int entity, bool start) +void ControllingSystem::drop(id_type entity, bool start) { - auto& animatable = game.getEntityManager().getComponent(entity); - auto& droppable = game.getEntityManager().getComponent(entity); - + auto& droppable = game_.getEntityManager().getComponent(entity); + auto& ponderable = game_.getEntityManager().getComponent(entity); + + if (start && (ponderable.getState() == PonderableComponent::state::grounded)) + { + ponderable.setState(PonderableComponent::state::dropping); + } else if ((!start) && (ponderable.getState() == PonderableComponent::state::dropping)) + { + ponderable.setState(PonderableComponent::state::grounded); + } droppable.setDroppable(start); - animatable.setCrouching(start); } diff --git a/src/systems/controlling.h b/src/systems/controlling.h index 30210b3..1f1e8a0 100644 --- a/src/systems/controlling.h +++ b/src/systems/controlling.h @@ -3,24 +3,28 @@ #include "system.h" #include +#include "entity_manager.h" class ControllingSystem : public System { - public: - ControllingSystem(Game& game) - : System(game) {} - - void tick(double dt); - void input(int key, int action); - - private: - void walkLeft(int entity); - void walkRight(int entity); - void stopWalking(int entity); - void jump(int entity); - void stopJumping(int entity); - void drop(int entity, bool start); - - std::queue> actions; +public: + + ControllingSystem(Game& game) : System(game) + { + } + + void tick(double dt); + void input(int key, int action); + +private: + + void walkLeft(id_type entity); + void walkRight(id_type entity); + void stopWalking(id_type entity); + void jump(id_type entity); + void stopJumping(id_type entity); + void drop(id_type entity, bool start); + + std::queue> actions_; }; #endif /* end of include guard: CONTROLLING_H_80B1BB8D */ diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 50a8bc8..e40db1d 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp @@ -5,12 +5,14 @@ void PonderingSystem::tick(double dt) { - auto entities = game.getEntityManager().getEntitiesWithComponents(); + auto entities = game_.getEntityManager().getEntitiesWithComponents< + PonderableComponent, + TransformableComponent>(); - for (auto entity : entities) + for (id_type entity : entities) { - auto& transformable = game.getEntityManager().getComponent(entity); - auto& ponderable = game.getEntityManager().getComponent(entity); + auto& transformable = game_.getEntityManager().getComponent(entity); + auto& ponderable = game_.getEntityManager().getComponent(entity); // Accelerate ponderable.setVelocityX(ponderable.getVelocityX() + ponderable.getAccelX() * dt); diff --git a/src/systems/pondering.h b/src/systems/pondering.h index 3fe5473..44e7600 100644 --- a/src/systems/pondering.h +++ b/src/systems/pondering.h @@ -4,11 +4,13 @@ #include "system.h" class PonderingSystem : public System { - public: - PonderingSystem(Game& game) - : System(game) {} +public: - void tick(double dt); + PonderingSystem(Game& game) : System(game) + { + } + + void tick(double dt); }; #endif /* end of include guard: PONDERING_H_F2530E0E */ diff --git a/src/systems/rendering.cpp b/src/systems/rendering.cpp index 251c2bc..8219732 100644 --- a/src/systems/rendering.cpp +++ b/src/systems/rendering.cpp @@ -3,19 +3,35 @@ #include "components/animatable.h" #include "components/transformable.h" -void RenderingSystem::tick(double dt) +void RenderingSystem::tick(double) { - texture.fill(texture.entirety(), 0, 0, 0); - - std::set spriteEntities = game.getEntityManager().getEntitiesWithComponents(); - for (int entity : spriteEntities) + texture_.fill(texture_.entirety(), 0, 0, 0); + + std::set spriteEntities = + game_.getEntityManager().getEntitiesWithComponents< + AnimatableComponent, + TransformableComponent>(); + + for (id_type entity : spriteEntities) { - auto& sprite = game.getEntityManager().getComponent(entity); - auto& transform = game.getEntityManager().getComponent(entity); - Rectangle dstrect {(int) transform.getX(), (int) transform.getY(), transform.getW(), transform.getH()}; - - texture.blit(sprite.getTexture(), sprite.getFrameRect(), dstrect); + auto& sprite = game_.getEntityManager(). + getComponent(entity); + + auto& transform = game_.getEntityManager(). + getComponent(entity); + + Rectangle dstrect { + static_cast(transform.getX()), + static_cast(transform.getY()), + transform.getW(), + transform.getH()}; + + const AnimationSet& aset = sprite.getAnimationSet(); + texture_.blit( + aset.getTexture(), + aset.getFrameRect(sprite.getFrame()), + dstrect); } - - texture.renderScreen(); + + texture_.renderScreen(); } diff --git a/src/systems/rendering.h b/src/systems/rendering.h index cec72e2..a53ee64 100644 --- a/src/systems/rendering.h +++ b/src/systems/rendering.h @@ -6,14 +6,17 @@ #include "consts.h" class RenderingSystem : public System { - public: - RenderingSystem(Game& game) - : System(game) {} +public: - void tick(double dt); + RenderingSystem(Game& game) : System(game) + { + } - private: - Texture texture {GAME_WIDTH, GAME_HEIGHT}; + void tick(double dt); + +private: + + Texture texture_ {GAME_WIDTH, GAME_HEIGHT}; }; #endif /* end of include guard: RENDERING_H_76ABC02A */ -- cgit 1.4.1