diff --git a/Ui/button.c b/Ui/button.c index 4e77dac..e62a877 100644 --- a/Ui/button.c +++ b/Ui/button.c @@ -6,27 +6,28 @@ #include "raylib.h" #include "string.h" -Button * InitButton(Texture2D textures[3], Vector2 *position, char *text, int textLEN, int id){ +Button * ButtonInitButton(Texture2D textures[4], Vector2 *position, char *text, int textLEN, int id){ Button *button = malloc(sizeof(Button)); button->textures[0] = textures[0]; button->textures[1] = textures[1]; button->textures[2] = textures[2]; + button->textures[3] = textures[3]; button->position = (Vector2){position->x, position->y}; button->centerPosition = (Vector2){position->x + textures[0].width/2, position->y + textures[0].height/2}; strncpy(button->text, text, textLEN); - button->state = 0; + button->state = BUTTON_STATE_DEFAULT; button->id = id; return button; } void ButtonExecuteButton(Button *button, Game *game){ - button->state = 0; + button->state = BUTTON_STATE_DEFAULT; switch(button->id){ - case 0: // continue game + case BUTTON_ID_CONTINUE: // continue game if(game->screen == SCREEN_PAUSE){ game->screen = SCREEN_GAME; } @@ -35,49 +36,30 @@ void ButtonExecuteButton(Button *button, Game *game){ } void ButtonDrawButton(Button * button){ - ButtonUpdateButtonState(button); + // erst Button Texture, dann Text zentriert drauf DrawTexture(button->textures[button->state], button->position.x, button->position.y, WHITE); DrawText(button->text, button->centerPosition.x - MeasureText(button->text, BUTTON_FONT_SIZE)/2, button->centerPosition.y - BUTTON_FONT_SIZE/2, BUTTON_FONT_SIZE, BLACK); } int ButtonUpdateButtonState(Button * button){ - if(GetMouseX() > button->position.x && + if(button->state == BUTTON_STATE_RELEASED){ + // Wir verlassen den RELEASED State automatisch wenn wir den Code des Buttons ausführen, siehe ButtonExecuteButton + // So lange der Code nicht ausgeführt wurde bleiben wir im state damit er definitiv im nächsten Frame ausgeführt wird + return button->state; + } + else 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; + if(IsMouseButtonDown(MOUSE_BUTTON_LEFT)){ + return button->state = BUTTON_STATE_PRESSED; } - button->state = 1; - return 1; - } - button->state = 0; - return 0; -} - -int ButtonIsButtonHovered(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 ButtonIsButtonPressed(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; + else if(button->state == BUTTON_STATE_PRESSED){ + return button->state = BUTTON_STATE_RELEASED; } + return button->state = BUTTON_STATE_HOVERED; } - return button->state = 0; + return button->state = BUTTON_STATE_DEFAULT; } diff --git a/Ui/button.h b/Ui/button.h index 77673d9..df33050 100644 --- a/Ui/button.h +++ b/Ui/button.h @@ -6,16 +6,23 @@ #define BUTTON_FONT_SIZE 36 +#define BUTTON_STATE_DEFAULT 0 +#define BUTTON_STATE_HOVERED 1 +#define BUTTON_STATE_PRESSED 2 +#define BUTTON_STATE_RELEASED 3 + +#define BUTTON_ID_CONTINUE 0 + typedef struct Button{ - Texture2D textures[3]; // [0]: Normal [1]: Hovered [2]: Pressed + Texture2D textures[4]; // [0]: Normal [1]: Hovered [2]: Pressed [3]: Released Vector2 position; Vector2 centerPosition; char text[20]; - int state; // 0: default 1: hovered 2: pressed + int state; // 0: default 1: hovered 2: pressed 3: released int id; } Button; -Button * InitButton(Texture2D textures[3], Vector2 *position, char *text, int textLEN, int id); +Button * ButtonInitButton(Texture2D textures[4], Vector2 *position, char *text, int textLEN, int id); // executes the logic of one button of certain id - huge switch? void ButtonExecuteButton(Button *button, Game * game); @@ -24,8 +31,4 @@ int ButtonUpdateButtonState(Button * button); void ButtonDrawButton(Button * button); -int ButtonisButtonPressed(Button * button); - -int ButtonisButtonHovered(Button * button); - #endif \ No newline at end of file diff --git a/Ui/uiContainer.c b/Ui/uiContainer.c index d5f9a37..264e180 100644 --- a/Ui/uiContainer.c +++ b/Ui/uiContainer.c @@ -8,12 +8,13 @@ UiContainer * UiContainerInitPauseUiContainer(){ UiContainer *uiContainer = malloc(sizeof(UiContainer)); - Texture2D textures[3] = { LoadTexture("assets/button.png"), - LoadTexture("assets/button_hovered.png"), - LoadTexture("assets/button_pressed.png")}; + Texture2D textures[4] = { LoadTexture("assets/button.png"), //DEFAULT + LoadTexture("assets/button_hovered.png"), //HOVERED + LoadTexture("assets/button_pressed.png"), //PRESSED + LoadTexture("assets/button_pressed.png")}; //RELEASED Vector2 position = (Vector2){GetScreenWidth()/2 - textures[0].width/2, GetScreenHeight()/2 + 150}; - Button *continuebutton = InitButton(textures, &position, "Continue", 9, 0); + Button *continuebutton = ButtonInitButton(textures, &position, "Continue", 9, BUTTON_ID_CONTINUE); uiContainer->buttons[0] = continuebutton; uiContainer->buttonCounter = 1; @@ -22,18 +23,22 @@ UiContainer * UiContainerInitPauseUiContainer(){ } UiContainer * UiContainerInitGameUiContainer(){ - + printf("\n\n\n\n UiContainerInitGameUiContainer not implemented yet!! \n\n\n\n"); + return 0; } +// Updated alle Buttons und führt gegebenenfalls deren Code aus void UiContainerUpdateUiContainer(UiContainer *uiContainer, Game *game){ int i = 0; for(i=0 ; i < uiContainer->buttonCounter; i++){ ButtonUpdateButtonState(uiContainer->buttons[i]); - if(uiContainer->buttons[i]->state == 2){ + if(uiContainer->buttons[i]->state == BUTTON_STATE_RELEASED){ ButtonExecuteButton(uiContainer->buttons[i], game); } } } + +// Drawed alle Buttons void UiContainerDrawUiContainer(UiContainer *uiContainer){ int i = 0; for(i=0 ; i < uiContainer->buttonCounter; i++){ diff --git a/animation.o b/animation.o new file mode 100644 index 0000000..75e4a75 Binary files /dev/null and b/animation.o differ diff --git a/animationHandler.o b/animationHandler.o new file mode 100644 index 0000000..21f4c01 Binary files /dev/null and b/animationHandler.o differ diff --git a/bucket.o b/bucket.o new file mode 100644 index 0000000..b9b0c0a Binary files /dev/null and b/bucket.o differ diff --git a/button.o b/button.o new file mode 100644 index 0000000..0e6eab8 Binary files /dev/null and b/button.o differ diff --git a/game.o b/game.o new file mode 100644 index 0000000..df4b9e1 Binary files /dev/null and b/game.o differ diff --git a/inputHandler.o b/inputHandler.o new file mode 100644 index 0000000..d1c4449 Binary files /dev/null and b/inputHandler.o differ diff --git a/isometricMap.o b/isometricMap.o new file mode 100644 index 0000000..6881c00 Binary files /dev/null and b/isometricMap.o differ diff --git a/list.o b/list.o new file mode 100644 index 0000000..b0440a7 Binary files /dev/null and b/list.o differ diff --git a/main.o b/main.o new file mode 100644 index 0000000..9045b7a Binary files /dev/null and b/main.o differ diff --git a/mergeSort.o b/mergeSort.o new file mode 100644 index 0000000..84c8b38 Binary files /dev/null and b/mergeSort.o differ diff --git a/spiel b/spiel new file mode 100755 index 0000000..63354e1 Binary files /dev/null and b/spiel differ diff --git a/sprite.o b/sprite.o new file mode 100644 index 0000000..83d073c Binary files /dev/null and b/sprite.o differ diff --git a/textureatlas.o b/textureatlas.o new file mode 100644 index 0000000..ddd110b Binary files /dev/null and b/textureatlas.o differ diff --git a/uiContainer.o b/uiContainer.o new file mode 100644 index 0000000..6f9d2fa Binary files /dev/null and b/uiContainer.o differ