parent
f84124e768
commit
732efea2d3
@ -0,0 +1,66 @@
|
|||||||
|
#include "buttons.h"
|
||||||
|
#include "../game.h"
|
||||||
|
#include "screenIDs.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
void executeButton(Button *button, Game *game){
|
||||||
|
button->state = 0;
|
||||||
|
switch(button->id){
|
||||||
|
case 0: // continue game
|
||||||
|
if(game->screen == SCREEN_PAUSE){
|
||||||
|
game->screen = SCREEN_GAME;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawButton(Button * button){
|
||||||
|
printf("%d\n", button->state);
|
||||||
|
updateButtonState(button);
|
||||||
|
printf("DRAW JETZT\n");
|
||||||
|
DrawTexture(*button->textures[button->state], button->position.x, button->position.y, WHITE);
|
||||||
|
printf("funktioniert\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int updateButtonState(Button * button){
|
||||||
|
if(GetMouseX() > button->position.x &&
|
||||||
|
GetMouseX() < button->position.x + button->textures[button->state]->width &&
|
||||||
|
GetMouseY() > button->position.y &&
|
||||||
|
GetMouseY() < button->position.y + button->textures[button->state]->height
|
||||||
|
){
|
||||||
|
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){
|
||||||
|
button->state = 2;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
button->state = 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
button->state = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isButtonHovered(Button * button){
|
||||||
|
if(GetMouseX() > button->position.x &&
|
||||||
|
GetMouseX() < button->position.x + button->textures[0]->width &&
|
||||||
|
GetMouseY() > button->position.y &&
|
||||||
|
GetMouseY() < button->position.y + button->textures[0]->height
|
||||||
|
){
|
||||||
|
return button->state = 1;
|
||||||
|
}
|
||||||
|
return button->state = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isButtonPressed(Button * button){
|
||||||
|
if(GetMouseX() > button->position.x &&
|
||||||
|
GetMouseX() < button->position.x + button->textures[0]->width &&
|
||||||
|
GetMouseY() > button->position.y &&
|
||||||
|
GetMouseY() < button->position.y + button->textures[0]->height
|
||||||
|
){
|
||||||
|
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
|
||||||
|
return button->state = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return button->state = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef BUTTONS_H_
|
||||||
|
#define BUTTONS_H_
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "../game.h"
|
||||||
|
|
||||||
|
typedef struct Button{
|
||||||
|
Texture2D *textures[3]; // [0]: Normal [1]: Hovered [2]: Pressed
|
||||||
|
Vector2 position;
|
||||||
|
//char text[20];
|
||||||
|
int state; // 0: default 1: hovered 2: pressed
|
||||||
|
int id;
|
||||||
|
} Button;
|
||||||
|
|
||||||
|
// executes the logic of one button of certain id - huge switch?
|
||||||
|
void executeButton(Button *button, Game * game);
|
||||||
|
|
||||||
|
int updateButtonState(Button * button);
|
||||||
|
|
||||||
|
void drawButton(Button * button);
|
||||||
|
|
||||||
|
int isButtonPressed(Button * button);
|
||||||
|
|
||||||
|
int isButtonHovered(Button * button);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 8.3 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in new issue