-
Notifications
You must be signed in to change notification settings - Fork 1
/
Turtle.cpp
64 lines (49 loc) · 1.69 KB
/
Turtle.cpp
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
#include "Turtle.hpp"
#include "GameState.hpp"
namespace APlusPlus
{
Turtle::Turtle(GameDataRef data) : _data(data)
{
_animationIterator = 0;
_animationFrames.push_back(this->_data->assets.GetTexture("Turtle Frame 1"));
_turtleSprite.setTexture(_animationFrames.at(_animationIterator));
_turtleSprite.setPosition((_data->window.getSize().x / 4) - (_turtleSprite.getGlobalBounds().width / 2), (_data->window.getSize().y / 2) - (_turtleSprite.getGlobalBounds().height / 2));
_turtleState = TURTLE_STATE_STILL;
sf::Vector2f origin = sf::Vector2f(_turtleSprite.getGlobalBounds().width / 2, _turtleSprite.getGlobalBounds().height / 2);
_turtleSprite.setOrigin(origin);
_rotation = 0;
}
Turtle::~Turtle() {}
void Turtle::Draw()
{
_data->window.draw(_turtleSprite);
}
void Turtle::Update(float dt)
{
if(_turtleState == TURTLE_STATE_FALLING)
{
_turtleSprite.move(0, GRAVITY * dt);
_rotation = 0;
}
else if(_turtleState == TURTLE_STATE_FLYING)
{
_turtleSprite.move(0, -FLYING_SPEED * dt);
_rotation = 0;
}
if(_movementClock.getElapsedTime().asSeconds() > FLYING_DURATION)
{
_turtleState = TURTLE_STATE_FALLING;
_movementClock.restart();
}
_turtleSprite.setRotation(_rotation);
}
void Turtle::Tap()
{
_turtleState = TURTLE_STATE_FLYING;
_movementClock.restart();
}
const sf::Sprite& Turtle::GetSprite() const
{
return _turtleSprite;
}
}