Clickevents fixed
This commit is contained in:
parent
75abf597e3
commit
547943749f
7
main.c
7
main.c
@ -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);
|
||||||
|
28
startmenu.c
28
startmenu.c
@ -59,18 +59,20 @@ 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 (clickInRect(b, &PLAYBUTTON_Rect) == 1) {
|
if (gameState == MainMenu) {
|
||||||
GAME_ChangeState(Game);
|
if (clickInRect(b, &PLAYBUTTON_Rect) == 1) {
|
||||||
} else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) {
|
GAME_ChangeState(Game);
|
||||||
GAME_ChangeState(SkinSelect);
|
} else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) {
|
||||||
} else if (clickInRect(b, &LEVELBUTTON_Rect) == 1) {
|
GAME_ChangeState(SkinSelect);
|
||||||
GAME_ChangeState(LevelSelect);
|
} else if (clickInRect(b, &LEVELBUTTON_Rect) == 1) {
|
||||||
} else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) {
|
GAME_ChangeState(LevelSelect);
|
||||||
GAME_ChangeState(Settings);
|
} else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) {
|
||||||
} else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) {
|
GAME_ChangeState(Settings);
|
||||||
GAME_ChangeState(Highscores);
|
} else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) {
|
||||||
} else if (clickInRect(b, &QUITBUTTON_Rect) == 1) {
|
GAME_ChangeState(Highscores);
|
||||||
GAME_Escape();
|
} else if (clickInRect(b, &QUITBUTTON_Rect) == 1) {
|
||||||
|
GAME_Escape();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user