33
33
/*===========================================================================
34
34
Init at game start-up
35
35
===========================================================================*/
36
void GameRenderer::init(void) {
37
/* Load sprite definitions. Sprites are very renderer specific in the
38
meaning that they serve only a visual purpose - hence they are handled
39
here in the renderer. */
42
Sprites.readFromFile("sprites.dat");
43
TiXmlDocument *pSprites = Sprites.getLowLevelAccess();
44
if(pSprites == NULL) {
45
/* No sprite definitions! */
46
Log("** Warning ** : failed to load sprite definitions from 'sprites.dat'");
49
TiXmlElement *pSpriteDataElem = pSprites->FirstChildElement("spritedata");
50
if(pSpriteDataElem == NULL) {
51
/* No valid spritedata-element */
52
Log("** Warning ** : 'sprites.dat' does not contain valid sprite data");
56
for(TiXmlElement *pSpriteElem=pSpriteDataElem->FirstChildElement("sprite");
57
pSpriteElem!=NULL;pSpriteElem=pSpriteElem->NextSiblingElement("sprite")) {
61
pc = pSpriteElem->Attribute("name");
62
if(pc != NULL) Name = pc;
66
Vector2f Center(0.5,0.5);
68
TiXmlElement *pSizeElem = pSpriteElem->FirstChildElement("size");
69
TiXmlElement *pCenterElem = pSpriteElem->FirstChildElement("center");
71
pc=pSizeElem->Attribute("width");
72
if(pc != NULL) Size.x = atof(pc);
74
pc=pSizeElem->Attribute("height");
75
if(pc != NULL) Size.y = atof(pc);
77
pc=pCenterElem->Attribute("x");
78
if(pc != NULL) Center.x = atof(pc);
79
else Center.x = Size.x/2.0f;
81
pc=pCenterElem->Attribute("y");
82
if(pc != NULL) Center.y = atof(pc);
83
else Center.y = Size.y/2.0f;
86
std::string TryPath = std::string("./Textures/Sprites/") + Name + std::string(".png");
87
Texture *pTexture = getParent()->TexMan.loadTexture(TryPath,false,true,true);
88
if(pTexture == NULL) {
89
/* Could not load it */
90
Log("** Warning ** : Sprite '%s' failed to load",TryPath.c_str());
93
m_SpriteTypes[m_nNumSpriteTypes].Name = Name;
94
m_SpriteTypes[m_nNumSpriteTypes].Center = Center;
95
m_SpriteTypes[m_nNumSpriteTypes].Size = Size;
96
m_SpriteTypes[m_nNumSpriteTypes].pTexture = pTexture;
102
Log(" %d sprite%s loaded",m_nNumSpriteTypes,m_nNumSpriteTypes==1?"":"s");
104
/* Load animations in the same way */
106
int nTotalFrames = 0;
107
Anims.readFromFile("anims.dat");
108
TiXmlDocument *pAnims = Anims.getLowLevelAccess();
110
/* No animation definitions! */
111
Log("** Warning ** : failed to load animations from 'anims.dat'");
114
TiXmlElement *pAnimationDataElem = pAnims->FirstChildElement("animationdata");
115
if(pAnimationDataElem == NULL) {
116
/* No valid animationdata-element */
117
Log("** Warning ** : 'anims.dat' does not contain valid animation data");
120
/* For each animation */
121
for(TiXmlElement *pAnimationElem=pAnimationDataElem->FirstChildElement("animation");
122
pAnimationElem!=NULL;pAnimationElem=pAnimationElem->NextSiblingElement("animation")) {
123
/* Load definition */
126
pc = pAnimationElem->Attribute("name");
127
if(pc != NULL) Name = pc;
130
/* Current settings (can be changed prior to each frame) */
132
Vector2f Center(0.5,0.5);
135
/* Allocate and register animation */
136
Animation *pAnim = new Animation;
137
m_Anims.push_back( pAnim );
139
pAnim->fFrameTime = 0.0f;
140
pAnim->m_nCurFrame = 0;
142
/* Go trough definition... */
143
for(TiXmlElement *pi=pAnimationElem->FirstChildElement();pi!=NULL;pi=pi->NextSiblingElement()) {
144
std::string Type = pi->Value();
147
pc = pi->Attribute("width");
148
if(pc != NULL) Size.x = atof(pc);
149
pc = pi->Attribute("height");
150
if(pc != NULL) Size.y = atof(pc);
152
else if(Type == "center") {
153
pc = pi->Attribute("x");
154
if(pc != NULL) Center.x = atof(pc);
155
pc = pi->Attribute("y");
156
if(pc != NULL) Center.y = atof(pc);
158
else if(Type == "delay") {
159
pc = pi->Attribute("time");
160
if(pc != NULL) fDelay = atof(pc);
162
else if(Type == "frame") {
163
pc = pi->Attribute("file");
165
std::string Path = std::string("./Textures/") + std::string(pc);
167
Texture *pTex = getParent()->TexMan.loadTexture(Path.c_str());
169
AnimationFrame *pFrame = new AnimationFrame;
170
pAnim->m_Frames.push_back(pFrame);
171
pFrame->pTexture = pTex;
172
pFrame->Center = Center;
174
pFrame->fDelay = fDelay;
180
Log("** Warning ** : unknown element '%s' in animation '%s'",Type.c_str(),Name.c_str());
185
Log(" %d animation%s (%d total frame%s) loaded",m_Anims.size(),m_Anims.size()==1?"":"s",
186
nTotalFrames,nTotalFrames==1?"":"s");
188
m_pArrowTexture = getParent()->TexMan.loadTexture("Textures/Misc/Arrow.png");
190
/* Load misc. textures */
191
m_pSkyTexture1 = getParent()->TexMan.loadTexture("Textures/Effects/Sky1.jpg");
192
m_pSkyTexture2 = getParent()->TexMan.loadTexture("Textures/Effects/Sky2.jpg");
193
m_pSkyTexture2Drift = getParent()->TexMan.loadTexture("Textures/Effects/Sky2Drift.jpg");
194
m_pEdgeGrass1 = getParent()->TexMan.loadTexture("Textures/Effects/EdgeGrass1.png");
196
m_pSmoke1 = getParent()->TexMan.loadTexture("Textures/Effects/Smoke1.png");
197
m_pSmoke2 = getParent()->TexMan.loadTexture("Textures/Effects/Smoke2.png");
198
m_pFire1 = getParent()->TexMan.loadTexture("Textures/Effects/Fire1.png");
199
m_pDirt1 = getParent()->TexMan.loadTexture("Textures/Effects/Debris1.png");
201
/* Load bike textures */
202
theme_normal.BikeBody = getParent()->TexMan.loadTexture("Textures/Bikes/Body1.png");
203
theme_normal.BikeRear = getParent()->TexMan.loadTexture("Textures/Bikes/Rear1.png");
204
theme_normal.BikeFront = getParent()->TexMan.loadTexture("Textures/Bikes/Front1.png");
205
theme_normal.BikeWheel = getParent()->TexMan.loadTexture("Textures/Bikes/Wheel1.png");
207
if(theme_normal.BikeBody == NULL || theme_normal.BikeRear == NULL ||
208
theme_normal.BikeFront == NULL || theme_normal.BikeWheel == NULL)
209
throw Exception("important bike texture missing");
211
/* Load rider textures */
212
theme_normal.RiderTorso = getParent()->TexMan.loadTexture("Textures/Riders/Torso1.png");
213
theme_normal.RiderUpperLeg = getParent()->TexMan.loadTexture("Textures/Riders/UpperLeg1.png");
214
theme_normal.RiderLowerLeg = getParent()->TexMan.loadTexture("Textures/Riders/LowerLeg1.png");
215
theme_normal.RiderUpperArm = getParent()->TexMan.loadTexture("Textures/Riders/UpperArm1.png");
216
theme_normal.RiderLowerArm = getParent()->TexMan.loadTexture("Textures/Riders/LowerArm1.png");
218
if(theme_normal.RiderTorso == NULL || theme_normal.RiderUpperLeg == NULL ||
219
theme_normal.RiderLowerArm == NULL || theme_normal.RiderLowerLeg == NULL || theme_normal.RiderUpperArm == NULL)
220
throw Exception("important rider texture missing");
222
#if defined(ALLOW_GHOST)
223
/* Load bike textures */
224
theme_ghost.BikeBody = getParent()->TexMan.loadTexture("Textures/Bikes/Body_Ghost.png");
225
theme_ghost.BikeRear = getParent()->TexMan.loadTexture("Textures/Bikes/Rear_Ghost.png");
226
theme_ghost.BikeFront = getParent()->TexMan.loadTexture("Textures/Bikes/Front_Ghost.png");
227
theme_ghost.BikeWheel = getParent()->TexMan.loadTexture("Textures/Bikes/Wheel_Ghost.png");
229
if(theme_ghost.BikeBody == NULL || theme_ghost.BikeRear == NULL ||
230
theme_ghost.BikeFront == NULL || theme_ghost.BikeWheel == NULL)
231
throw Exception("important bike texture missing");
233
/* Load ghost textures */
234
theme_ghost.RiderTorso = getParent()->TexMan.loadTexture("Textures/Riders/Torso_Ghost.png");
235
theme_ghost.RiderUpperLeg = getParent()->TexMan.loadTexture("Textures/Riders/UpperLeg_Ghost.png");
236
theme_ghost.RiderLowerLeg = getParent()->TexMan.loadTexture("Textures/Riders/LowerLeg_Ghost.png");
237
theme_ghost.RiderUpperArm = getParent()->TexMan.loadTexture("Textures/Riders/UpperArm_Ghost.png");
238
theme_ghost.RiderLowerArm = getParent()->TexMan.loadTexture("Textures/Riders/LowerArm_Ghost.png");
240
if(theme_ghost.RiderTorso == NULL || theme_ghost.RiderUpperLeg == NULL ||
241
theme_ghost.RiderLowerArm == NULL || theme_ghost.RiderLowerLeg == NULL || theme_ghost.RiderUpperArm == NULL)
242
throw Exception("important rider texture missing");
245
/* Obtain ref. to known animations */
246
m_pStrawberryAnim = _GetAnimationByName("Strawberry");
247
m_pFlowerAnim = _GetAnimationByName("Flower");
248
m_pWreckerAnim = _GetAnimationByName("Wrecker");
250
if(m_pStrawberryAnim == NULL || m_pFlowerAnim == NULL || m_pWreckerAnim == NULL)
251
throw Exception("important animation missing");
36
void GameRenderer::init(void) {
254
39
getGUI()->setApp(getParent());
255
40
getGUI()->setPosition(0,0,getParent()->getDispWidth(),getParent()->getDispHeight());