summary refs log tree commit diff stats
path: root/mazeoflife.cpp
blob: 952fbdbd0cb35ddcdc01ec6cce338897e4ebe8b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "mazeoflife.h"

#include <SDL.h>
#include <SDL_net.h>
#include <SDL_ttf.h>

#include <cstdlib>
#include <ctime>
#include <iostream>

#include "state.h"
#include "titlestate.h"

int main(int argc, char* argv[]) {
  srand(time(NULL));

  if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
    printf("Could not initialize SDL: %s.\n", SDL_GetError());
    exit(-1);
  }

  if (TTF_Init() == -1) {
    printf("Could not initialize SDL_ttf: %s.\n", TTF_GetError());
    exit(-1);
  }

  if (SDLNet_Init() == -1) {
    printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError());
    exit(-1);
  }

  SDL_Window* window =
      SDL_CreateWindow("Maze of Life", 100, 100, 480, 480, SDL_WINDOW_SHOWN);
  if (window == NULL) {
    std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
    return 1;
  }

  SDL_Surface* icon = SDL_LoadBMP("resources/icon.bmp");
  SDL_SetWindowIcon(window, icon);

  SDL_Renderer* renderer = SDL_CreateRenderer(
      window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  if (renderer == NULL) {
    std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
    return 1;
  }

  State* state = new TitleState();
  while (state != NULL) {
    state = (*state)(window, renderer);
  }

  SDL_DestroyRenderer(renderer);
  SDL_DestroyWindow(window);
  SDLNet_Quit();
  TTF_Quit();
  SDL_Quit();
}