-
Notifications
You must be signed in to change notification settings - Fork 4
/
Tileset.cpp
88 lines (69 loc) · 1.73 KB
/
Tileset.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
#include "TileSet.h"
#include "SDL2/SDL.h"
#include "SDL2/SDL_image.h"
#include "Render.h"
JResult CTileset::Load( const char *szName, int dwCellWidth, int dwCellHeight )
{
SDL_Surface *TextureImage;
JResult retval = JSUCCESS;
bool bIsBMP = false;
if( IsBMP( szName ) )
{
TextureImage = SDL_LoadBMP(szName);
bIsBMP = true;
}
else
{
TextureImage = IMG_Load( szName );
}
// break out if you couldn't load this image
if( !TextureImage )
{
return JERROR();
}
#ifdef RENDER_TILESET_POSTLOAD_NEEDED
// Turn this image into an OpenGL texture
retval = g_pGame->GetRender()->PostLoadTexture( m_Texture, TextureImage->pixels, 4, bIsBMP,
TextureImage->w, TextureImage->h, dwCellWidth, dwCellHeight );
#endif
m_dwTilesPerRow = TextureImage->w / dwCellWidth;
m_vTexels.x = 1.0f / (float)m_dwTilesPerRow;
m_vTexels.y = (float)dwCellHeight / (float)TextureImage->h;
#ifdef RENDER_TILESET_POSTLOAD_NEEDED // destroy the temporary surface
if( TextureImage )
{
SDL_FreeSurface(TextureImage);
}
#endif
return retval;
}
bool CTileset::DrawTile( int dwIndex, const JFVector &vPos, JVector &vSize, bool bIsTextured )
{
/*if( !IsInWorld( vPos ) )
{
return false;
}/**/
JIVector vTile;
GetTile( dwIndex, vTile );
//if( bIsTextured )
{
g_pGame->GetRender()->DrawTile( vPos, vSize, vTile, m_vTexels );
}
//else
//{
// g_pGame->GetRender()->DrawTile( vPos, vSize, vTile );
//}
return true;
}
void CTileset::PreDrawTile()
{
g_pGame->GetRender()->PreDrawTile();
}
void CTileset::PostDrawTile()
{
g_pGame->GetRender()->PostDrawTile();
}
void CTileset::SetTileColor( JColor color )
{
g_pGame->GetRender()->SetTileColor(color);
}