summary refs log tree commit diff stats
path: root/src/main.cpp
blob: 2a1d9eab3baf13c1cbd6a824077c03acd4c3ce6b (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
60
61
#include <ctime>
#include <list>
#include "map.h"
#include "state.h"
#include "mapview.h"
#include "renderer.h"

using namespace::std;

bool quit = false;

State* curGameState;

void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
  if ((key == GLFW_KEY_ESCAPE) && (action == GLFW_PRESS))
  {
    quit = true;
  }
  
  if (curGameState != NULL)
  {
    curGameState->input(key, action);
  }
}

int main()
{
  GLFWwindow* window = initRenderer();
  glfwSwapInterval(1);
  glfwSetKeyCallback(window, key_callback);
  
  Map* m = new Map("../maps/bigmap.txt");
  Map* m2 = new Map("../maps/cozy.txt");
  
  m->setLeftMap(m2);
  m2->setRightMap(m);
  
  curGameState = new MapView(m, 100, 100);
  
  Texture* buffer = createTexture(GAME_WIDTH, GAME_HEIGHT);
  
  while (!(quit || glfwWindowShouldClose(window)))
  {
    // Tick!
    curGameState->tick();
    
    // Do rendering
    curGameState->render(buffer);
    renderScreen(buffer);
    
    glfwPollEvents();
  }
  
  delete curGameState;
  delete m;
  
  destroyRenderer();
  
  return 0;
}