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; break;
case MainMenu: case MainMenu:
// Startmenu_Update(keystate); // Startmenu_Update(keystate);
Startmenu_Draw(renderer); Startmenu_Draw(renderer);
break; break;
case Highscores: case Highscores:
@ -70,6 +69,10 @@ void GAME_Escape(){
} }
void GAME_ChangeState(GameState state){ void GAME_ChangeState(GameState state){
if (gameState == state) {
printf("State wasn't changed!\n");
return;
}
gameState = state; gameState = state;
switch (gameState) { switch (gameState) {
case Highscores: case Highscores:
@ -97,7 +100,7 @@ void HandleSDLEvents(){
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
mousePress(event.button); mousePress(event.button);
button_clicked(event.button); button_clicked(event.button, gameState);
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
windowChanged(event.window); windowChanged(event.window);

View File

@ -59,7 +59,8 @@ void Startmenu_Draw(SDL_Renderer * renderer) {
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect); SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
} }
void button_clicked(SDL_MouseButtonEvent b) { void button_clicked(SDL_MouseButtonEvent b, GameState gameState) {
if (gameState == MainMenu) {
if (clickInRect(b, &PLAYBUTTON_Rect) == 1) { if (clickInRect(b, &PLAYBUTTON_Rect) == 1) {
GAME_ChangeState(Game); GAME_ChangeState(Game);
} else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) { } else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) {
@ -74,3 +75,4 @@ void button_clicked(SDL_MouseButtonEvent b) {
GAME_Escape(); GAME_Escape();
} }
} }
}

View File

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