-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.cpp
45 lines (37 loc) · 863 Bytes
/
game.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
#include <cstdio>
#include <unistd.h>
#include "game.h"
const int FRAMERATE = 1;
namespace {
int framerate_to_usec(int fps){
return (int)(1000000/fps + 0.5);
}
int WORLD_WIDTH = 30;
int WORLD_HEIGHT = 30;
}
Game::Game()
: m_players(new std::vector<Player>()), m_world(new World(WORLD_WIDTH, WORLD_HEIGHT))
{
for (int j = 0; j < WORLD_HEIGHT; ++j){
for (int i = 0; i < WORLD_WIDTH; ++i){
m_world->at(i, j) = '.';
}
}
}
void Game::set_renderer(std::shared_ptr<Renderer> renderer){
m_renderer = renderer;
m_renderer->set_world(m_world);
m_renderer->set_players(m_players);
}
void Game::start(){
bool quit = false;
int frame = 0;
while (!quit){
m_renderer->draw_everything();
usleep(framerate_to_usec(FRAMERATE));
if (++frame == FRAMERATE){
printf("Frame %i\n", frame);
frame = 0;
}
}
}