-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "headers/Cell.hpp" | ||
#include <SFML/Graphics.hpp> | ||
|
||
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <cstring> | ||
#include "headers/Cell.hpp" | ||
#include "headers/Grid.hpp" | ||
#include <SFML/Graphics.hpp> | ||
#include <iostream> | ||
|
||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
#pragma once | ||
#include <SFML/Graphics.hpp> | ||
|
||
class Cell | ||
{ | ||
private: | ||
bool nextAliveState; | ||
|
||
public: | ||
sf::RectangleShape shape; | ||
bool alive; | ||
void update(); | ||
|
||
Cell(); | ||
Cell(int i, int j, float size); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
#include <Cell.hpp> | ||
|
||
#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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters