-
Notifications
You must be signed in to change notification settings - Fork 0
/
Goomba.cpp
76 lines (63 loc) · 2.44 KB
/
Goomba.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
65
66
67
68
69
70
71
72
73
74
75
76
#include "Goomba.hpp"
#include "DEFINITIONS.h"
namespace ArktisProductions
{
Goomba::Goomba(GameDataRef data) :_data(data)
{
_animationIterator = 0;
}
void Goomba::Animate(float dt)
{
float how_many_frames = 2.0f; // It means there are 4 animation states (4 different textures)
if(_clock.getElapsedTime().asSeconds() > GOOMBA_ANIMATION_DURATION / how_many_frames) // Make jump anim.
{
if (_animationIterator < how_many_frames-1)
this->_animationIterator++;
else
this->_animationIterator = 0;
for (unsigned short int i=0; i < goombaSprites.size(); i++)
this->goombaSprites.at(i).setTexture(this->_data->assets.GetTexture("Goomba_" + std::to_string(_animationIterator)));
this->_clock.restart();
}
}
void Goomba::SpawnAGoomba()
{
sf::Sprite sprite(this->_data->assets.GetTexture("Goomba_0")); // TODO: Import goomba textures and name them
// Just like that - goomba_0, goomba_1 etc.
sprite.setPosition(FIXED_PLATFORM_X_COORDINATE, SCREEN_HEIGHT-(216+128)); // 216
this->goombaSprites.push_back(sprite);
}
void Goomba::MoveGoombas(float dt)
{
for (unsigned short int i = 0; i < goombaSprites.size(); i++)
{
if (this->goombaSprites.at(i).getPosition().x < 0 - this->goombaSprites.at(i).getGlobalBounds().width)
this->goombaSprites.erase(goombaSprites.begin()+i);
else
{
// sf::Vector2f position = platformSprites.at(i).getPosition();
float mvmt = GOOMBA_MVMT_SPEED * dt;
this->goombaSprites.at(i).move(-mvmt, 0);
}
}
}
void Goomba::DeleteGoomba(unsigned short int index)
{
this->goombaSprites.erase(goombaSprites.begin() + index);
}
void Goomba::DrawGoombas()
{
for (unsigned short int i = 0; i < goombaSprites.size(); i++)
this->_data->window.draw(goombaSprites.at(i));
}
void Goomba::PurgeGoombas()
{
this->_animationIterator = 0;
this->goombaSprites.clear();
this->_clock.restart();
}
const std::vector<sf::Sprite> &Goomba::GetSprites() const
{
return this->goombaSprites;
}
}