Debug gamestate added (important (main.c edited))!

This commit is contained in:
Michael Chen 2018-01-15 15:34:43 +01:00
parent 929322cc1e
commit e707caa7cc
2 changed files with 42 additions and 4 deletions

6
gamestate.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __gamestate_h__
#define __gamestate_h__
typedef enum gameStateEnum { MainMenu = 1, Game = 2, LevelSelect = 3, Settings = 4, Highscores = 5 } GameState;
#endif

40
main.c
View File

@ -10,12 +10,16 @@
#include "breakout.h" #include "breakout.h"
#include "vector.h" #include "vector.h"
#include "startmenu.h" #include "startmenu.h"
#include "gamestate.h"
#ifndef __nullptr__ #ifndef __nullptr__
#define Nullptr(type) (type *)0 #define Nullptr(type) (type *)0
#endif // __nullptr__ #endif // __nullptr__
typedef enum gameStateEnum { MainMenu, Game, LevelSelect, Settings, Highscores } GameState; #define ae "\204"
#define oe "\224"
#define ue "\201"
#define ss "\341"
void INITIALIZE(); void INITIALIZE();
void QUIT(); void QUIT();
@ -26,6 +30,7 @@ void mousePress(SDL_MouseButtonEvent b);
void keyPress(SDL_KeyboardEvent b); void keyPress(SDL_KeyboardEvent b);
void windowChanged(SDL_WindowEvent b); void windowChanged(SDL_WindowEvent b);
void toggleFullscreen(); void toggleFullscreen();
int readIntFromIO(char * m1, char * m2, char * m3, int min, int max);
const int width = 1920; const int width = 1920;
const int height = 1080; const int height = 1080;
@ -38,12 +43,13 @@ SDL_Renderer * renderer;
SDL_Event event; SDL_Event event;
bool running = true, fullscreen = false; bool running = true, fullscreen = false;
TTF_Font * font = NULL; TTF_Font * font = NULL;
GameState gameState = MainMenu; GameState gameState = Game;
Ball ball; Ball ball;
int main(int argc, char * args[]){ int main(int argc, char * args[]){
// system("bhi.exe"); 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");
gameState = 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(); INITIALIZE();
while (running) { // Gameloop while (running) { // Gameloop
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
@ -71,12 +77,13 @@ int main(int argc, char * args[]){
BREAKOUT_Draw(renderer); BREAKOUT_Draw(renderer);
break; break;
case MainMenu: case MainMenu:
// Startmenu_Update(keystate);
Startmenu_Draw(renderer); Startmenu_Draw(renderer);
break; break;
default: default:
printf("Unknow state was updated: %d\n", gameState); printf("Unknow state was updated: %d\n", gameState);
} }
DrawText(renderer, "FICK DICH"); // DrawText(renderer, "FICK DICH");
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
QUIT(); QUIT();
@ -204,3 +211,28 @@ void QUIT(){
printf("Quitting SDL finished!\n"); printf("Quitting SDL finished!\n");
printf("De-initializing finished!\n"); printf("De-initializing finished!\n");
} /* QUIT */ } /* QUIT */
int readIntFromIO(char * m1, char * m2, char * m3, int min, int max){
int nitems, num;
while (1) {
while (1) {
printf(m1);
nitems = scanf("%d", &num);
if (nitems == 0) {
printf(m2);
fflush(stdin);
continue;
} else {
break;
}
}
if ((num < min) || (num > max)) {
printf(m3, num);
} else {
break;
}
}
fflush(stdin);
return(num);
} /* readIntFromIO */