diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | TODO.md | 2 | ||||
| -rw-r--r-- | helpers.h | 43 | ||||
| -rw-r--r-- | main.c | 90 |
4 files changed, 111 insertions, 26 deletions
@@ -1,5 +1,5 @@ main: main.c helpers.h ante.h - gcc main.c -lraylib -o output/main + gcc main.c -lraylib -lm -o output/main ./output/main @@ -1,6 +1,6 @@ [] Cmatrix for the Title Menu Background [] find a wood-click sfx for clicks -[] make the binary texture for the music bars + [] make the binary texture for the music bars [] Make the Menu Screen Work [] Try Anchoring the insides of Each rectangle, to the rectangle. -- Done @@ -1,31 +1,64 @@ #include <string.h> +#include <math.h> #define TEXT_FONT text_font + +// TEXT Helpers #define WriteDrawText(text, posX, posY, fontSize, color) \ DrawText(text, posX - (MeasureText(text, fontSize) / 2), posY, fontSize, \ color); -#define WriteDrawTextFont(font, text, posX, posY, fontSize, spacing, color) DrawTextEx(font, text, (Vector2){(posX - MeasureTextEx(font, text, fontSize, spacing).x/2), posY}, fontSize, spacing, color); +#define WriteDrawTextFont(font, text, posX, posY, fontSize, spacing, color) \ +DrawTextEx(font, text, (Vector2){(posX - MeasureTextEx(font, text, fontSize, spacing).x/2), posY}, fontSize, spacing, color); -#define WriteText(text, posX, posY, fontSize, color) DrawTextEx(TEXT_FONT, text, (Vector2){(posX - MeasureTextEx(TEXT_FONT, text, fontSize, 0).x/2), posY}, fontSize, 0, color); +#define WriteText(text, posX, posY, fontSize, color) \ + DrawTextEx(TEXT_FONT, text, (Vector2){(posX - MeasureTextEx(TEXT_FONT, text, fontSize, 0).x/2), posY}, fontSize, 0, color); +/////////////// -#define DrawRect(posX,posY,width,height,color) DrawRectangle(posX - width/2, posY, width, height, color); +// Rectangle Helpers #define MakeRect(posX, posY, width, height) {posX - width/2, posY, width, height}; +#define MakeBtn(posX, posY, txt, fontSize, padding) \ + { \ + posX - MeasureText(txt, fontSize) / 2 - padding, \ + posY - padding, MeasureText(txt, fontSize) + padding * 2, fontSize + padding * 2} -#define MakeBtn(posX, posY, txt, fontSize, padding) {posX - MeasureText(txt, fontSize) / 2 - padding, posY - padding, MeasureText(txt, fontSize) + padding * 2, fontSize + padding * 2} +#define DrawRect(posX, posY, width, height, color) \ + DrawRectangle(posX - width/2, posY, width, height, color); +#define DrawRectangleDropShadow(posX,posY,width,height,color) +#define DrawRectangleRecDropShadow(rec, color, angle, shadow_distance) \ + DrawRectangle(rec.x - rec.width/2 + shadow_distance, rec.y + (sin(angle)*shadow_distance), rec.width, rec.height, (Color){0,0,0,225}); \ + DrawRectangleRec(rec, color); #define IsMouseInside(rec) CheckCollisionPointRec(mouse_position, rec) +//////////////////// + typedef enum ScreenType { TitleScreen, SettingsScreen, GameStartScreen } ScreenType; + +typedef enum Position { + LEFT_TOP, + MIDDLE_TOP, + RIGHT_TOP, + LEFT_CENTER, + MIDDLE_CENTER, + RIGHT_CENTER, + LEFT_BOTTOM, + MIDDLE_BOTTOM, + RIGHT_BOTTOM, + FILL, +} Position; + +// Function Defenitions void MainMenu(); void SettingsMenu(); void LoadConfiguration(); void WriteConfiguration(); void SetVariables(char* line); - +void GameStart(); +void WriteTextInsideRectangle(struct Rectangle rec, Position pos, char* text, int font_size, int padding, struct Color color); @@ -4,7 +4,7 @@ #include <unistd.h> #include <stdio.h> #include <string.h> - +#include <math.h> #include "helpers.h" #include "ante.h" @@ -31,9 +31,15 @@ int widths[] = {1920, 1366, 2560 }; int heights[] = {1080, 768, 1440 }; int resolution_counter = 0; + // Vsync bool vsync_check = false; +// ante_count +int ante_count = 0; + + +char file_path[1024]; #define BTN_PADDING 25 void MainMenu() { @@ -348,17 +354,13 @@ void SetVariables(char *line) { void LoadConfiguration() { // Make a config directory - chdir(getenv("HOME")); - int check = mkdir(".config/raycar", 0777); - - chdir(".config/raycar"); /* Make a file */ - FILE *fptr = fopen("settings.conf", "rw"); + FILE *fptr = fopen(file_path, "rw"); if (!fptr) { fptr = fopen("settings.conf", "w"); - printf("INFO: Couldn't read the file\n"); WriteConfiguration(); + printf("INFO: Couldn't read the file, So Write Configuration\n"); return; } @@ -382,12 +384,7 @@ void LoadConfiguration() { void WriteConfiguration() { - chdir(getenv("HOME")); - int check = mkdir(".config/raycar", 0777); - - chdir(".config/raycar"); - - FILE *fptr = fopen("settings.conf", "w"); + FILE *fptr = fopen(file_path, "w"); char buf[1024] = ""; char *vsync_string = "false"; if (vsync_check) { @@ -414,19 +411,74 @@ void GameStart() { Rectangle right_rect = MakeRect(width / 2 + width / (3), height / 10, width / 3.5, height - height / 5); - - DrawRectangleRec(left_rect, BLACK); - DrawRectangleRec(middle_rect, BLACK); - DrawRectangleRec(right_rect, BLACK); + + DrawRectangleRec(left_rect, (Color){50,50,50, 255}); + DrawRectangleRec(middle_rect, (Color){50,50,50, 255}); + DrawRectangleRec(right_rect, (Color){50,50,50, 255}); + + /* WriteTextInsideRectangle(left_rect, MIDDLE_TOP, "<~ KiloByte ~>", font_size*2, 20, WHITE); */ + /* WriteTextInsideRectangle(middle_rect, FILL, "<~ KiloByte ~>", font_size*2, 20, WHITE); */ + /* if (ante_count < 12) { */ + /* ante_count +=3; */ + /* } */ +} + +void WriteTextInsideRectangle(Rectangle rec, Position pos, char *text, + int font_size, int padding, Color color) { + int x = rec.x; + int y = rec.y; + int w = rec.width; + int h = rec.height; + switch (pos) { + case LEFT_TOP: + WriteText(text, x + MeasureText(text, font_size),y+padding,font_size, color); + break; + case MIDDLE_TOP: + WriteText(text, x + w/2,y+padding,font_size, color); + break; + case RIGHT_TOP: + WriteText(text, x + w - MeasureText(text, font_size),y+padding,font_size, color); + break; + case LEFT_CENTER: + WriteText(text, x + MeasureText(text, font_size),y+h/2,font_size, color); + break; + case MIDDLE_CENTER: + WriteText(text, x + w/2,y+h/2,font_size, color); + break; + + case RIGHT_CENTER: + WriteText(text, x + w - MeasureText(text, font_size),y+h/2,font_size, color); + break; + case LEFT_BOTTOM: + WriteText(text, x + MeasureText(text, font_size),y+h-padding-font_size,font_size, color); + break; + case MIDDLE_BOTTOM: + WriteText(text, x + w/2,y+h-padding-font_size,font_size, color); + break; + case RIGHT_BOTTOM: + WriteText(text, x + w - MeasureText(text, font_size), y + h - padding - font_size, + font_size, color); + break; + case FILL: + WriteText(text, x+MeasureTextEx(TEXT_FONT, text, font_size, 0).x/2,y,font_size,color); + break; + } } int main() { + char *home = (getenv("HOME")); + + char dir_path[1024]; + sprintf(dir_path, "%s/.config/leetaro/", home); + mkdir(dir_path, 0777); + sprintf(file_path, "%s/.config/leetaro/settings.conf", home); LoadConfiguration(); if(vsync_check){ SetConfigFlags(FLAG_VSYNC_HINT); } InitWindow(width, height, "Leetaro"); - title_font = LoadFontEx("/home/san/code/raylib_car/assets/Pixelout.ttf", 32, NULL,0); - text_font = LoadFontEx("/home/san/code/raylib_car/assets/alagard.ttf", 48, NULL,0); + + title_font = LoadFontEx("./assets/Pixelout.ttf", 32, NULL,0); + text_font = LoadFontEx("./assets/alagard.ttf", 48, NULL,0); SetTargetFPS(max_fps); while (!WindowShouldClose()) { mouse_position = GetMousePosition(); |
