-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage.cpp
90 lines (76 loc) · 1.88 KB
/
stage.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "stage.h"
stage::stage()
{
}
stage::~stage()
{
}
void stage::freeButtons()
{
for(int i = 0; i < TOTAL_STAGE_BUTTONS; i++)
{
buttons[i].buttonTexture.free();
}
}
bool stage::setStageButtonTextures(SDL_Renderer* renderer, bool success)
{
for( int i = 0; i < TOTAL_STAGE_BUTTONS; ++i )
{
std::stringstream ss;
ss << "images/buttons/" << buttons[i].buttonName << ".png";
std::string str = ss.str();
success = buttons[i].buttonTexture.loadFromFile( str,renderer );
//buttons[ i ].setPosition( ((i*160)-80), SCREEN_HEIGHT - 140 );
}
//save and exit
buttons[0].setPosition(600,20);
return success;
}
void stage::setButtonNames()
{
for(int i = 0; i < TOTAL_STAGE_BUTTONS; i++)
{
buttons[i].setStageButtonName(i);
}
}
bool stage::setStageTextures(SDL_Renderer* renderer)
{
bool success = true;
setFileNames();
for(int i = 0; i<TOTAL_STAGE_BACKGROUNDS;i++)
{
success = stage1BG[i].loadFromFile( bgFileName[i],renderer );
}
return success;
}
void stage::setFileNames()
{
bgFileName[0] = "images/thanks.png";
}
void stage::freeBGTextures()
{
stage1BG[0].free();
}
bool stage::loadStage(SDL_Renderer* renderer, bool success)
{
setButtonNames();
//load stage button textures and positions
success = setStageButtonTextures(renderer,success);
//set stage bg texture
success = setStageTextures(renderer);
//load player texture
player1.loadPlayer(renderer);
return success;
}
void stage::free()
{
freeButtons();
freeBGTextures();
player1.freePlayer();
}
void stage::renderStage1(SDL_Renderer* renderer)
{
stage1BG[0].render(0,0,NULL,0.0,NULL,SDL_FLIP_NONE,renderer);
player1.render(renderer);
buttons[0].buttonTexture.render(buttons[0].getPositionX(),buttons[0].getPositionY(),NULL,0.0,NULL,SDL_FLIP_NONE,renderer);
}