-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
42 lines (34 loc) · 962 Bytes
/
main.cpp
File metadata and controls
42 lines (34 loc) · 962 Bytes
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
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/System.hpp>
#define TITLE "Game of Life"
#include <iostream>
#include "include/grid.h"
using namespace std;
int main(){
int width = 600, height = 600;
sf::RenderWindow window(sf::VideoMode(width,height), "Game of Life");
Grid mainGrid(width/15, height/15);
while(window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
//close window: exit
if(event.type == sf::Event::Closed){
window.close();
}
else if(event.type == sf::Event::MouseButtonPressed){
mainGrid.toggleByClick(width, height, event.mouseButton.x, event.mouseButton.y);
}
else if(event.type == sf::Event::KeyPressed){
if(event.key.code == sf::Keyboard::Space)
mainGrid.toggleState();
}
}
window.clear(sf::Color(255,0,255,0));
mainGrid.update();
window.draw(mainGrid);
window.display();
sf::sleep(sf::milliseconds(30));
}
}