summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 38d1e06..c72d597 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,10 +21,10 @@ class Unit: Entity{
std::vector<int> animation_frame_count { 6, 8, 6, 1, 14 };
Graphics::Animation walking_animation;
Graphics::Animation standing_animation;
- Graphics::Animation shooting_animation;
- Graphics::Animation complaining_animation;
- Graphics::Animation dying_animation;
- Graphics::Animation& current_animation = standing_animation;
+ Graphics::OneShotAnimation shooting_animation;
+ Graphics::OneShotAnimation complaining_animation;
+ Graphics::OneShotAnimation dying_animation;
+ Graphics::Animation* current_animation = &standing_animation;
sf::Sprite sprite;
sf::Vector2f position;
@@ -36,9 +36,9 @@ class Unit: Entity{
spritesheet_.loadFromFile("angle1_all.png");
standing_animation = Graphics::Animation(spritesheet_, 6, 60, 44, 48, 0);
walking_animation = Graphics::Animation(spritesheet_, 8, 60, 44, 48, 1);
- shooting_animation = Graphics::Animation(spritesheet_, 6, 60, 44, 48, 2);
- complaining_animation = Graphics::Animation(spritesheet_, 1, 60, 44, 48, 3);
- dying_animation = Graphics::Animation(spritesheet_, 14, 60, 44, 48, 4);
+ shooting_animation = Graphics::OneShotAnimation(spritesheet_, 6, 60, 44, 48, 2);
+ complaining_animation = Graphics::OneShotAnimation(spritesheet_, 1, 60, 44, 48, 3);
+ dying_animation = Graphics::OneShotAnimation(spritesheet_, 14, 60, 44, 48, 4);
position = sf::Vector2f{0,0};
speed = sf::Vector2f{0,0};
@@ -46,16 +46,23 @@ class Unit: Entity{
void walk(float vx, float vy){
speed.y = vy;
speed.x = vx;
- current_animation.reset();
- current_animation = walking_animation;
- walking_animation.reset();
+ current_animation->reset();
+ current_animation = &walking_animation;
+ }
+ void shoot(){
+ 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.setTextureRect(current_animation->next(dt));
sprite.setPosition(position.x, position.y);
}
};
@@ -83,7 +90,7 @@ int main()
}
if(elapsed_time > 1000 && once){
- unit.walk(0.3, 0);
+ unit.shoot();
once = false;
}