-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
91 lines (80 loc) · 1.9 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include "entities.hpp"
#include "game.hpp"
#include "global.hpp"
#include "util.hpp"
using namespace sf;
using namespace std;
// substitute rand with a xorshift
int x, y, z, w;
int rand() {
int t = x ^ (x << 11);
x = y; y = z; z = w;
return w = w ^ (w >> 19) ^ t ^ (t >> 8);
}
int main()
{
// init xorshift, badly
x = time(NULL);
y = time(NULL) * 1234567;
z = time(NULL) * 98765;
w = time(NULL) * 45678;
window = new RenderWindow(VideoMode(WIDTH, HEIGHT), "Santa Ski");
window->setVerticalSyncEnabled(true);
window->setFramerateLimit(60);
// load resources
Decal::preload();
Player::preload();
Tree::preload();
Rock::preload();
Dune::preload();
Jump::preload();
Monster::preload();
bool result = defaultFont.loadFromFile("fonts/Munro.ttf");
assert(result);
Game game;
Clock clock;
while (window->isOpen()) {
// event loop
Event event;
while (window->pollEvent(event)) {
switch (event.type) {
case Event::Closed:
window->close();
break;
case Event::Resized:
// keep a nice viewport
{
View view = getLetterboxView(WIDTH, HEIGHT, event.size.width, event.size.height);
window->setView(view);
}
break;
case Event::KeyPressed:
switch (event.key.code) {
case Keyboard::Up: game.player.goUp(); break;
case Keyboard::Down: game.player.goDown(); break;
case Keyboard::Left: game.player.goLeft(); break;
case Keyboard::Right: game.player.goRight(); break;
}
break;
}
}
float deltaTime = clock.getElapsedTime().asSeconds();
clock.restart();
game.update(deltaTime);
// center on the player
View view = window->getView();
view.setCenter(game.player.getPosition());
window->setView(view);
window->clear(snowColor);
game.draw();
window->display();
}
delete window;
return 0;
}