-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpriteSheet.cpp
58 lines (56 loc) · 1.64 KB
/
SpriteSheet.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
#include "SpriteSheet.h"
using namespace sf;
using namespace std;
vector<Texture> SpriteSheet::flags;
vector<Texture> SpriteSheet::bombs;
bool SpriteSheet::loaded=false;
SpriteSheet::SpriteSheet()
{
int multiplier = rand()%5+1;
flagFramesRestart=60*multiplier;
if(!loaded){
loaded=true;
for(int i=0;i<flagCount;i++){
flags.push_back(Texture());
if(!flags[i].loadFromFile("images\\sprites\\flag\\"+to_string(i)+".png"))
throw std::runtime_error("could not load flag sprites");
flags[i].setSmooth(true);
}
for(int i=0;i<bombCount;i++){
bombs.push_back(Texture());
if(!bombs[i].loadFromFile("images\\sprites\\bomb\\"+to_string(i)+".png"))
throw std::runtime_error("could not load bomb sprites");
bombs[i].setSmooth(true);
}
}
}
Texture* SpriteSheet::getFlagTexture(){
if(flagFramesRestart == 0){
int index=flagIndex;
if(flagFramesPassed<=0){
flagFramesPassed=flagFrames;
this->flagIndex+=1;
this->flagIndex%=this->flagCount;
if(flagIndex==0){
int multiplier = rand()%5+1;
flagFramesRestart=60*multiplier;
}
}
flagFramesPassed--;
return &flags[index];
}
else{
flagFramesRestart--;
return &flags[0];
}
}
Texture* SpriteSheet::getBombTexture(){
int index=bombIndex;
if(bombFramesPassed<=0){
bombFramesPassed=bombFrames;
this->bombIndex+=1;
this->bombIndex%=this->bombCount;
}
bombFramesPassed--;
return &bombs[index];
}