summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-11-17 16:59:15 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-11-17 16:59:15 +0100
commit82598dbaac1bc99a0a4f99833b68915ffbec0495 (patch)
tree5dd3786ec850f0fbc46957368972a0883a56e5b3 /src/main.cpp
parentd1cc137aeb5eec8faa50d209a909cb3375e910f8 (diff)
Simplify animations
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp56
1 files changed, 16 insertions, 40 deletions
diff --git a/src/main.cpp b/src/main.cpp
index bd330fc..02697d7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,20 +14,8 @@ class Unit: Entity{
sf::Texture spritesheet_;
public:
- enum class Anim : int{
- standing = 0,
- walking = 1,
- shooting = 2,
- complaining = 3,
- dying = 4,
- };
- std::vector<int> animation_frame_count { 6, 8, 6, 1, 14 };
- gph::Animation walking_animation;
- gph::Animation standing_animation;
- gph::FlippedAnimation<gph::OneShotAnimation> shooting_animation;
- gph::OneShotAnimation complaining_animation;
- gph::OneShotAnimation dying_animation;
- gph::Animation* current_animation = &standing_animation;
+ gph::Animation dying_animation;
+ gph::Animation& current_animation = dying_animation;
sf::Sprite sprite;
sf::Vector2f position;
@@ -37,11 +25,8 @@ class Unit: Entity{
Unit(sf::Texture& spritesheet){
spritesheet_ = spritesheet;
- standing_animation = gph::Animation(spritesheet_, 6, 60, 44, 48, 0);
- walking_animation = gph::Animation(spritesheet_, 8, 60, 44, 48, 1);
- shooting_animation = gph::FlippedAnimation<gph::OneShotAnimation>(spritesheet_, 6, 60, 44, 48, 2);
- complaining_animation = gph::OneShotAnimation(spritesheet_, 1, 60, 44, 48, 3);
- dying_animation = gph::OneShotAnimation(spritesheet_, 14, 60, 44, 48, 4);
+ dying_animation = gph::Animation(spritesheet_, 14, sf::milliseconds(1400), false);
+ current_animation = dying_animation;
position = sf::Vector2f{0,0};
speed = sf::Vector2f{0,0};
@@ -49,25 +34,16 @@ class Unit: Entity{
void walk(float vx, float vy){
speed.y = vy;
speed.x = vx;
- current_animation->reset();
- current_animation = &walking_animation;
+ current_animation.reset();
+ // current_animation = &walking_animation;
}
void shoot(){
- current_animation->reset();
- current_animation = &shooting_animation;
+ current_animation.reset();
+ // current_animation = &shooting_animation;
}
~Unit(){};
- void update(int dt){
- //if (current_animation->finished()){
- // current_animation->reset();
- // current_animation = &standing_animation;
- //}
- position.x += round(speed.x * dt);
- sprite.setTexture(spritesheet_);
- sprite.setScale(8,8);
- sprite.setTextureRect(current_animation->next(dt));
- sprite.setPosition(position.x, position.y);
- sprite = sprite;
+ void update(sf::Time dt){
+ current_animation.update( dt);
}
};
@@ -88,17 +64,17 @@ int main()
sf::Clock clock;
ResourceManager<sf::Texture, TextureId> TextureManager;
- TextureManager.load( TextureId::Angle1, "assets/img/Player/Player Angle 1 Sheet.png");
+ TextureManager.load( TextureId::Angle1, "assets/img/Player/angle1-dying.png");
Unit unit = Unit(TextureManager.get(TextureId::Angle1));
renderWindow.setFramerateLimit(60);
- long elapsed_time = 0;
+ sf::Time elapsed_time = sf::Time::Zero;
bool once = true;
while (renderWindow.isOpen()){
- int dt = clock.getElapsedTime().asMilliseconds();
+ sf::Time dt = clock.getElapsedTime();
elapsed_time += dt;
clock.restart();
while (renderWindow.pollEvent(event)){
@@ -106,15 +82,15 @@ int main()
renderWindow.close();
}
- if(elapsed_time > 1000 && once){
- unit.shoot();
+ if(elapsed_time > sf::milliseconds(4000) && once){
+ unit.current_animation.reset();
once = false;
}
unit.update(dt);
renderWindow.clear();
- renderWindow.draw(unit.sprite);
+ renderWindow.draw(unit.current_animation);
renderWindow.display();
}
}