-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.h
More file actions
74 lines (57 loc) · 1.7 KB
/
game.h
File metadata and controls
74 lines (57 loc) · 1.7 KB
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
#ifndef GAME_H
#define GAME_H
#include <SFML/Graphics.hpp>
#include <iostream>
#include "boids.h"
template<typename T>
/*game engine housing all the logic and concealing it from the user*/
class Game {
private:
//member variables
Boids<T> boids;
//rendering data
sf::RenderWindow* window = nullptr;
sf::Event ev;
sf::VideoMode videomode;
public:
//constructor and destructor
Game(const unsigned int& size, const size_type& count, sf::Color fill_color, bool rand_saturation, unsigned int x = 1900, unsigned int y = 1000) {
//initialize window
this->videomode.width = x;
this->videomode.height = y;
this->window = new sf::RenderWindow(this->videomode, "Flocking Behaviour", sf::Style::Close | sf::Style::Resize);
this->window->setPosition(sf::Vector2i(0,0));
this->window->setVerticalSyncEnabled(true);
//initialize variables i.e. boids
this->boids.boidsInit(size, count, fill_color, this->window, rand_saturation);
}
~Game() {
delete this->window;
}
//accessors; the game and event loops run in main
bool running() const {
return this->window->isOpen();
}
void update() {
this->pollEvents();
}
void render() {
this->window->clear(sf::Color(20,20,30,255));
//render all the content within this window
this->boids.visualize(this->window);
this->window->display();
}
void pollEvents() {
while (this->window->pollEvent(this->ev))
switch (this->ev.type) {
case sf::Event::Closed :
this->window->close();
break;
case sf::Event::Resized :
printf("new window width: %i new window height: %i\n", this->ev.size.width, this->ev.size.height);
break;
}
return;
}
};
#endif