diff --git a/Cell.cpp b/Cell.cpp index ac27455..5646e31 100644 --- a/Cell.cpp +++ b/Cell.cpp @@ -7,24 +7,26 @@ Cell::Cell() { } -Cell::Cell(int i, int j, float size) +Cell::Cell(int i, int j, int base_x, int base_y, float size) { x = i; y = j; alive = rand() % 2; shape = sf::RectangleShape(sf::Vector2f(size, size)); - shape.setPosition(i * size, j * size); + shape.setPosition(base_x + i * size, base_y + j * size); + shape.setOutlineThickness(2.0f); + shape.setOutlineColor(sf::Color(255, 255, 255)); } void Cell::render() { if (alive) { - shape.setFillColor(sf::Color::White); + shape.setFillColor(sf::Color(255, 255, 255, 150)); } else { - shape.setFillColor(sf::Color::Black); + shape.setFillColor(sf::Color(0, 0, 0, 0)); } } diff --git a/Cell.o b/Cell.o index 7efb523..91673d4 100644 Binary files a/Cell.o and b/Cell.o differ diff --git a/Grid.cpp b/Grid.cpp index c820d2e..92959c3 100644 --- a/Grid.cpp +++ b/Grid.cpp @@ -6,7 +6,7 @@ #include "Headers/Grid.hpp" #include "Headers/Cell.hpp" -Grid::Grid(int _size, int _x, int _y) +Grid::Grid(int _size, int base_x, int base_y, int _x, int _y) { size = _size; x = _x; @@ -17,7 +17,7 @@ Grid::Grid(int _size, int _x, int _y) { for (int j = 0; j < y; j++) { - cells[y * i + j] = Cell(i, j, size); + cells[y * i + j] = Cell(i, j, base_x, base_y, size); } } } @@ -75,4 +75,9 @@ void Grid::render(sf::RenderWindow &window) window.draw(cell->shape); } } +} + +Grid::~Grid() +{ + free(cells); } \ No newline at end of file diff --git a/Grid.o b/Grid.o index 58126c1..37e5139 100644 Binary files a/Grid.o and b/Grid.o differ diff --git a/Headers/Cell.hpp b/Headers/Cell.hpp index 33705c2..6943e3a 100644 --- a/Headers/Cell.hpp +++ b/Headers/Cell.hpp @@ -15,5 +15,5 @@ class Cell void setNeighbors(int _neighbors); Cell(); - Cell(int i, int j, float size); + Cell(int i, int j, int base_x, int base_y, float size); }; diff --git a/Headers/Grid.hpp b/Headers/Grid.hpp index 1a33911..5250bb0 100644 --- a/Headers/Grid.hpp +++ b/Headers/Grid.hpp @@ -9,7 +9,8 @@ class Grid Cell *cells = nullptr; public: - Grid(int _size, int _x, int _y); + Grid(int _size, int base_x, int base_y, int _x, int _y); + ~Grid(); void update(); void render(sf::RenderWindow &window); diff --git a/main.cpp b/main.cpp index 29c1055..32e1428 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,13 @@ int main() { - int width = 800; + int windowWidth = 1200; + int windowHeight = 800; + + int sideBarWidth = 400; + int titleHeight = 100; + + int width = 600; int height = 600; int size = 40; @@ -13,9 +19,9 @@ int main() int x = width / size; int y = height / size; // Create the main window - sf::RenderWindow window(sf::VideoMode(width, height), "Game of Life"); + sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "Game of Life"); - Grid grid(size, x, y); + Grid grid(size, sideBarWidth, titleHeight, x, y); sf::Clock clock; // Main Loop while (1 == window.isOpen()) @@ -32,7 +38,7 @@ int main() window.clear(sf::Color::Black); - if (clock.getElapsedTime().asSeconds() > 0.01f) + if (clock.getElapsedTime().asSeconds() > 1.0f) { grid.update(); clock.restart(); diff --git a/main.o b/main.o index e750700..e4ad7b0 100644 Binary files a/main.o and b/main.o differ diff --git a/run b/run new file mode 100755 index 0000000..2ac3af2 Binary files /dev/null and b/run differ diff --git a/sfml-app b/sfml-app deleted file mode 100755 index bd4b9b3..0000000 Binary files a/sfml-app and /dev/null differ