diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 222 |
1 files changed, 222 insertions, 0 deletions
@@ -0,0 +1,222 @@ +#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); + + + /* DrawRectangle(width/2 + (width/5) - font_size*2, height/2+(height/10), MeasureText("[]", font_size*2)*master_level, font_size*2, BLACK); */ + x + ////////////// + + // Music Level + WriteDrawText("Music Level", width / 2 - (width / 6), + height / 2 + (height / 10) * 2, (font_size * 2), BLACK); + + WriteDrawText(sound_level[music_level], width/2+(width/5), height/2+(height/10)*2, (font_size*2), BLACK); + + ////////////// + + // SFX Level + WriteDrawText("SFX Level", width / 2 - (width / 6), + height / 2 + (height / 10) * 3, (font_size * 2), BLACK); + + WriteDrawText(sound_level[sfx_level], width/2+(width/5), height/2+(height/10)*3, (font_size*2), BLACK); + ////////////// +} + +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; +} |
