forked from rtpHarry/Sokoban
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SokobanRenderer.cpp
133 lines (104 loc) · 3.36 KB
/
SokobanRenderer.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include ".\sokobanrenderer.h"
#include <windows.h>
#include "GLee.h"
//#include <gl/GL.h>
#include <GL/glu.h>
SokobanRenderer::SokobanRenderer(void)
{
}
SokobanRenderer::~SokobanRenderer(void)
{
m_Theme.DestroyTheme();
}
// Initialize the Render System
void SokobanRenderer::Setup(void)
{
// TODO :: Theme Setup
m_Theme.SetupTheme();
ShadowMap.SetupEffect();
}
void SokobanRenderer::RenderLevel(const SokobanActiveLevel LevelData)
{
// Pre Render
//////////////////////////////////////////////////////////////////////////
m_Theme.PreRender();
// Render
//////////////////////////////////////////////////////////////////////////
glPushMatrix();
/* ShadowMap.RenderFirstPass();
_RenderLevel(LevelData);
ShadowMap.RenderSecondPass();
_RenderLevel(LevelData);
ShadowMap.RenderThirdPass();
_RenderLevel(LevelData);
ShadowMap.RenderCleanUp();*/
_RenderLevel(LevelData);
glPopMatrix();
// Surrounding Scenery
//////////////////////////////////////////////////////////////////////////
// TODO base location of surround on level not origin
m_Theme.RenderSurroundingScene(0,0,0,0);
// Post Render
//////////////////////////////////////////////////////////////////////////
m_Theme.PostRender();
}
// Actually render the level
void SokobanRenderer::_RenderLevel(const SokobanActiveLevel LevelData)
{
// calculate level scale
float ScaleFactor = CalculateScaleFactor(30.0f, LevelData);
glScalef(ScaleFactor, ScaleFactor, ScaleFactor);
// draw the architecture
//////////////////////////////////////////////////////////////////////////
for (int outer = 0; outer < LevelData.m_WallData.size(); outer++)
{
// loop through current line
for (int inner = 0; inner < LevelData.m_WallData[outer].length(); inner++)
{
switch(LevelData.m_WallData[outer][inner])
{
case SYMBOL_WALL:
m_Theme.RenderTileWall((float)outer, (float)inner);
break;
case SYMBOL_FLOOR:
m_Theme.RenderTileFloor((float)outer, (float)inner);
break;
case SYMBOL_VOID:
m_Theme.RenderTileVoid((float)outer, (float)inner);
break;
}
}
}
// draw the items
//////////////////////////////////////////////////////////////////////////
for (int indx = 0; indx < LevelData.m_ItemList.size(); indx++)
{
int x = LevelData.m_ItemList[indx].ItemLocation.x;
int y = LevelData.m_ItemList[indx].ItemLocation.y;
switch(LevelData.m_ItemList[indx].ItemType)
{
case SYMBOL_CRATE:
m_Theme.RenderItemCrate((float)x, (float)y);
break;
case SYMBOL_TARGET:
m_Theme.RenderItemTarget((float)x, (float)y);
break;
}
}
// draw the player
//////////////////////////////////////////////////////////////////////////
int x = LevelData.m_Player.ItemLocation.x;
int y = LevelData.m_Player.ItemLocation.y;
m_Theme.RenderItemPlayer((float)x, (float)y);
}
// Calculate the amount to scale the level to in order to fit it on screen
float SokobanRenderer::CalculateScaleFactor(float ClampAmount, const SokobanActiveLevel LevelData)
{
// calculate the true level dimensions
float Width = LevelData.m_LevelDimensions.x + (LevelData.m_LevelDimensions.x * m_Theme.GetTileOffsetGap());
float Height = LevelData.m_LevelDimensions.y + (LevelData.m_LevelDimensions.y * m_Theme.GetTileOffsetGap());
// decide which axis is the controlling scale factor
float ScaleFactor = ((Width > Height) ? Width : Height);
// calculate the scale factor
return (1 / (ScaleFactor / ClampAmount));
}