Clickevents fixed

This commit is contained in:
Michael Chen 2018-01-18 16:13:54 +01:00
parent 75abf597e3
commit 547943749f
3 changed files with 22 additions and 16 deletions

7
main.c
View File

@ -45,7 +45,6 @@ int main(int argc, char * args[]){
break;
case MainMenu:
// Startmenu_Update(keystate);
Startmenu_Draw(renderer);
break;
case Highscores:
@ -70,6 +69,10 @@ void GAME_Escape(){
}
void GAME_ChangeState(GameState state){
if (gameState == state) {
printf("State wasn't changed!\n");
return;
}
gameState = state;
switch (gameState) {
case Highscores:
@ -97,7 +100,7 @@ void HandleSDLEvents(){
break;
case SDL_MOUSEBUTTONDOWN:
mousePress(event.button);
button_clicked(event.button);
button_clicked(event.button, gameState);
break;
case SDL_WINDOWEVENT:
windowChanged(event.window);

View File

@ -59,18 +59,20 @@ void Startmenu_Draw(SDL_Renderer * renderer) {
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
}
void 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();
void button_clicked(SDL_MouseButtonEvent b, GameState gameState) {
if (gameState == MainMenu) {
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();
}
}
}

View File

@ -7,12 +7,13 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "gamestate.h"
void Load_Textures (SDL_Renderer* renderer);
void Startmenu_Draw (SDL_Renderer* renderer);
void button_clicked(SDL_MouseButtonEvent b);
void button_clicked(SDL_MouseButtonEvent b, GameState gameState);
int clickInRect(SDL_MouseButtonEvent b, SDL_Rect* area_rect);