-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.cpp
41 lines (36 loc) · 693 Bytes
/
Grid.cpp
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 <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);
}
}
}