-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnakeMap.cpp
More file actions
55 lines (45 loc) · 1021 Bytes
/
Copy pathSnakeMap.cpp
File metadata and controls
55 lines (45 loc) · 1021 Bytes
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
49
50
51
52
53
54
55
#include "SnakeMap.h"
CSnakeMap::CSnakeMap(int width, int height, SDL_Surface * surface)
{
mWidth = width;
mHeight = height;
mMap = new unsigned char[width * height];
mSurface = surface;
mTextures = 0;
}
CSnakeMap::~CSnakeMap(void)
{
if (mMap != 0)
delete mMap;
}
void CSnakeMap::AddTiles(SDL_Surface * textures[], int count)
{
mRect.h = textures[0]->h;
mRect.w = textures[0]->w;
mTextures = textures;
mItemCount = count;
}
void CSnakeMap::Draw()
{
for (int i = 0; i < mHeight; i++)
for (int j = 0; j < mWidth; j++)
Draw(j, i);
}
void CSnakeMap::Draw(int x, int y)
{
mRect.x = x * mRect.w;
mRect.y = y * mRect.h;
SDL_BlitSurface(mTextures[mMap[x + y * mWidth]], NULL, mSurface, &mRect);
}
unsigned char * CSnakeMap::GetBuffer()
{
return mMap;
}
unsigned char CSnakeMap::GetItem(int x, int y)
{
return mMap[x + y * mWidth];
}
void CSnakeMap::AddItem(int x, int y, unsigned char item)
{
mMap[x + y * mWidth] = item;
}