Skip to content

Commit

Permalink
style: 💄 Made Color Nice and Size Bigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Polaris66 committed Jul 29, 2023
1 parent b3ec7c2 commit 18483e3
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 12 deletions.
10 changes: 6 additions & 4 deletions Cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Binary file modified Cell.o
Binary file not shown.
9 changes: 7 additions & 2 deletions Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -75,4 +75,9 @@ void Grid::render(sf::RenderWindow &window)
window.draw(cell->shape);
}
}
}

Grid::~Grid()
{
free(cells);
}
Binary file modified Grid.o
Binary file not shown.
2 changes: 1 addition & 1 deletion Headers/Cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
3 changes: 2 additions & 1 deletion Headers/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 10 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@

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;

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())
Expand All @@ -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();
Expand Down
Binary file modified main.o
Binary file not shown.
Binary file added run
Binary file not shown.
Binary file removed sfml-app
Binary file not shown.

0 comments on commit 18483e3

Please sign in to comment.