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. --- src/components/animatable.cpp | 27 ---------------- src/components/animatable.h | 75 ++++++++++++++++++++++++++++++------------- src/components/orientable.h | 24 ++++++++++++++ src/components/ponderable.h | 13 ++++++++ 4 files changed, 90 insertions(+), 49 deletions(-) delete mode 100644 src/components/animatable.cpp create mode 100644 src/components/orientable.h (limited to 'src/components') 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 */ -- cgit 1.4.1