-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
73 lines (66 loc) · 2.22 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
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include "lib/Grid.hpp"
#include "lib/Animal.hpp"
void render_text(sf::RenderWindow& window, sf::Clock& CLOCK, sf::Font& FONT, sf::Vector3i& data, int& window_width, int& window_height);
int main()
{
//Setup
int window_width;
int window_height;
int wator_width;
int wator_height;
std::cout << "Enter window width: ";
std::cin >> window_width;
std::cout << "Enter window height: ";
std::cin >> window_height;
std::cout << "Enter wator width: ";
std::cin >> wator_width;
std::cout << "Enter wator height: ";
std::cin >> wator_height;
//Initilises grid to begin simulation
int starting_zebra_percentage = 15;
int starting_lion_percentage = 2;
Grid grid(sf::Vector2f(wator_width, wator_height), sf::Vector2f(window_width, window_height));
grid.init(starting_zebra_percentage, starting_lion_percentage);
sf::RenderWindow window(sf::VideoMode(window_width, window_height, 32), "Pstefa's Zebras and Lions");
sf::Font arial;
arial.loadFromFile("./lib/arial.ttf");
sf::Event event;
sf::Clock CLOCK;
CLOCK.restart();
int years = 0;
while (window.isOpen())
{
years ++;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
grid.init(starting_zebra_percentage, starting_lion_percentage);
years = 0;
}
window.clear(sf::Color(30, 150, 30));
sf::Vector3i data = grid.step(window, years);
render_text(window, CLOCK, arial, data, window_width, window_height);
window.display();
}
return 0;
}
void render_text(sf::RenderWindow& window, sf::Clock& CLOCK, sf::Font& FONT, sf::Vector3i& data, int& window_width, int& window_height)
{
std::string fps = "FPS: " + std::to_string((int)round(1 / CLOCK.getElapsedTime().asSeconds()));
sf::Text FPS(fps, FONT, 30);
sf::Text ANIMALS("Zebras: " + std::to_string(data.x) + "\nLions: " + std::to_string(data.y) + "\nYear: " + std::to_string(data.z), FONT, 30);
FPS.setFillColor(sf::Color::Black);
ANIMALS.setFillColor(sf::Color::Black);
ANIMALS.setPosition(sf::Vector2f(5, 5));
FPS.setPosition(sf::Vector2f(window_width - 130, window_height - 35));
window.draw(ANIMALS);
window.draw(FPS);
CLOCK.restart();
}