-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
149 lines (120 loc) · 3.39 KB
/
main.cpp
File metadata and controls
149 lines (120 loc) · 3.39 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
// main.cpp
#include <iostream>
#include <thread>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "Panel.h"
#include "Splashscreen.h"
#include "Menu.h"
#include "Game.h"
#include "Settings.h"
#include "Shop.h"
#include "Score.h"
#include "Account.h"
#include "Credits.h"
// #include <Windows.h>
#pragma warning (disable : 4244)
#pragma warning (disable : 4305)
#pragma warning (disable : 4018)
int main()
{
using namespace sf;
//Window variables
int ticks = 0;
// ::FreeConsole(); //Hide console
//Init window
MyWindow window(sf::VideoMode(1440, 810, 0), "SpaceGO", sf::Style::Close);
window.setFramerateLimit(60);
sf::Image image;
image.loadFromFile("images/icon.png");
window.setIcon(128,128, image.getPixelsPtr());
//Init music
sf::Music music;
if (!music.openFromFile("sounds/music.wav"))
{}
music.setLoop(true);
music.setVolume(0);
music.play();
//Init panels
int activePanel = 0;
std::vector<Panel*> panels;
panels.push_back(new Splashscreen(&window));
panels.push_back(new Menu(&window));
panels.push_back(new Game(&window));
panels.push_back(new Settings(&window));
panels.push_back(new Shop(&window));
panels.push_back(new Score(&window));
panels.push_back(new Account(&window));
panels.push_back(new Credits(&window));
//Program running
while (window.isOpen())
{
sf::Event event;
if (window.getConfig()->isMusicOn()) {
music.setVolume(window.getConfig()->getVolume());
}
else {
music.setVolume(0);
}
window.setVerticalSyncEnabled(window.getConfig()->isVsyncOn());
//Event manager
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.getConfig()->save();
window.close();
break;
case sf::Event::KeyPressed:
if (panels[activePanel]->keyPressedOnce(event.key.code) != -1) {
activePanel = panels[activePanel]->keyPressedOnce(event.key.code);
}
break;
case sf::Event::MouseButtonPressed:
if (panels[activePanel]->mouseClicked(event.mouseButton.x, event.mouseButton.y, event.mouseButton.button) >= 0) {
activePanel = panels[activePanel]->mouseClicked(event.mouseButton.x, event.mouseButton.y, event.mouseButton.button);
}
break;
case sf::Event::MouseMoved:
if (panels[activePanel]->mouseMove(event.mouseMove.x, event.mouseMove.y) >= 0) {
activePanel = panels[activePanel]->mouseMove(event.mouseMove.x, event.mouseMove.y);
}
break;
}
}
//Background animation
panels[activePanel]->moveBackground();
if (panels[activePanel]->getType() == Panel::PANEL_SPLASHSCREEN) {
ticks++;
if (ticks >= 30) {
panels[activePanel]->blink();
ticks = 0;
}
}
//Keys manager
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
panels[activePanel]->keyPressed(sf::Keyboard::Z);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
panels[activePanel]->keyPressed(sf::Keyboard::S);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
panels[activePanel]->keyPressed(sf::Keyboard::Q);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
panels[activePanel]->keyPressed(sf::Keyboard::D);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
panels[activePanel]->keyPressed(sf::Keyboard::Space);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::R)) {
panels[activePanel]->keyPressed(sf::Keyboard::R);
}
//Init view
window.clear();
panels[activePanel]->init();
window.display();
}
return 0;
}