-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.h
161 lines (139 loc) · 7.8 KB
/
system.h
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
#pragma once
#include <SFML/Graphics.hpp> //îñíîâíàÿ áèáëèîòåêà äëÿ ðàáîòû ñ ãðàôèêîé è èçîáðàæåíèåì
#include <SFML/Audio.hpp> //äëÿ ðàáîòû ñî çâóêîì è ìóçûêîé
#include <Windows.h> //íóæíà ÷òî á óçíàòü ðàçðåøåíèå ýêðàíà èãðîêà
using namespace std;
using namespace sf;
enum TypeState {unknown = -1, menu = 0, player, admin}; //òèï ñîñòîÿíèÿ èãðû
enum SubtypeState {launcher = 0, mode, settings, exitt, selectLVL, audioSetting, controlSeting, playerLVL, about, //0-8 //ïîäòèïû ñîñòîÿíèÿ èãðû
editLVL, openLVL, saveLVL, deleteLVL, listLVL, // 9-13
play, pause, startLVL, completeLVL, //14-17
wholeType, allState, loadingLVL}; //18-20
enum StatePlayer {rectangle, triangle, circle}; //ñîñòîÿíèå èãðîêà
enum CreateWall {rectangleW, triangleW, circleW, wall, finishW, startW, saveW}; //êàêîé òèï ñòåíû ñòàâèòñÿ èãðîêîì â àäìèí ìîäå â òåêóùèé ìîìåíò
class TileMap : public Drawable, public Transformable{ //êëàññ äëÿ ñîçäàíèÿ êàðòû
//ññûëêà íà ðåóñóðñ îòêóäà áûë âçÿò ýòîò êëàññ https://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php#example-tile-map
private:
VertexArray m_vertices;
Texture m_tileset;
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const{
states.transform *= getTransform ();
states.texture = &m_tileset;
target.draw (m_vertices, states);
}
public:
bool load(const string &tileset, Vector2u tileSize, const int *tiles, unsigned int width, unsigned int height, Vector2i size){
if (!m_tileset.loadFromFile (tileset))
return false;
m_vertices.setPrimitiveType (Quads);
m_vertices.resize (width * height * 4);
for (unsigned int i = 0; i < width; ++i)
for (unsigned int j = 0; j < height; ++j){
// get the current tile number
int tileNumber = tiles [i + j * width];
// find its position in the tileset texture
int tu = tileNumber / (m_tileset.getSize ().y / tileSize.y);
int tv = tileNumber % (m_tileset.getSize ().y / tileSize.y);
// get a pointer to the current tile's quad
sf::Vertex* quad = &m_vertices [(i + j * width) * 4];
// define its 4 corners
quad [0].position = Vector2f ((float) (i * size.x), (float) (j * size.y));
quad [1].position = Vector2f ((float) ((i + 1) * size.x), (float) (j * size.y));
quad [2].position = Vector2f ((float) ((i + 1) * size.x), (float) ((j + 1) * size.y));
quad [3].position = Vector2f ((float) (i * size.x), (float) ((j + 1) * size.y));
// define its 4 texture coordinates
quad [0].texCoords = Vector2f ((float) (tu * tileSize.x), (float) (tv * tileSize.y));
quad [1].texCoords = Vector2f ((float) ((tu + 1) * tileSize.x), (float) (tv * tileSize.y));
quad [2].texCoords = Vector2f ((float) ((tu + 1) * tileSize.x), (float) ((tv + 1) * tileSize.y));
quad [3].texCoords = Vector2f ((float) (tu * tileSize.x), (float) ((tv + 1) * tileSize.y));
}
return true;
}
};
class System{ //îñíîâíîé êëàññ èãðû, â êîòîðîì õðàíèòñÿ âñå ñàìûå âàæíûå ïåðåìåííûå, âñå îñòàëüíûå êëàññû íàñëåäóþòñÿ îò íåãî
public:
static bool F_gameIsLocked; //ôëàã, êîòîðûé ïîêàçûâàåò çàáëîêèðîâàíà ëè èãðà (åñëè èçìåíèëè íàñòðîéêè)
static bool F_musicOff; //ôëàã, êîòîðûé ïîêàçûâàåò âûêëþ÷åíà ëè ìóçûêà
static bool F_soundOff; //ôëàã, êîòîðûé ïîêàçûâàåò âûêëþ÷åíû ëè çâóêè
static bool F_lvlComplete; //ïîêàçûâàåò çàâåðøåí óðîâåíü
static bool F_changeStates; //ôëàã, êîòîðûé ïîêàçûâàåò, ìåíÿåòñÿ ëè ñîñòîÿíèå â äàííûé ìîìåíò
static float speedChangeSt; //ñêîðîñòü èçìåíåíèÿ ðàçìåðà êíîïîê ïðè èçìåíåíèè ñîñòîÿíèÿ
static float speed; //ñêîðîñòü ñ êîòîðîé äâèæåòñÿ èãðîê ïî óðîâíþ
static float timer; //òàéìåð
static float time; //âðåìÿ
static float volumeMusic; //ãðîìîêîñòü ôîíîâîé ìóçûêè
static float volumeSound; //ãðîìêîñòü çâóêà
static int FPS; //çíà÷åíèå ÔÏÑ
static int keyCodePressed; //êàêàÿ êëàâèøà áûëà íàæàòà
static int key [3]; //ìàññèâ â êîòîðîì õðàíÿòñÿ íîìåðà êëàâèø, êîòîðûå ìåíÿþò ôèãóðó
static int whatButChange; //ïðè íàæàòèè êëàâèøè, êàêàÿ êíîïêà èçìåíèò ñâî¸ çíà÷åíèå (êîãäà èãðîê íàñòðàèâàåò êëàâèøè èçìåíåíèÿ ôèãóðû)
static int passedLVL; //ñêîëüêî ïðîéäåíî óðîâíåé
static int* levelArray; //ìàññèâ â êîòîðîì õðàíèòñÿ êàðòà
static RenderWindow *window; //îêíî, â êîòîðîì çàïóñêàåòñÿ èãðà
static Event event; //ñîáûòèå
static Clock clock; //âðåìÿ
static Sound sndTeleport; //çâóê òåëåïîðòà èãðîêà ê ñîõðàíåíèþ
static Sound sndClickButt; //çâóê íàæàòèÿ íà êíîïêó
static Music backgroundMusic; //ôîíîâàÿ ìóçûêà
static SoundBuffer bufferClickButt; //áóôåð äëÿ çâóêà íàæàòèÿ íà êíîïêè
static SoundBuffer bufferTeleport; //áóôåð äëÿ çâóêà òåëåïîðòà èãðîêà ê ñîõðàíåíèþ
static String AdOrPlMode; //ñòðîêà õðàíÿùàÿ èìÿ òåêóùåãî ìîäà èãðû (èãðîê èëè àäìèí)
static Vector2i mousePosWin; //êîîðäèíàòû ìûøè îòíîñ. îêíà
static Vector2f posMouse; //êîîðäèíàòû ìûøè îòíîñ. êàðòû
static TileMap map; //êàðòà
static CreateWall whichWall; //êàêàÿ ñòåíà âûáðàíà àäìèíîì â äàííûé ìîìåíò
static Coordinate Start; //êîîðäèíàòû ñòàðòà (îòêóäà èãðîê ñòàðòóåò)
static Coordinate Finish; //êîîðäèíàòû ôèíèøà (êóäà äîëæåí ïðèäòè)
int W_WIN; //øèðèíà ðàçðåøåíèÿ ýêðàíà ïîëüçîâàòåëÿ
int H_WIN; //âûñîòà ðàçðåøåíèÿ ýêðàíà ïîëüçîâàòåëÿ
int INTERVAL; //ðàññòîÿíèå ìåæäó êíîïêàìè
int EDGE; //ðàçìåð îäíîé êëåòêè â àäìèí ìîäå
int NUM_CELL_X; //êîëè÷åñòâî êëåòîê â øèðèíó â óðîâíå
int NUM_CELL_Y; //êîëè÷åñòâî êëåòîê â âûñîòó â óðîâíå
int W_BUTTON; //øèðèíà êíîïîê
int H_BUTTON; //âûñîòà êíîïîê
int SIZE_TEXT; //ðàçìåð òåêñòà êíîïîê
int NUM_SQUARE; //êîëè÷åñòâî êâàäðàòîâ âèäèìûõ èãðîêó
int SQUARE; //ðàçìåð êâàäðàòà âèäèìîãî èãðîêó
int NUM_LVL; //êîëè÷åñòâî óðîâíåé
public:
System (){
W_WIN = GetSystemMetrics (0); H_WIN = GetSystemMetrics (1); //ïîëó÷àåì ðàçðåøåíèå ýêðàíà ïîëüçîâàòåëÿ
EDGE = 5; //ðàçìåð êëåòêè ïîëó÷àåì â öèêëå
NUM_CELL_X = 64; //êîëè÷åñòâî êëåòîê óðîâíÿ ïî øèðèíå
NUM_CELL_Y = 32; //êîëè÷åñòâî êëåòîê óðîâíÿ ïî âûñîòå
W_BUTTON = (int) (W_WIN / 8); //øèðèíà êíîïêè
H_BUTTON = H_WIN / 19; //âûñîòà êíîïêè
INTERVAL = H_BUTTON / 10; //ðàññòîÿíèå ìåæäó êíîïêàìè
SIZE_TEXT = (int) 30 * H_BUTTON / 44; //ðàçìåð òåêñòà íà êíîïêå
while (1){ //öèêë â êîòîðîì ìû ïîëó÷àåì îïòèìàëüíûé ðàçìåð êëåòêè (óâåëè÷èâàåì ðàçìåð, ïîêà ìû íå äîøëè äî ïðåäåëà ïî âûñîòå èëè øèðèíå)
if ((H_WIN - NUM_CELL_Y * EDGE) / 2 < H_BUTTON * 2 || (W_WIN - NUM_CELL_X * EDGE) / 2 < 60)
break;
EDGE++;
}
NUM_SQUARE = 8; //êîëè÷åñòâî êâàäðàòîâ âèäèìûõ íà ýêðàíå êîãäà èãðàåò èãðîê
SQUARE = EDGE * NUM_CELL_Y / NUM_SQUARE; //ðàçìåð îäíîãî òàêîãî êâàäðàòà
speed = (float) 3 * SQUARE; //ñêîëüêî èãðîê ïðîéäåò çà 1 ñåêóíäó êâàäðàòîâ
speedChangeSt = 200; //íà ñêîëüêî ïðîöåíòîâ óìåíüøèòñÿ êíîïêà çà 1 ñåêóíäó
NUM_LVL = 4; //êîëè÷åñòâî óðîâíåé
}
TypeState findType (SubtypeState tmpS){ //âñïîìîãàòåëüíàÿ ôóíêöèÿ íàõîæäåíèÿ òèïà çíàÿ ïîäòèï
if (tmpS > -1 && tmpS <= 8) return menu;
else if (tmpS > 8 && tmpS <= 13) return admin;
else if (tmpS > 13 && tmpS <= 17) return player;
else return unknown;
}
protected:
void changeBool (bool &tmpB){ //âñïîîìãàòåëüíàÿ ôóíêöèÿ, êîòîðàÿ ìåíÿåò áóëåâñêóþ ïåðåìåííóþ
if (tmpB) tmpB = false;
else tmpB = true;
}
void changeMusicVolume (float tmpV){ //âñïîìîãàòåëüíàÿ ôóíêöèÿ èçìåíåíèÿ ãðîìêîñòè ìóçûêè
backgroundMusic.setVolume (tmpV);
}
void changeSoundVolume (float tmpV){ //âñïîìîãàòåëüíàÿ ôóíêöèÿ èçìåíåíèÿ ãðîìêîñòè çâóêîâ
sndClickButt.setVolume (tmpV);
sndTeleport.setVolume (tmpV);
}
};