function added for button clicks in main menu

This commit is contained in:
Stefan Neumann 2018-01-18 13:18:48 +01:00
parent d3a6dada59
commit 76f54de298
2 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,6 @@
#ifndef __gamestate_h__ #ifndef __gamestate_h__
#define __gamestate_h__ #define __gamestate_h__
typedef enum gameStateEnum { MainMenu = 1, Game = 2, LevelSelect = 3, Settings = 4, Highscores = 5 } GameState; typedef enum gameStateEnum { MainMenu = 1, Game = 2, LevelSelect = 3, SkinSelect = 4, Settings = 5, Highscores = 6 } GameState;
#endif #endif

View File

@ -19,6 +19,10 @@ SDL_Rect SKINSBUTTON_Rect;
SDL_Rect HIGHSCORESBUTTON_Rect; SDL_Rect HIGHSCORESBUTTON_Rect;
SDL_Rect QUITBUTTON_Rect; SDL_Rect QUITBUTTON_Rect;
int clickInRect(SDL_MouseButtonEvent b, SDL_Rect* area_rect) {
return (((b.x) >= (area_rect->x)) && ((b.x) <= ((area_rect->x) + (area_rect->w))) && ((b.y) >= (area_rect->y)) && ((b.y) <= ((area_rect->y) + (area_rect->h))));
}
void Load_Textures (SDL_Renderer* renderer) { void Load_Textures (SDL_Renderer* renderer) {
TITLE_Texture = IMG_LoadTexture(renderer, "assets/images/breaking_button.png"); TITLE_Texture = IMG_LoadTexture(renderer, "assets/images/breaking_button.png");
TITLE_Rect = (SDL_Rect){.x = 685,.y = 50, .w=550, .h=250}; TITLE_Rect = (SDL_Rect){.x = 685,.y = 50, .w=550, .h=250};
@ -51,3 +55,19 @@ void Startmenu_Draw (SDL_Renderer* renderer) {
SDL_RenderCopy(renderer, HIGHSCORESBUTTON_Texture, NULL, &HIGHSCORESBUTTON_Rect); SDL_RenderCopy(renderer, HIGHSCORESBUTTON_Texture, NULL, &HIGHSCORESBUTTON_Rect);
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect); SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
} }
int button_clicked(SDL_MouseButtonEvent b) {
if(clickInRect(b, PLAYBUTTON_Rect) == 1) {
GAME_ChangeState(Game);
} else if (clickInRect(b, SKINSBUTTON_Rect) == 1) {
GAME_ChangeState(SkinSelect);
} else if (clickInRect(b, LEVELBUTTON_Rect) == 1) {
GAME_ChangeState(LevelSelect);
} else if (clickInRect(b, SETTINGSBUTTON_Rect) == 1) {
GAME_ChangeState(Settings);
} else if (clickInRect(b, HIGHSCORESBUTTON_Rect) == 1) {
GAME_ChangeState(Highscores);
} else if (clickInRect(b, QUITBUTTON_Rect) == 1) {
GAME_Escape();
}
}