From ffd335aca284c286030e2b26f1a02a0441748f46 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Tue, 27 Aug 2013 11:39:37 -0400 Subject: Started rewriting game from scratch with SDL2 Only the title screen is currently implemented --- mazeoflife.cpp | 141 ++++++++++++--------------------------------------------- 1 file changed, 29 insertions(+), 112 deletions(-) (limited to 'mazeoflife.cpp') diff --git a/mazeoflife.cpp b/mazeoflife.cpp index 107a640..a020f6c 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp @@ -1,7 +1,12 @@ -#include "includes.h" - -SDL_Surface *screen; -State* state; +#include "mazeoflife.h" +#include +#include +#include +#include +#include +#include +#include "state.h" +#include "titlestate.h" int main(int argc, char *argv[]) { @@ -24,118 +29,30 @@ int main(int argc, char *argv[]) printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError()); exit(-1); } - - /* Clean up on exit */ - atexit(SDL_Quit); - atexit(TTF_Quit); - atexit(SDLNet_Quit); - - SDL_WM_SetCaption("Maze Of Life", NULL); - - SDL_Surface* icon; - icon = SDL_LoadBMP("resources/icon.bmp"); - SDL_WM_SetIcon(icon, NULL); - - /* - * Initialize the display in a 640x480 8-bit palettized mode, - * requesting a software surface - */ - screen = SDL_SetVideoMode(WIDTH*16, HEIGHT*16, 8, SDL_DOUBLEBUF); - if ( screen == NULL ) { - fprintf(stderr, "Couldn't set %dx%dx8 video mode: %s\n", WIDTH*16, WIDTH*16, SDL_GetError()); - exit(1); - } - - SDL_EnableKeyRepeat(100, 70); - - state = new TitleState(); - - SDL_AddTimer(TICKDELAY, *tick, NULL); - - SDL_Event anEvent; - for (;;) + + SDL_Window* window = SDL_CreateWindow("Maze of Life", 100, 100, 480, 480, SDL_WINDOW_SHOWN); + if (window == NULL) { - while (SDL_PollEvent(&anEvent)) - { - switch (anEvent.type) - { - case SDL_QUIT: - exit(0); - - break; - case SDL_KEYDOWN: - if (anEvent.key.keysym.sym == SDLK_F4) - { - SDL_WM_ToggleFullScreen(screen); - } else { - state->input(anEvent.key.keysym); - } - - break; - } - } + std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl; + return 1; } - - exit(0); -} - -void wrap(int* x, int* y) -{ - if (*x < 0) - { - *x = WIDTH-(0-*x); - } else if (*y < 0) + + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if (renderer == NULL) { - *y = HEIGHT-(0-*y); - } else if (*x >= WIDTH) - { - *x = *x-WIDTH; - } else if (*y >= HEIGHT) - { - *y = *y-HEIGHT; + std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl; + return 1; } -} - -Uint32 getColor(int r, int g, int b) -{ - return SDL_MapRGB(screen->format, r, g, b); -} - -void changeState(State* nState) -{ - state = nState; -} - -Uint32 tick(Uint32 interval, void *param) -{ - state->tick(); - state->render(screen); - SDL_Flip(screen); - - return interval; -} - -TTF_Font* loadFont(int size) -{ - TTF_Font* tmpfont = TTF_OpenFont("resources/mono.ttf", size); - - if (tmpfont == NULL) + State* state = new TitleState(); + while (state != NULL) { - printf("Unable to load font: %s\n", TTF_GetError()); - exit(1); + state = (*state)(renderer); } - - return tmpfont; -} - -const char* getDataFile() -{ -#ifdef WINDOWS - char* dir = getenv("USERPROFILE"); -#else - char* dir = getenv("HOME"); -#endif - - return (std::string(dir) + "/.molhslist").c_str(); -} + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDLNet_Quit(); + TTF_Quit(); + SDL_Quit(); +} \ No newline at end of file -- cgit 1.4.1