summary refs log tree commit diff stats
path: root/mazeoflife.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mazeoflife.cpp')
-rw-r--r--mazeoflife.cpp100
1 files changed, 49 insertions, 51 deletions
diff --git a/mazeoflife.cpp b/mazeoflife.cpp index cf21d2a..952fbdb 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp
@@ -1,61 +1,59 @@
1#include "mazeoflife.h" 1#include "mazeoflife.h"
2
2#include <SDL.h> 3#include <SDL.h>
3#include <SDL_ttf.h>
4#include <SDL_net.h> 4#include <SDL_net.h>
5#include <SDL_ttf.h>
6
5#include <cstdlib> 7#include <cstdlib>
6#include <ctime> 8#include <ctime>
7#include <iostream> 9#include <iostream>
10
8#include "state.h" 11#include "state.h"
9#include "titlestate.h" 12#include "titlestate.h"
10 13
11int main(int argc, char *argv[]) 14int main(int argc, char* argv[]) {
12{ 15 srand(time(NULL));
13 srand(time(NULL)); 16
14 17 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
15 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) 18 printf("Could not initialize SDL: %s.\n", SDL_GetError());
16 { 19 exit(-1);
17 printf("Could not initialize SDL: %s.\n", SDL_GetError()); 20 }
18 exit(-1); 21
19 } 22 if (TTF_Init() == -1) {
20 23 printf("Could not initialize SDL_ttf: %s.\n", TTF_GetError());
21 if (TTF_Init() == -1) 24 exit(-1);
22 { 25 }
23 printf("Could not initialize SDL_ttf: %s.\n", TTF_GetError()); 26
24 exit(-1); 27 if (SDLNet_Init() == -1) {
25 } 28 printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError());
26 29 exit(-1);
27 if (SDLNet_Init() == -1) 30 }
28 { 31
29 printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError()); 32 SDL_Window* window =
30 exit(-1); 33 SDL_CreateWindow("Maze of Life", 100, 100, 480, 480, SDL_WINDOW_SHOWN);
31 } 34 if (window == NULL) {
32 35 std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
33 SDL_Window* window = SDL_CreateWindow("Maze of Life", 100, 100, 480, 480, SDL_WINDOW_SHOWN); 36 return 1;
34 if (window == NULL) 37 }
35 { 38
36 std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl; 39 SDL_Surface* icon = SDL_LoadBMP("resources/icon.bmp");
37 return 1; 40 SDL_SetWindowIcon(window, icon);
38 } 41
39 42 SDL_Renderer* renderer = SDL_CreateRenderer(
40 SDL_Surface* icon = SDL_LoadBMP("resources/icon.bmp"); 43 window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
41 SDL_SetWindowIcon(window, icon); 44 if (renderer == NULL) {
42 45 std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
43 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); 46 return 1;
44 if (renderer == NULL) 47 }
45 { 48
46 std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl; 49 State* state = new TitleState();
47 return 1; 50 while (state != NULL) {
48 } 51 state = (*state)(window, renderer);
49 52 }
50 State* state = new TitleState(); 53
51 while (state != NULL) 54 SDL_DestroyRenderer(renderer);
52 { 55 SDL_DestroyWindow(window);
53 state = (*state)(window, renderer); 56 SDLNet_Quit();
54 } 57 TTF_Quit();
55 58 SDL_Quit();
56 SDL_DestroyRenderer(renderer);
57 SDL_DestroyWindow(window);
58 SDLNet_Quit();
59 TTF_Quit();
60 SDL_Quit();
61} \ No newline at end of file 59} \ No newline at end of file