-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCTileWindow.cpp
93 lines (69 loc) · 2.08 KB
/
CTileWindow.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//==============================================================================
#include "CTileWindow.h"
CTileWindow::CTileWindow()
{
Surf_TileWindow = NULL;
X = 0;
Y = 0;
Width = 0;
Height = 0;
Active = 0;
}
CTileWindow::~CTileWindow()
{
OnCleanup();
}
//==============================================================================
bool CTileWindow::OnLoad(char* File, int Width, int Height)
{
if((Surf_TileWindow = CSurface::OnLoad(File)) == NULL)
{
return false;
}
CSurface::Transparent(Surf_TileWindow, 255, 0, 255);
this->Width = Width;
this->Height = Height;
return true;
}
//------------------------------------------------------------------------------
void CTileWindow::OnLoop()
{
}
//------------------------------------------------------------------------------
void CTileWindow::OnRender(SDL_Surface* Surf_Display)
{
CSurface::OnDraw(Surf_Display, Surf_TileWindow, 0, 0);
//CSurface::OnDraw(Surf_Display, Surf_Entity, X - CCamera::CameraControl.GetX(), Y - CCamera::CameraControl.GetY() + 2, CurrentFrameCol * Width, (CurrentFrameRow + 5) * Height, Width, Height);
}
//------------------------------------------------------------------------------
void CTileWindow::OnCleanup()
{
if(Surf_TileWindow)
{
SDL_FreeSurface(Surf_TileWindow);
}
Surf_TileWindow = NULL;
}
//------------------------------------------------------------------------------
int CTileWindow::GetTileID(int mX, int mY, int &TileType)
{
int TilesetWidth = Width;
int TilesetHeight = Height;
int ID = 0;
for(int Y = 0; Y < TilesetHeight; Y += TILE_SIZE)
{
for(int X = 0; X < TilesetWidth; X += TILE_SIZE)
{
int tileX = X;
int tileY = Y;
// if the mouse click was within the bounds of this tile...
if(mX > tileX && mX < tileX + TILE_SIZE &&
mY > tileY && mY < tileY + TILE_SIZE)
{
// then return the tile's ID!
return ID;
}
ID++;
}
}
}