1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include<SFML/Graphics.hpp>
#include<vector>
#include<cstdio>
#include<cmath>
#include "graphics/animation.h"
#include "entity.h"
#include "resourceManager.h"
namespace gph = Graphics;
class Unit: Entity{
private:
sf::Texture spritesheet_;
public:
gph::Animation dying_animation;
gph::Animation& current_animation = dying_animation;
sf::Sprite sprite;
sf::Vector2f position;
sf::Vector2f size;
sf::Vector2f speed;
Unit(sf::Texture& spritesheet){
spritesheet_ = spritesheet;
dying_animation = gph::Animation(spritesheet_, 14, sf::milliseconds(1400), false);
current_animation = dying_animation;
position = sf::Vector2f{0,0};
speed = sf::Vector2f{0,0};
};
void walk(float vx, float vy){
speed.y = vy;
speed.x = vx;
current_animation.reset();
// current_animation = &walking_animation;
}
void shoot(){
current_animation.reset();
// current_animation = &shooting_animation;
}
~Unit(){};
void update(sf::Time dt){
current_animation.update( dt);
}
};
enum class TextureId{
Angle1,
Angle2,
Front,
Back,
Side
};
int main()
{
sf::RenderWindow renderWindow(sf::VideoMode(640, 480), "Demo Game");
sf::Event event;
sf::Clock clock;
ResourceManager<sf::Texture, TextureId> TextureManager;
TextureManager.load( TextureId::Angle1, "assets/img/Player/angle1-dying.png");
Unit unit = Unit(TextureManager.get(TextureId::Angle1));
renderWindow.setFramerateLimit(60);
sf::Time elapsed_time = sf::Time::Zero;
bool once = true;
while (renderWindow.isOpen()){
sf::Time dt = clock.getElapsedTime();
elapsed_time += dt;
clock.restart();
while (renderWindow.pollEvent(event)){
if (event.type == sf::Event::EventType::Closed)
renderWindow.close();
}
if(elapsed_time > sf::milliseconds(4000) && once){
unit.current_animation.reset();
once = false;
}
unit.update(dt);
renderWindow.clear();
renderWindow.draw(unit.current_animation);
renderWindow.display();
}
}
|