#include "SDL.h" #include "states.h" #include "menu.h" struct menuItem mainMenu[] = { {"Neues Spiel", STATE_NUMPLAYERS}, {"Credits", STATE_CREDITS}, {"Spiel beenden", STATE_EXIT} }; struct menuItem numplayersMenu[] = { {"Einspieler", STATE_RUNNINGGAME}, {"Zweispieler", STATE_RUNNINGGAME}, {"Dreispieller", STATE_RUNNINGGAME}, {"Zurueck", STATE_MAINMENU} }; struct menuItem creditsMenu[] = { {"Zurueck", STATE_MAINMENU} }; struct menuItem rlyquitMenu[] = { {"Beenden", STATE_MAINMENU}, {"Weiterspielen", STATE_RUNNINGGAME} }; void handleMenuEvent(struct menuItem items[], int numItems, enum states prevState) { if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_DOWN: case SDLK_j: currentMenuActionState++; if (currentMenuActionState > numItems-1) currentMenuActionState = 0; break; case SDLK_UP: case SDLK_k: currentMenuActionState--; if (currentMenuActionState < 0) currentMenuActionState = numItems-1; break; case SDLK_RETURN: case SDLK_SPACE: currentState = items[currentMenuActionState].targetState; currentMenuActionState = 0; break; case SDLK_ESCAPE: case SDLK_BACKSPACE: currentMenuActionState = 0; currentState = prevState; break; default: break; } } } void drawMenu(struct menuItem items[], int numItems) { SDL_Surface *text; SDL_Rect targetPos; SDL_Color colorSelected = {0, 255, 66}; SDL_Color colorNormal = {59, 71, 62}; for (int i=0; i