main_menu as default start screen added and now you can click to change gamestate

This commit is contained in:
Stefan Neumann 2018-01-18 15:19:04 +01:00
parent 76f54de298
commit 04d0cfb994
3 changed files with 18 additions and 10 deletions

8
main.c
View File

@ -47,12 +47,12 @@ SDL_Window * window;
SDL_Renderer * renderer;
SDL_Event event;
bool running = true, fullscreen = false;
GameState gameState = Game;
GameState gameState = MainMenu;
Scenery scenery;
int main(int argc, char * args[]){
printf("Spielbereiche\n\t- 1: Hauptmen"ue "\n\t- 2: Spiel\n\t- 3: Level Select\n\t- 4: Settings\n\t- 5: Highscores\n");
GAME_ChangeState(readIntFromIO("W"ae "hle einen Spielbereich aus, den du testen m"oe "chtest:", "Fehlerhafte Eingabe!\n", "%d ist kein g"ue "ltiger Spielbereich!\n", 1, 5));
//printf("Spielbereiche\n\t- 1: Hauptmen"ue "\n\t- 2: Spiel\n\t- 3: Level Select\n\t- 4: Settings\n\t- 5: Highscores\n");
//GAME_ChangeState(readIntFromIO("W"ae "hle einen Spielbereich aus, den du testen m"oe "chtest:", "Fehlerhafte Eingabe!\n", "%d ist kein g"ue "ltiger Spielbereich!\n", 1, 5));
INITIALIZE();
while (running) { // Gameloop
HandleSDLEvents();
@ -64,6 +64,7 @@ int main(int argc, char * args[]){
break;
case MainMenu:
// Startmenu_Update(keystate);
Startmenu_Draw(renderer);
break;
case Highscores:
@ -111,6 +112,7 @@ void HandleSDLEvents(){
break;
case SDL_MOUSEBUTTONDOWN:
mousePress(event.button);
button_clicked(event.button);
break;
case SDL_WINDOWEVENT:
windowChanged(event.window);

View File

@ -2,6 +2,8 @@
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "gamestate.h"
SDL_Texture* TITLE_Texture;
SDL_Texture* PLAYBUTTON_Texture;
@ -56,18 +58,18 @@ void Startmenu_Draw (SDL_Renderer* renderer) {
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
}
int button_clicked(SDL_MouseButtonEvent b) {
if(clickInRect(b, PLAYBUTTON_Rect) == 1) {
void button_clicked(SDL_MouseButtonEvent b) {
if(clickInRect(b, &PLAYBUTTON_Rect) == 1) {
GAME_ChangeState(Game);
} else if (clickInRect(b, SKINSBUTTON_Rect) == 1) {
} else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) {
GAME_ChangeState(SkinSelect);
} else if (clickInRect(b, LEVELBUTTON_Rect) == 1) {
} else if (clickInRect(b, &LEVELBUTTON_Rect) == 1) {
GAME_ChangeState(LevelSelect);
} else if (clickInRect(b, SETTINGSBUTTON_Rect) == 1) {
} else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) {
GAME_ChangeState(Settings);
} else if (clickInRect(b, HIGHSCORESBUTTON_Rect) == 1) {
} else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) {
GAME_ChangeState(Highscores);
} else if (clickInRect(b, QUITBUTTON_Rect) == 1) {
} else if (clickInRect(b, &QUITBUTTON_Rect) == 1) {
GAME_Escape();
}
}

View File

@ -12,4 +12,8 @@ void Load_Textures (SDL_Renderer* renderer);
void Startmenu_Draw (SDL_Renderer* renderer);
void button_clicked(SDL_MouseButtonEvent b);
int clickInRect(SDL_MouseButtonEvent b, SDL_Rect* area_rect);
#endif