-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
197 lines (158 loc) · 5.05 KB
/
main.cpp
File metadata and controls
197 lines (158 loc) · 5.05 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
#include <cstdlib>
#include "candyJar.hpp"
#include "SandJar.hpp"
#include "Menu.hpp"
using namespace std;
int main(int argc, char *argv[])
{
sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "");
int WIDTH = window.getSize().x;
int HEIGHT = window.getSize().y;
vector<Jar*> jars;
vector<Jar*> jarsComplete;
vector<Jar*> jarsNotComplete;
array<vector<Jar*>*, 3> jarTypes;
SandJar SJAR(5,WIDTH, HEIGHT, "im jar 1", "look at me");
SandJar SJAR2(5,WIDTH, HEIGHT, "im jar 2", "look at me");
SandJar SJAR3(5,WIDTH, HEIGHT, "im jar 3", "look at me");
SandJar SJAR4(5,WIDTH, HEIGHT, "im jar 4", "look at me");
SandJar SJAR5(5,WIDTH, HEIGHT, "im jar 5", "look at me");
SJAR2.move(300, 0);
SJAR3.move(600, 0);
SJAR4.move(900, 0);
SJAR5.move(1200, 0);
int curJar = 0;
int aToggle;
int jarType = 0;
bool menuShow = false;
bool up = true;
jars.push_back(&SJAR);
jars.push_back(&SJAR2);
jars.push_back(&SJAR3);
jars.push_back(&SJAR4);
jars.push_back(&SJAR5);
jarsNotComplete.push_back(&SJAR);
jarsNotComplete.push_back(&SJAR2);
jarsComplete.push_back(&SJAR);
jarTypes[0] = &jars;
jarTypes[1] = &jarsComplete;
jarTypes[2] = &jarsNotComplete;
Menu menu(WIDTH, HEIGHT);
int jarAddAnim = 0;
//Load background image
sf::Texture backTex;
if(!backTex.loadFromFile("background.png"))
return EXIT_FAILURE;
sf::Sprite background(backTex);
background.setScale((float) HEIGHT / backTex.getSize().y, (float) HEIGHT / backTex.getSize().y);
background.setOrigin(backTex.getSize().x/2, backTex.getSize().y/2);
background.setPosition(WIDTH / 2, HEIGHT / 2);
cout << WIDTH << " " << backTex.getSize().x;
//Set base background color
sf::Color backColor(146,214,255, 1);
sf::View view = window.getDefaultView();
sf::Font font;
if(!font.loadFromFile("CaviarDreams.ttf"))
{
throw "Cant locate font file";
}
sf::Text jarTitle;
jarTitle.setFont(font);
jarTitle.setCharacterSize(40); // in pixels, not points!
// set the color
jarTitle.setColor(sf::Color::Black);
jarTitle.setPosition(WIDTH / 2, HEIGHT / 4);
jarTitle.setStyle(sf::Text::Bold);
while (window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
}
if(sf::Touch::isDown(0))
{
sf::Vector2i position = sf::Touch::getPosition(0);
for(int i = 0; i < jarTypes[jarType]->size(); i++)
jarTypes[jarType]->at(i)->incAnim();
}
else {
// for(int i = 0; i < jars.size(); i++)
// jars[i]->decAnim();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
if(!menu.isShown() && aToggle == 1 && curJar < jarTypes[jarType]->size() - 1 == !jars[curJar]->isAnim())
{
for(int i = 0; i < jarTypes[jarType]->size(); i++)
jarTypes[jarType]->at(i)->move(-300, 0);
curJar++;
}
aToggle = 0;
}
else {
aToggle = 1;
}
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
sf::Vector2i position = sf::Mouse::getPosition(window);
int res = -1;
if(up)
{
res = menu.checkInput(position.x, position.y);
jarAddAnim = 50;
}
if(res == 0)//working clicked
{
jarType = 0;
curJar = 0;
}
else if(res == 1)//check clicked
{
jarType = 2;
curJar = 0;
}
else if(res == 2)//x clicked
{
jarType = 1;
curJar = 0;
}
up = false;
}
else
{
up = true;
// for(int i = 0; i < jarTypes[jarType]->size(); i++)
// jarTypes[jarType]->at(i)->decAnim();
}
if(jarAddAnim > 0)
{
jarTypes[jarType]->at(curJar)->incAnim();
jarAddAnim--;
}
else {
jarTypes[jarType]->at(curJar)->decAnim();
}
jarTitle.setString(jarTypes[jarType]->at(curJar)->getTitle());
sf::FloatRect textRect = jarTitle.getLocalBounds();
jarTitle.setOrigin(textRect.left + textRect.width/2.0f, textRect.top + textRect.height/2.0f);
jarTitle.setPosition(sf::Vector2f(WIDTH/2.0f,HEIGHT/5.0f));
window.clear(backColor);
window.draw(background);
for(int i = 0; i < jarTypes[jarType]->size(); i++)
jarTypes[jarType]->at(i)->draw(window);
window.draw(jarTitle);
menu.draw(window);
window.display();
}
}