diff --git a/Cell.cpp b/Cell.cpp index e69de29..d361519 100644 --- a/Cell.cpp +++ b/Cell.cpp @@ -0,0 +1,15 @@ +#include "headers/Cell.hpp" +#include + +Cell::Cell() +{ +} + +Cell::Cell(int i, int j, float x) +{ + shape = sf::RectangleShape(sf::Vector2f(x, x)); + shape.setPosition(i * x, j * x); + shape.setFillColor(sf::Color::White); + shape.setOutlineThickness(1.0f); + shape.setOutlineColor(sf::Color(255, 0, 0)); +} \ No newline at end of file diff --git a/Cell.o b/Cell.o new file mode 100644 index 0000000..e83b5d7 Binary files /dev/null and b/Cell.o differ diff --git a/Grid.cpp b/Grid.cpp index e69de29..8d5e4a9 100644 --- a/Grid.cpp +++ b/Grid.cpp @@ -0,0 +1,41 @@ +#include +#include "headers/Cell.hpp" +#include "headers/Grid.hpp" +#include +#include + +Grid::Grid(int _size, int _x, int _y) +{ + size = _size; + x = _x; + y = _y; + + cells = new Cell[x * y]; + for (int i = 0; i < x; i++) + { + for (int j = 0; j < y; j++) + { + cells[y * i + j] = Cell(i, j, size); + } + } +} + +Cell *Grid::getCell(int xpos, int ypos) +{ + return cells + (y * xpos + ypos); +} + +void Grid::update() +{ +} + +void Grid::render(sf::RenderWindow &window) +{ + for (int i = 0; i < x; i++) + { + for (int j = 0; j < y; j++) + { + window.draw(cells[i * y + j].shape); + } + } +} \ No newline at end of file diff --git a/Grid.o b/Grid.o new file mode 100644 index 0000000..dd1ecbf Binary files /dev/null and b/Grid.o differ diff --git a/headers/Cell.hpp b/headers/Cell.hpp index 7554bb4..a918727 100644 --- a/headers/Cell.hpp +++ b/headers/Cell.hpp @@ -1,11 +1,16 @@ +#pragma once +#include + class Cell { private: bool nextAliveState; public: + sf::RectangleShape shape; bool alive; void update(); Cell(); + Cell(int i, int j, float size); }; diff --git a/headers/Grid.hpp b/headers/Grid.hpp index 1f509d4..e79c861 100644 --- a/headers/Grid.hpp +++ b/headers/Grid.hpp @@ -1,16 +1,17 @@ -#include - +#pragma once +#include "Cell.hpp" class Grid { private: + int x, y; Cell *cells = nullptr; public: - int width, height; - Grid(int _width, int _height); - ~Grid(); + int size; + Grid(int _size, int _x, int _y); void update(); + void render(sf::RenderWindow &window); - Cell &getCell(int xpos, int ypos, int localWidth); + Cell *getCell(int xpos, int ypos); }; diff --git a/main.cpp b/main.cpp index 365b604..b8f64f9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,15 +1,19 @@ +#include "headers/Grid.hpp" #include int main() { int width = 800; int height = 600; + + int size = 40; + + int x = width / size; + int y = height / size; // Create the main window sf::RenderWindow window(sf::VideoMode(width, height), "Game of Life"); - sf::CircleShape shape(50.f); - shape.setFillColor(sf::Color(100, 250, 50)); - + Grid grid(size, x, y); // Main Loop while (window.isOpen()) { @@ -25,8 +29,9 @@ int main() window.clear(sf::Color::Black); + grid.render(window); + // Display Stuff - window.draw(shape); window.display(); } diff --git a/main.o b/main.o index bcde543..f622538 100644 Binary files a/main.o and b/main.o differ diff --git a/sfml-app b/sfml-app index 22a06b0..4050905 100755 Binary files a/sfml-app and b/sfml-app differ