From 6c8965f31bcdf40c790f75c25279ddef05e27a83 Mon Sep 17 00:00:00 2001 From: parking_turkeys Date: Thu, 23 Jul 2026 14:29:46 -0400 Subject: [PATCH] finish end screen, start start screen (i think i forgor to commit halp) --- endscreen.c | 29 ++++++++++++++++++++++++ game.h | 14 +++++++++++- main_v2.c | 21 ++++++++++++++++- startgame.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 endscreen.c create mode 100644 startgame.c diff --git a/endscreen.c b/endscreen.c new file mode 100644 index 0000000..e913e44 --- /dev/null +++ b/endscreen.c @@ -0,0 +1,29 @@ +#include "raylib.h" +#include "game.h" +#include + +struct time { + int min; + int sec; +}; + +static struct time *formattime(int seconds); + +int drawendscreen(int seconds) +{ + //printf("Time to draw an end screen :)"); + ClearBackground(RAYWHITE); + DrawText("Game End",80,80,100,BLACK); + struct time *gametime = formattime(seconds); + //printf("time to draw the gametime"); + DrawText(TextFormat("Time: %02d:%02d",gametime->min,gametime->sec),80,240,20, GRAY); + return 1; +}; + +static struct time *formattime(int s) +{ + struct time *t = &(struct time){0,0}; + t->min = s/60; //integer division rounds towards 0 + t->sec = s - t->min * 60; //fairly simple :p + return t; +} diff --git a/game.h b/game.h index 739b155..24cb96e 100644 --- a/game.h +++ b/game.h @@ -15,7 +15,13 @@ #define FRAMELENGTH 0.1 #define JUMPVELOCITY -160 -#define LEVELS 3 +#define LEVELS 10 + +//these are for the "mode" variable + +#define STARTGAMEMODE 0 +#define LEVELMODE 1 +#define ENDSCREENMODE 2 struct character *spielersetup(void); int next_level(struct character *player); @@ -39,6 +45,10 @@ int is_killed(struct Rectangle *rect); int level_cleanup(void); int player_cleanup(void); +int drawstartgame(void); +int handlebuttons(void); +int drawendscreen(int game_seconds); + //structures struct character { struct Rectangle rect; @@ -91,3 +101,5 @@ struct spritesheet { extern int level; extern int frozen; extern int objects_interacted[]; +extern int mode; +extern int inputs[]; diff --git a/main_v2.c b/main_v2.c index a299b3b..82473d4 100644 --- a/main_v2.c +++ b/main_v2.c @@ -12,6 +12,8 @@ int level = 9; int frozen = 0; //0:game, 1:stage dialogue, 2+:object[frozen-2] dialogue +int mode = 0; //0:'start game', 1: 'levels', 2:'end screen' (later: 2 will be bossfight and 3 will be end screen lol) +int fullsectime = 0; int main(void) { @@ -25,7 +27,13 @@ int main(void) frozen= 1; //for dialogue while (!WindowShouldClose()) { - //variables. + switch (mode) { + case STARTGAMEMODE: + ZeichnenAnfangen(); + drawstartgame(); + ZeichnenAufhören(); + break; + case LEVELMODE: if (!frozen) {variables(GetFrameTime(), player);}; ZeichnenAnfangen(); bühnezeichnen(); @@ -35,6 +43,13 @@ int main(void) DrawRectangle(1, 0, 45, 12, WHITE); DrawText(TextFormat("Seconds played: %5.2f", GetTime()), 2, 0, 10, BLACK); ZeichnenAufhören(); + break; + case ENDSCREENMODE: + ZeichnenAnfangen(); + drawendscreen(fullsectime); + ZeichnenAufhören(); + break; + }; } CloseWindow(); @@ -57,6 +72,10 @@ int next_level(struct character *player) frozen = 1; //printf("set frozen\n"); player->rect.x = 0; player->rect.y = 300; + if (level == LEVELS) { + mode = ENDSCREENMODE; + fullsectime = GetTime(); + }; return 1; } diff --git a/startgame.c b/startgame.c new file mode 100644 index 0000000..6c5098f --- /dev/null +++ b/startgame.c @@ -0,0 +1,65 @@ +#include "raylib.h" +#include "game.h" +#include + +#define BUTTONCOUNT 1 + +static int drawbutton(char *text, Rectangle *rect, Color colour, Color outline_colour, Color text_colour); + +struct button { + Rectangle *rect; + char *label; +}; + +struct button buttons[BUTTONCOUNT] = {0}; + +int checkbuttonsmouse(int *is_clicked[]); +int checkbuttonskbd(int *is_clicked[]); + +int handlebuttons(void) +{ + int is_clicked[BUTTONCOUNT] = {0}; + //check mouse clicks + checkbuttonsmouse(&is_clicked); + + + //check wasd/r clicks + checkbuttonskbd(&is_clicked); +}; + +int checkbuttonsmouse(int *c[]) +{ + // +}; + +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); + + return 1; +} + +static int drawbutton(char *t, Rectangle *r, Color c, Color o, Color t_c) +{ + static int i = 0; + DrawRectangleRec(*r,c); + DrawRectangleLinesEx(*r,5,o); + int t_s, t_x, t_y; //text size, x, and y + int n_w = r->width - 20; //needed width + t_s = r->height - 20; + t_x = r->x + 10; + t_y = r->y + 10; + while (MeasureText(t,t_s) > n_w) + { + t_s -= 1; + }; + t_x += (n_w - MeasureText(t,t_s))/2; + DrawText(t, t_x, t_y, t_s, t_c); + if (i != BUTTONCOUNT) { + buttons[i] = (struct button){r,t}; + i++; + }; +}; -- 2.47.3