#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 {
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;
}