From 8ba387dca8f6d8218dc01e3263a2581c258d6579 Mon Sep 17 00:00:00 2001 From: parking_turkeys Date: Thu, 23 Jul 2026 15:25:39 -0400 Subject: [PATCH] start screen!! which also has code for having multiple buttons bc i want to make that a thing that lets you change input maps... maybe ill do that now? --- main_v2.c | 1 + startgame.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/main_v2.c b/main_v2.c index 82473d4..34965be 100644 --- a/main_v2.c +++ b/main_v2.c @@ -31,6 +31,7 @@ int main(void) case STARTGAMEMODE: ZeichnenAnfangen(); drawstartgame(); + handlebuttons(); ZeichnenAufhören(); break; case LEVELMODE: diff --git a/startgame.c b/startgame.c index 6c5098f..9076d44 100644 --- a/startgame.c +++ b/startgame.c @@ -4,6 +4,9 @@ #define BUTTONCOUNT 1 +//label names +#define STARTGAMELABEL "START" + static int drawbutton(char *text, Rectangle *rect, Color colour, Color outline_colour, Color text_colour); struct button { @@ -13,31 +16,70 @@ struct button { struct button buttons[BUTTONCOUNT] = {0}; -int checkbuttonsmouse(int *is_clicked[]); -int checkbuttonskbd(int *is_clicked[]); +int checkbuttonsmouse(int (*is_clicked)[BUTTONCOUNT]); +int checkbuttonskbd(int (*is_clicked)[BUTTONCOUNT]); int handlebuttons(void) { int is_clicked[BUTTONCOUNT] = {0}; //check mouse clicks checkbuttonsmouse(&is_clicked); - + //printf("mouse clicks CHECKED\n"); //check wasd/r clicks checkbuttonskbd(&is_clicked); + + for (int i = 0; i < BUTTONCOUNT; i++) { + if (is_clicked[i] == 1) { + if (buttons[i].label == STARTGAMELABEL) { + mode = 1; + }; + }; + }; }; -int checkbuttonsmouse(int *c[]) +int checkbuttonsmouse(int (*c)[BUTTONCOUNT]) { - // + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + for (int i = 0; i < BUTTONCOUNT; i++) { + if (CheckCollisionPointRec((Vector2){GetMouseX(),GetMouseY()}, *buttons[i].rect)) { + (*c)[i] = 1; + }; + }; + }; }; +int checkbuttonskbd(int (*i)[BUTTONCOUNT]) +{ + static int s_i = 0; //selected index + //draw select on selected one + + DrawRectangleLinesEx(*buttons[s_i].rect,5,RED); + int c = 0; + while ((c = GetKeyPressed()) != 0) { + if (c == inputs[0]) { //left + s_i -= 1; + if (s_i < 0) { + s_i = BUTTONCOUNT- 1; + }; + } else if (c == inputs[1]) { //right + s_i += 1; + if (s_i == BUTTONCOUNT) { + s_i = 0; + }; + } else if (c == inputs[5]) { //interact/select + (*i)[s_i] = 1; + }; + }; + +} + int drawstartgame(void) { ClearBackground(BLUE); //printf("%d\n", MeasureText("Ai-chan platformer", 50)); DrawText("Ai-chan platformer", 80,80,50,GREEN); - drawbutton("START", &(struct Rectangle){100,150,440,80}, GREEN, WHITE, WHITE); + drawbutton(STARTGAMELABEL, &(struct Rectangle){100,150,440,80}, GREEN, WHITE, WHITE); return 1; } -- 2.47.3