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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
#include <stdlib.h>
#include <raylib.h>
#include "main.h"
#include <stdio.h>
#include <string.h>
ScreenType screentype = SettingsScreen;
int width = 1920;
int height = 1080;
int font_size = 12;
int master_level = 9;
int music_level = 9;
int sfx_level = 9;
Vector2 mouse_position = {0.0, 0.0};
// FPS Counters
bool show_fps = true;
int max_fps = 60;
int fps[] = {60,144,165,240,280,0};
int fps_counter = 0;
// Resolution
int widths[] = {1920, 1366, 2560 };
int heights[] = {1080, 768, 1440 };
int resolution_counter = 0;
// Vsync
bool vsync_check = false;
void LoadConfiguration() {
MakeDirectory("~/.config/raycar_lib");
}
void MainMenu() {
WriteDrawText("Astra", width / 2, height / 5, font_size * 10, BLACK);
WriteDrawText("Play", width / 2, height / 2, font_size * 5, BLACK);
Rectangle rec = MakeBtn(width/2, height/2 + (height/10), "Settings", font_size * 5, 25);
if (IsMouseInside(rec)) {
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) {
WriteDrawText("Settings", width / 2, height / 2 + (height / 10),
(font_size * 5 + 3), RED);
screentype = SettingsScreen;
} else {
WriteDrawText("Settings", width / 2, height / 2 + (height / 10),
font_size * 5, BLACK);
ClearBackground(RAYWHITE);
}
} else {
WriteDrawText("Settings", width / 2, height / 2 + (height / 10),
font_size * 5, BLACK);
}
/* rec = {width / 2 - MeasureText("Exit", font_size * 5), height /2 + (height / 5), MeasureText("Exit", font_size * 5), 80}; */
Rectangle exit_btn = MakeBtn(width/2, height/2 + (height/5), "Exit",font_size*5, 10);
if (CheckCollisionPointRec(mouse_position, exit_btn)) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
WriteDrawText("Exit", width / 2, height / 2 + (height / 5),
(font_size * 5 + 3), RED);
EndDrawing();
CloseWindow();
exit(0);
} else {
WriteDrawText("Exit", width / 2, height / 2 + (height / 5), font_size * 5,
BLACK);
}
} else {
WriteDrawText("Exit", width / 2, height / 2 + (height / 5), font_size * 5,
BLACK);
}
}
void SettingsMenu() {
WriteDrawText("Settings", width / 2, height / 2 - (height / 3),
(font_size * 3), BLACK);
WriteDrawText("Resolution", width / 2 - (width / 6),
height / 2 - (height / 4), (font_size * 2), BLACK);
Rectangle resolution_left_arrow = MakeBtn(((width / 2 + width / 5) - MeasureText("1920x108", font_size*2)), height / 2 - height / 4,
">", font_size * 2, 10);
Rectangle resolution_right_arrow = MakeBtn(((width / 2 + width / 5) + MeasureText("1920x108", font_size*2)), height / 2 - height / 4,
">", font_size * 2, 10);
WriteDrawText(TextFormat("< %ix%i >", widths[resolution_counter], heights[resolution_counter]),
width / 2 + (width / 5), height / 2 - (height / 4),
(font_size * 2), BLACK);
if (IsMouseInside(resolution_left_arrow)) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
if (resolution_counter == 0)
resolution_counter = 2;
else
resolution_counter--;
}
}
if (IsMouseInside(resolution_right_arrow)) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
resolution_counter = (resolution_counter + 1)% 3;
}
}
///////////////
// VSync
WriteDrawText("Vsync", width / 2 - (width / 6), height / 3.1, (font_size * 2),
BLACK);
Rectangle vsync_left_arrow = MakeBtn(((width / 2 + width / 5) - MeasureText("True", font_size*2)), height / 3.1 ,
">", font_size * 2, 10);
Rectangle vsync_right_arrow = MakeBtn(((width / 2 + width / 5) + MeasureText("True", font_size*2)), height / 3.1,
">", font_size * 2, 10);
if (vsync_check) {
WriteDrawText("< True >", width / 2 + (width / 5), height / 3.1, (font_size * 2), BLACK);
} else {
WriteDrawText("< False >", width / 2 + (width / 5), height / 3.1, (font_size * 2), BLACK);
}
if (IsMouseInside(vsync_left_arrow) || IsMouseInside(vsync_right_arrow)) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
vsync_check = !vsync_check;
}
}
///////////////
// FPS
WriteDrawText("FPS", width / 2 - (width / 6), height / 2.5, (font_size * 2),
BLACK);
Rectangle fps_left_arrow = MakeBtn(((width / 2 + width / 5) - MeasureText("144 ", font_size*2)), height / 2.5 ,
">", font_size * 2, 10);
Rectangle fps_right_arrow = MakeBtn(((width / 2 + width / 5) + MeasureText("144 ", font_size*2)), height / 2.5,
">", font_size * 2, 10);
WriteDrawText(TextFormat("< %i >", fps[fps_counter]),
width / 2 + (width / 5), height / 2.5, (font_size * 2), BLACK);
if (IsMouseInside(fps_left_arrow)) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
if (fps_counter == 0) {
fps_counter = 5;
} else {
fps_counter--;
}
}
}
if (IsMouseInside(fps_right_arrow)) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
fps_counter = (fps_counter + 1) % 6;
}
}
///////////////
WriteDrawText("Audio Level", width /2, height/2, (font_size * 3), BLACK);
// Master Level
WriteDrawText("Master Level", width / 2 - (width / 6),
height / 2 + (height / 10), (font_size * 2), BLACK);
/* Rectangle master_rec = {width / 2 + (width / 5), height / 2 + (height / 10), */
/* MeasureText("[]", font_size * 3) * master_level, */
/* font_size * 2, BLACK}; */
Rectangle master_rec = MakeRect(width/2+(width/5), height/2 + (height/10), MeasureText("[]", font_size * 3) * master_level, font_size*2);
Rectangle master_bg = MakeRect(width/2+(width/5), height/2 + (height/10), MeasureText("[]", font_size * 3) * 9, font_size*2);
DrawRectangleRec(master_bg, WHITE);
DrawRectangleRec(master_rec, BLACK);
if (IsMouseInside(master_bg)) {
float delta_mouse_scroll = GetMouseWheelMove();
if (delta_mouse_scroll < 0) {
if (master_level > 0) {
master_level--;
}
}
if (delta_mouse_scroll > 0) {
if (master_level < 9) {
master_level++;
}
}
}
//////////////
// Music Level
WriteDrawText("Music Level", width / 2 - (width / 6),
height / 2 + (height / 10) * 2, (font_size * 2), BLACK);
Rectangle music_rec = MakeRect(width/2+(width/5), height/2 + (height/10)*2, MeasureText("[]", font_size * 3) * music_level, font_size*2);
Rectangle music_bg = MakeRect(width/2+(width/5), height/2 + (height/10)*2, MeasureText("[]", font_size * 3) * 9, font_size*2);
DrawRectangleRec(music_bg, WHITE);
DrawRectangleRec(music_rec, BLACK);
if (IsMouseInside(music_bg)) {
float delta_mouse_scroll = GetMouseWheelMove();
if (delta_mouse_scroll < 0) {
if (music_level > 0) {
music_level--;
}
}
if (delta_mouse_scroll > 0) {
if (music_level < 9) {
music_level++;
}
}
}
//////////////
// SFX Level
WriteDrawText("SFX Level", width / 2 - (width / 6),
height / 2 + (height / 10) * 3, (font_size * 2), BLACK);
Rectangle sfx_rec = MakeRect(width/2+(width/5), height/2 + (height/10)*3, MeasureText("[]", font_size * 3) * sfx_level, font_size*2);
Rectangle sfx_bg = MakeRect(width/2+(width/5), height/2 + (height/10)*3, MeasureText("[]", font_size * 3) * 9, font_size*2);
DrawRectangleRec(sfx_bg, WHITE);
DrawRectangleRec(sfx_rec, BLACK);
if (IsMouseInside(sfx_bg)) {
float delta_mouse_scroll = GetMouseWheelMove();
if (delta_mouse_scroll < 0) {
if (sfx_level > 0) {
sfx_level--;
}
}
if (delta_mouse_scroll > 0) {
if (sfx_level < 9) {
sfx_level++;
}
}
}
//////////////
}
int main() {
SetConfigFlags(FLAG_VSYNC_HINT);
InitWindow(width, height, "Astra");
SetTargetFPS(max_fps);
LoadConfiguration();
while (!WindowShouldClose()) {
mouse_position = GetMousePosition();
if (show_fps) {
DrawFPS(5,5);
}
BeginDrawing();
ClearBackground(RAYWHITE);
switch (screentype) {
case MainScreen:
MainMenu();
break;
case SettingsScreen:
ClearBackground(RAYWHITE);
SettingsMenu();
break;
}
EndDrawing();
}
CloseWindow();
return 0;
}
|