--- /dev/null
+#include "raylib.h"
+#include "game.h"
+#include <stdio.h>
+
+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;
+}
#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);
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;
extern int level;
extern int frozen;
extern int objects_interacted[];
+extern int mode;
+extern int inputs[];
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)
{
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();
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();
frozen = 1;
//printf("set frozen\n");
player->rect.x = 0; player->rect.y = 300;
+ if (level == LEVELS) {
+ mode = ENDSCREENMODE;
+ fullsectime = GetTime();
+ };
return 1;
}
--- /dev/null
+#include "raylib.h"
+#include "game.h"
+#include <stdio.h>
+
+#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++;
+ };
+};