summary refs log tree commit diff stats
path: root/board.cpp
blob: 8af001565bc94e129ded2f332c92de9e39f9f092 (plain) (blame)
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
42
43
44
45
46
47
48
#include "includes.h"

Board::Board()
{
	Board(Level());
}

Board::Board(Level level)
{
	int x,y;
	for (y=0;y<HEIGHT;y++)
	{
		for (x=0;x<WIDTH;x++)
		{
			if (level.checkSquare(x, y))
			{
				blocks[x][y] = rand() % 2;
			} else {
				blocks[x][y] = false;
			}
		}
	}
}

bool Board::isObstructed(int x, int y)
{
	return blocks[x][y];
}

void Board::render(SDL_Surface* screen, Level level)
{
	SDL_Rect block;
	block.w = 16;
	block.h = 16;

	int x,y;

	for (y=0;y<HEIGHT;y++)
	{
		for (x=0;x<WIDTH;x++)
		{
			block.x = x*16;
			block.y = y*16;

			SDL_FillRect(screen, &block, (blocks[x][y] ? level.getAliveColor() : level.getDeadColor()));
		}
	}
}