diff --git a/examples/animation/src/main.cpp b/examples/animation/src/main.cpp index 8f5aaaa..f2db6b9 100644 --- a/examples/animation/src/main.cpp +++ b/examples/animation/src/main.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include @@ -22,7 +22,7 @@ private: float movement_speed = 95; sf::Vector2u window_size; - std::unique_ptr move_anim_component; + std::unique_ptr move_anim_component; public: explicit PlayerEntity(sf::Vector2u window_size) : window_size(window_size) { AddComponent(std::make_unique(*this, movement_speed)); @@ -30,9 +30,12 @@ public: texture.loadFromFile("player_sheet.png"); sprite.setTexture(texture); - move_anim_component = std::make_unique(*this, sprite, texture, movement_speed, 5, 1.1); - move_anim_component->SetAnimation(simpleengine::MovementAnimationType::WALK_LEFT, 9, 0, 8, 9, 8, 128, 128); - move_anim_component->SetAnimation(simpleengine::MovementAnimationType::IDLE_LEFT, 20, 0, 0, 6, 0, 128, 128); + move_anim_component = std::make_unique(*this, sprite, + texture, movement_speed, 5, 1.1); + move_anim_component->SetAnimation(simpleengine::MovementAnimationType::WALK_LEFT, 9, 0, 8, + 9, 8, 128, 128); + move_anim_component->SetAnimation(simpleengine::MovementAnimationType::IDLE_LEFT, 20, 0, 0, + 6, 0, 128, 128); AddComponent(std::move(move_anim_component)); } diff --git a/include/simpleengine/components/movement_animation_component.h b/include/simpleengine/components/side_scroller_movement_animation_component.h similarity index 66% rename from include/simpleengine/components/movement_animation_component.h rename to include/simpleengine/components/side_scroller_movement_animation_component.h index aa2759c..8fbd8b7 100644 --- a/include/simpleengine/components/movement_animation_component.h +++ b/include/simpleengine/components/side_scroller_movement_animation_component.h @@ -4,8 +4,8 @@ // Email: seanomik@gmail.com // -#ifndef SIMPLEENGINE_MOVEMENT_ANIMATION_COMPONENT_H -#define SIMPLEENGINE_MOVEMENT_ANIMATION_COMPONENT_H +#ifndef SIMPLEENGINE_SIDE_SCROLLER_MOVEMENT_ANIMATION_COMPONENT_H +#define SIMPLEENGINE_SIDE_SCROLLER_MOVEMENT_ANIMATION_COMPONENT_H #include "../component.h" #include "animation_component.h" @@ -24,10 +24,11 @@ namespace simpleengine { IDLE_RIGHT }; - class MovementAnimationComponent : public Component { + // Use this for side scrollers! + class SideScrollerMovementAnimationComponent : public Component { public: - MovementAnimationComponent(Entity& owning_entity, sf::Sprite &sprite, sf::Texture &texture_sheet, - float max_velocity, float acceleration, float deceleration); + SideScrollerMovementAnimationComponent(Entity& owning_entity, sf::Sprite &sprite, sf::Texture &texture_sheet, + float max_velocity, float acceleration, float deceleration); void SetAnimation(const MovementAnimationType& type, simpleengine::Animation animation); void SetAnimation(const MovementAnimationType& type, float speed, int start_frame_x, int start_frame_y, int frame_ct_x, int frame_ct_y, @@ -46,4 +47,4 @@ namespace simpleengine { } -#endif //SIMPLEENGINE_MOVEMENT_ANIMATION_COMPONENT_H +#endif //SIMPLEENGINE_SIDE_SCROLLER_MOVEMENT_ANIMATION_COMPONENT_H diff --git a/src/components/movement_animation_component.cpp b/src/components/side_scroller_movement_animation_component.cpp similarity index 75% rename from src/components/movement_animation_component.cpp rename to src/components/side_scroller_movement_animation_component.cpp index e179d03..a008ce5 100644 --- a/src/components/movement_animation_component.cpp +++ b/src/components/side_scroller_movement_animation_component.cpp @@ -4,29 +4,29 @@ // Email: seanomik@gmail.com // -#include "components/movement_animation_component.h" +#include "components/side_scroller_movement_animation_component.h" -simpleengine::MovementAnimationComponent::MovementAnimationComponent(simpleengine::Entity &owning_entity, - sf::Sprite &sprite, sf::Texture &texture_sheet, float max_velocity, float acceleration, float deceleration) +simpleengine::SideScrollerMovementAnimationComponent::SideScrollerMovementAnimationComponent(simpleengine::Entity &owning_entity, + sf::Sprite &sprite, sf::Texture &texture_sheet, float max_velocity, float acceleration, float deceleration) : Component(owning_entity), anim_component(owning_entity, sprite, texture_sheet), move_component(owning_entity, max_velocity, acceleration, deceleration) { } -void simpleengine::MovementAnimationComponent::SetAnimation(const simpleengine::MovementAnimationType &type, - simpleengine::Animation animation) { +void simpleengine::SideScrollerMovementAnimationComponent::SetAnimation(const simpleengine::MovementAnimationType &type, + simpleengine::Animation animation) { anim_component.AddAnimation(MovementAnimationTypeToStr(type), animation); } -void simpleengine::MovementAnimationComponent::SetAnimation(const simpleengine::MovementAnimationType &type, - float speed, int start_frame_x, int start_frame_y, int frame_ct_x, int frame_ct_y, int width, int height) { +void simpleengine::SideScrollerMovementAnimationComponent::SetAnimation(const simpleengine::MovementAnimationType &type, + float speed, int start_frame_x, int start_frame_y, int frame_ct_x, int frame_ct_y, int width, int height) { anim_component.AddAnimation(MovementAnimationTypeToStr(type), speed, start_frame_x, start_frame_y, frame_ct_x, frame_ct_y, width, height); } -void simpleengine::MovementAnimationComponent::Update(const float& delta_time) { +void simpleengine::SideScrollerMovementAnimationComponent::Update(const float& delta_time) { move_component.Update(delta_time); if (move_component.GetVelocity().x > 0) { // Moving right @@ -98,7 +98,7 @@ void simpleengine::MovementAnimationComponent::Update(const float& delta_time) { } } -std::string simpleengine::MovementAnimationComponent::MovementAnimationTypeToStr( +std::string simpleengine::SideScrollerMovementAnimationComponent::MovementAnimationTypeToStr( const simpleengine::MovementAnimationType &type) { switch (type) { @@ -115,10 +115,10 @@ std::string simpleengine::MovementAnimationComponent::MovementAnimationTypeToStr } } -simpleengine::AnimationComponent simpleengine::MovementAnimationComponent::GetAnimationComponent() { +simpleengine::AnimationComponent simpleengine::SideScrollerMovementAnimationComponent::GetAnimationComponent() { return anim_component; } -simpleengine::MovementComponent simpleengine::MovementAnimationComponent::GetMovementComponent() { +simpleengine::MovementComponent simpleengine::SideScrollerMovementAnimationComponent::GetMovementComponent() { return move_component; }