Prefix `MovementAnimationComponent` class with SideScroller

The class is really only set up for side scrollers for now
This commit is contained in:
SeanOMik 2020-07-06 00:56:48 -05:00
parent 3b63025a3f
commit 0969a9fb12
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
3 changed files with 26 additions and 22 deletions

View File

@ -8,7 +8,7 @@
#include <simpleengine/event.h>
#include <simpleengine/entity.h>
#include <simpleengine/components/movement/movement_component.h>
#include <simpleengine/components/movement_animation_component.h>
#include <simpleengine/components/side_scroller_movement_animation_component.h>
#include <simpleengine/events/entity_event.h>
#include <simpleengine/animation.h>
@ -22,7 +22,7 @@ private:
float movement_speed = 95;
sf::Vector2u window_size;
std::unique_ptr<simpleengine::MovementAnimationComponent> move_anim_component;
std::unique_ptr<simpleengine::SideScrollerMovementAnimationComponent> move_anim_component;
public:
explicit PlayerEntity(sf::Vector2u window_size) : window_size(window_size) {
AddComponent(std::make_unique<simpleengine::MovementComponent>(*this, movement_speed));
@ -30,9 +30,12 @@ public:
texture.loadFromFile("player_sheet.png");
sprite.setTexture(texture);
move_anim_component = std::make_unique<simpleengine::MovementAnimationComponent>(*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<simpleengine::SideScrollerMovementAnimationComponent>(*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));
}

View File

@ -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,9 +24,10 @@ 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,
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);
@ -46,4 +47,4 @@ namespace simpleengine {
}
#endif //SIMPLEENGINE_MOVEMENT_ANIMATION_COMPONENT_H
#endif //SIMPLEENGINE_SIDE_SCROLLER_MOVEMENT_ANIMATION_COMPONENT_H

View File

@ -4,21 +4,21 @@
// 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,
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,
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,
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,
@ -26,7 +26,7 @@ void simpleengine::MovementAnimationComponent::SetAnimation(const simpleengine::
}
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;
}