diff --git a/gamestate.h b/gamestate.h index 9e2f3d6..fca7225 100644 --- a/gamestate.h +++ b/gamestate.h @@ -1,6 +1,6 @@ #ifndef __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 diff --git a/startmenu.c b/startmenu.c index cfc51cf..13afc14 100644 --- a/startmenu.c +++ b/startmenu.c @@ -19,6 +19,10 @@ SDL_Rect SKINSBUTTON_Rect; SDL_Rect HIGHSCORESBUTTON_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) { TITLE_Texture = IMG_LoadTexture(renderer, "assets/images/breaking_button.png"); 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, 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(); + } +}