-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
56 lines (38 loc) · 1.21 KB
/
main.cpp
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
#include <iostream>
#include <GLFW/glfw3.h>
#include "world.h"
Window *g_window;
World *g_world;
int main() {
g_window = new Window("2D Platform", 640, 480);
if (g_window->hasError()) return -1;
g_world = new World();
int width, height;
glfwGetFramebufferSize(g_window->getWindow(), &width, &height);
Platform floor(Vector(0, 400), width, 400);
g_world->addEntity(&floor);
Platform floor1(Vector(0, 250), 180, 60);
g_world->addEntity(&floor1);
Platform floor2(Vector(460, 250), 180, 60);
g_world->addEntity(&floor2);
Player player(Vector(0, 0));
g_world->addEntity(&player);
double t = 0.0;
double dt = 1.0 / 60.0;
while (!glfwWindowShouldClose(g_window->getWindow())) {
int width, height;
glfwGetFramebufferSize(g_window->getWindow(), &width, &height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, width, height, 0.0f, 0.0f, 1.0f);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT);
g_world->tick(dt);
g_world->draw();
glfwSwapBuffers(g_window->getWindow());
glfwPollEvents();
t += dt;
}
glfwTerminate();
return 0;
}