-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTechShop.cpp
172 lines (146 loc) · 4.18 KB
/
TechShop.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "TechShop.h"
TechShop::TechShop() {
cash = 100;
tab.LoadFromFile("Shop/tab.png");
bg1.LoadFromFile("Shop/bg1.png");
bg2.LoadFromFile("Shop/bg2.png");
bg3.LoadFromFile("Shop/bg3.png");
/*
* Font acquired from openfontlibrary.org
* ANARCHY SANS BY DOCTOR WAT
* http://openfontlibrary.org/font/anarchy-sans
* Font is available for use under free license
*/
font.LoadFromFile("AnarchySans.otf");
//currTechs = new std::vector<Technique>();
techs = new std::vector<Technique>();
currType = 1;
}
TechShop::TechShop(std::vector<Technique>* listOfTechs) {
techs = listOfTechs;
cash = 100;
tab.LoadFromFile("Shop/tab.png");
bg1.LoadFromFile("Shop/bg1.png");
bg2.LoadFromFile("Shop/bg2.png");
bg3.LoadFromFile("Shop/bg3.png");
/*
* Font acquired from openfontlibrary.org
* ANARCHY SANS BY DOCTOR WAT
* http://openfontlibrary.org/font/anarchy-sans
* Font is available for use under free license
*/
font.LoadFromFile("AnarchySans.otf");
techs = new std::vector<Technique>();
currType = 1;
}
TechShop::~TechShop() {
delete currTechs;
delete techs;
}
// add the amount of cash desired
void TechShop::addCash(int amount) {
cash += amount;
}
// unlock a tech and subtract its cost from total amount
// throw an error if you have insufficient funds
void TechShop::unlockTech(int id) {
for(std::vector<Technique>::iterator it = techs->begin(); it != techs->end(); ++it) {
Technique temp = *it;
if (temp.getId() == id) {
if (cash - temp.getCost() >= 0) {
cash -= temp.unlock();
}
}
}
}
void TechShop::addTech(Technique* tech) {
techs->push_back(*tech);
}
// returns techs based on the level given
std::vector<Technique>* TechShop::getPage(int level) {
std::vector<Technique>* oneList;
for(std::vector<Technique>::iterator it = techs->begin(); it != techs->end(); ++it) {
Technique temp = *it;
if (temp.getLevel() == level) {
oneList->push_back(temp);
}
}
return oneList;
}
// draws the shop on the screen
void TechShop::drawShop(sf::RenderWindow* window) {
if (currType == BEGINNER) {
// draw the tab
sf::Sprite sp_tab;
sp_tab.SetImage(tab);
sp_tab.SetPosition(0.0, 0.0);
window->Draw(sp_tab);
// draw the correct background
sf::Sprite sp_bg;
sp_tab.SetImage(bg1);
sp_tab.SetPosition(0.0, 70.0);
window->Draw(sp_bg);
// overlay the techniques onto the background
std::vector<Technique>* tmp = TechShop::getPage(1);
// write techniques
for (int i = 0; i < tmp->size(); i++) {
Technique temp = tmp->at(i);
sf::String techn;
techn.SetText(temp.getName());
techn.SetFont(font);
techn.SetSize(24);
techn.Move(30.f, 80.f + i*40.f);
window->Draw(techn);
}
} else if (currType == INTERMEDIATE) {
// draw the tab
sf::Sprite sp_tab;
sp_tab.SetImage(tab);
sp_tab.SetPosition(0.0, 0.0);
window->Draw(sp_tab);
// draw the correct background
sf::Sprite sp_bg;
sp_tab.SetImage(bg2);
sp_tab.SetPosition(0.0, 70.0);
window->Draw(sp_bg);
// overlay the techniques onto the background
std::vector<Technique>* tmp = TechShop::getPage(2);
// write techniques
for (int i = 0; i < tmp->size(); i++) {
Technique temp = tmp->at(i);
sf::String techn;
techn.SetText(temp.getName());
techn.SetFont(font);
techn.SetSize(24);
techn.Move(30.f, 80.f + i*40.f);
window->Draw(techn);
}
} else if (currType == ADVANCED) {
// draw the tab
sf::Sprite sp_tab;
sp_tab.SetImage(tab);
sp_tab.SetPosition(0.0, 0.0);
window->Draw(sp_tab);
// draw the correct background
sf::Sprite sp_bg;
sp_tab.SetImage(bg3);
sp_tab.SetPosition(0.0, 70.0);
window->Draw(sp_bg);
// overlay the techniques onto the background
std::vector<Technique>* tmp = TechShop::getPage(2);
// write techniques
for (int i = 0; i < tmp->size(); i++) {
Technique temp = tmp->at(i);
sf::String techn;
techn.SetText(temp.getName());
techn.SetFont(font);
techn.SetSize(24);
techn.Move(30.f, 80.f + i*40.f);
window->Draw(techn);
}
}
}
// switches the shop screen
void TechShop::switchScreen(int type) {
currTechs = TechShop::getPage(type);
}