source: GTP/trunk/App/Games/Jungle_Rumble/src/HUD.cpp @ 1378

Revision 1378, 14.4 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1#include "dxstdafx.h"
2#include "./HUD.h"
3
4HUD::HUD(void):Node() {
5        minutes = 0;
6        seconds = 0;
7        ammoAmount = 0;
8        testAgainstFrustum = false;
9        nodeType |= GameScene::NODE_HUD;
10
11        messagetimer = messagethreshold = 0;
12        messagedt = 0;
13               
14        youwintimer = youwinthreshold = 0;
15        youwindt = 0;
16       
17        youlosetimer = youlosethreshold = 0;
18        youlosedt = 0;
19
20        toastedtimer = toastedthreshold = 0;
21        toasteddt = 0;
22}
23
24void HUD::generateHUD()
25{
26        // Load textures
27        IDirect3DTexture9* tex = 0;
28
29        if (this->crosshair != "")
30                Textures.push_back(this->myScene->manager->resManager.loadTexture(this->crosshair));
31        if (this->radar != "")
32                Textures.push_back(this->myScene->manager->resManager.loadTexture(this->radar));
33        if (this->texture0 != "")
34                Textures.push_back(this->myScene->manager->resManager.loadTexture(this->texture0));
35        if (this->texture1 != "")
36                Textures.push_back(this->myScene->manager->resManager.loadTexture(this->texture1));
37        if (this->texture2 != "")
38                Textures.push_back(this->myScene->manager->resManager.loadTexture(this->texture2));
39        if (this->texture3 != "")
40                Textures.push_back(this->myScene->manager->resManager.loadTexture(this->texture3));
41        if (this->texture4 != "")
42                Textures.push_back(this->myScene->manager->resManager.loadTexture(this->texture4));
43
44        //load fancy font:
45        D3DSURFACE_DESC desc;
46       
47        //calculate scaling factor:
48        float scaling = (float)this->myScene->manager->screenHeight/3;
49        float positionFactorX = (float)this->myScene->manager->screenWidth/100;
50        float positionFactorY = (float)this->myScene->manager->screenHeight/100;
51
52        //set maximum rotation factor:
53        float maxRotation = 1.0f;
54       
55        //load you win letters:
56        Letter rufezeichen;
57        rufezeichen.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/rufezeichen.dds");
58        Textures.push_back(rufezeichen.texture);
59        rufezeichen.texture->GetLevelDesc(0, &desc);
60        rufezeichen.scale = scaling/desc.Height;
61        rufezeichen.centerX = desc.Width/2 * rufezeichen.scale;
62        rufezeichen.centerY = desc.Height/2 * rufezeichen.scale;
63        rufezeichen.x = 92*positionFactorX;
64        rufezeichen.y = 50*positionFactorY;
65        rufezeichen.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
66        YouWin.push_back(rufezeichen);
67       
68        Letter n;
69        n.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/n.dds");
70        Textures.push_back(n.texture);
71        n.texture->GetLevelDesc(0, &desc);
72        n.scale = scaling/desc.Height;
73        n.centerX = desc.Width/2 * n.scale;
74        n.centerY = desc.Height/2 * n.scale;
75        n.x = 82*positionFactorX;
76        n.y = 50*positionFactorY;
77        n.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
78        YouWin.push_back(n);
79
80        Letter i;
81        i.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/i.dds");
82        Textures.push_back(i.texture);
83        i.texture->GetLevelDesc(0, &desc);
84        i.scale = scaling/desc.Height;
85        i.centerX = desc.Width/2 * i.scale;
86        i.centerY = desc.Height/2 * i.scale;
87        i.x = 72*positionFactorX;
88        i.y = 50*positionFactorY;
89        i.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
90        YouWin.push_back(i);
91
92        Letter w;
93        w.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/w.dds");
94        Textures.push_back(w.texture);
95        w.texture->GetLevelDesc(0, &desc);
96        w.scale = scaling/desc.Height;
97        w.centerX = desc.Width/2 * w.scale;
98        w.centerY = desc.Height/2 * w.scale;
99        w.x = 57*positionFactorX;
100        w.y = 50*positionFactorY;
101        w.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
102        YouWin.push_back(w);
103
104        Letter u;
105        u.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/u.dds");
106        Textures.push_back(u.texture);
107        u.texture->GetLevelDesc(0, &desc);
108        u.scale = scaling/desc.Height;
109        u.centerX = desc.Width/2 * u.scale;
110        u.centerY = desc.Height/2 * u.scale;
111        u.x = 37*positionFactorX;
112        u.y = 50*positionFactorY;
113        u.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
114        YouWin.push_back(u);
115
116        Letter o;
117        o.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/o.dds");
118        Textures.push_back(o.texture);
119        o.texture->GetLevelDesc(0, &desc);
120        o.scale = scaling/desc.Height;
121        o.centerX = desc.Width/2 * o.scale;
122        o.centerY = desc.Height/2 * o.scale;
123        o.x = 23*positionFactorX;
124        o.y = 50*positionFactorY;
125        o.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
126        YouWin.push_back(o);
127
128        Letter y;
129        y.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/y.dds");
130        Textures.push_back(y.texture);
131        y.texture->GetLevelDesc(0, &desc);
132        y.scale = scaling/desc.Height;
133        y.centerX = desc.Width/2 * y.scale;
134        y.centerY = desc.Height/2 * y.scale;
135        y.x = 12*positionFactorX;
136        y.y = 50*positionFactorY;
137        y.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
138        YouWin.push_back(y);
139       
140        //load you lose letters:
141        Letter rufezeichen2;
142        rufezeichen2.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/rufezeichen.dds");
143        Textures.push_back(rufezeichen2.texture);
144        rufezeichen2.texture->GetLevelDesc(0, &desc);
145        rufezeichen2.scale = scaling/desc.Height;
146        rufezeichen2.centerX = desc.Width/2 * rufezeichen2.scale;
147        rufezeichen2.centerY = desc.Height/2 * rufezeichen2.scale;
148        rufezeichen2.x = 92*positionFactorX;
149        rufezeichen2.y = 50*positionFactorY;
150        rufezeichen2.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
151        YouLose.push_back(rufezeichen2);
152       
153        Letter e;
154        e.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/e.dds");
155        Textures.push_back(e.texture);
156        e.texture->GetLevelDesc(0, &desc);
157        e.scale = scaling/desc.Height;
158        e.centerX = desc.Width/2 * e.scale;
159        e.centerY = desc.Height/2 * e.scale;
160        e.x = 86*positionFactorX;
161        e.y = 50*positionFactorY;
162        e.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
163        YouLose.push_back(e);
164
165        Letter s;
166        s.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/s.dds");
167        Textures.push_back(s.texture);
168        s.texture->GetLevelDesc(0, &desc);
169        s.scale = scaling/desc.Height;
170        s.centerX = desc.Width/2 * s.scale;
171        s.centerY = desc.Height/2 * s.scale;
172        s.x = 77*positionFactorX;
173        s.y = 50*positionFactorY;
174        s.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
175        YouLose.push_back(s);
176
177        Letter o3;
178        o3.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/o.dds");
179        Textures.push_back(o3.texture);
180        o3.texture->GetLevelDesc(0, &desc);
181        o3.scale = scaling/desc.Height;
182        o3.centerX = desc.Width/2 * o3.scale;
183        o3.centerY = desc.Height/2 * o3.scale;
184        o3.x = 67*positionFactorX;
185        o3.y = 50*positionFactorY;
186        o3.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
187        YouLose.push_back(o3);
188
189        Letter l;
190        l.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/l.dds");
191        Textures.push_back(l.texture);
192        l.texture->GetLevelDesc(0, &desc);
193        l.scale = scaling/desc.Height;
194        l.centerX = desc.Width/2 * l.scale;
195        l.centerY = desc.Height/2 * l.scale;
196        l.x = 57*positionFactorX;
197        l.y = 50*positionFactorY;
198        l.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
199        YouLose.push_back(l);
200
201        Letter u2;
202        u2.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/u.dds");
203        Textures.push_back(u2.texture);
204        u2.texture->GetLevelDesc(0, &desc);
205        u2.scale = scaling/desc.Height;
206        u2.centerX = desc.Width/2 * u2.scale;
207        u2.centerY = desc.Height/2 * u2.scale;
208        u2.x = 37*positionFactorX;
209        u2.y = 50*positionFactorY;
210        u2.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
211        YouLose.push_back(u2);
212
213        Letter o2;
214        o2.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/o.dds");
215        Textures.push_back(o2.texture);
216        o2.texture->GetLevelDesc(0, &desc);
217        o2.scale = scaling/desc.Height;
218        o2.centerX = desc.Width/2 * o2.scale;
219        o2.centerY = desc.Height/2 * o2.scale;
220        o2.x = 23*positionFactorX;
221        o2.y = 50*positionFactorY;
222        o2.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
223        YouLose.push_back(o2);
224
225        Letter y2;
226        y2.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/y.dds");
227        Textures.push_back(y2.texture);
228        y2.texture->GetLevelDesc(0, &desc);
229        y2.scale = scaling/desc.Height;
230        y2.centerX = desc.Width/2 * y2.scale;
231        y2.centerY = desc.Height/2 * y2.scale;
232        y2.x = 12*positionFactorX;
233        y2.y = 50*positionFactorY;
234        y2.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
235        YouLose.push_back(y2);
236
237        //load toasted letters:
238        Letter rufezeichen3;
239        rufezeichen3.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/rufezeichen.dds");
240        Textures.push_back(rufezeichen3.texture);
241        rufezeichen3.texture->GetLevelDesc(0, &desc);
242        rufezeichen3.scale = scaling/desc.Height;
243        rufezeichen3.centerX = desc.Width/2 * rufezeichen3.scale;
244        rufezeichen3.centerY = desc.Height/2 * rufezeichen3.scale;
245        rufezeichen3.x = 91*positionFactorX;
246        rufezeichen3.y = 50*positionFactorY;
247        rufezeichen3.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
248        Toasted.push_back(rufezeichen3);
249       
250        Letter d;
251        d.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/d.dds");
252        Textures.push_back(d.texture);
253        d.texture->GetLevelDesc(0, &desc);
254        d.scale = scaling/desc.Height;
255        d.centerX = desc.Width/2 * d.scale;
256        d.centerY = desc.Height/2 * d.scale;
257        d.x = 82*positionFactorX;
258        d.y = 50*positionFactorY;
259        d.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
260        Toasted.push_back(d);
261
262        Letter e2;
263        e2.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/e.dds");
264        Textures.push_back(e2.texture);
265        e2.texture->GetLevelDesc(0, &desc);
266        e2.scale = scaling/desc.Height;
267        e2.centerX = desc.Width/2 * e2.scale;
268        e2.centerY = desc.Height/2 * e2.scale;
269        e2.x = 72*positionFactorX;
270        e2.y = 50*positionFactorY;
271        e2.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
272        Toasted.push_back(e2);
273
274        Letter t;
275        t.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/t.dds");
276        Textures.push_back(t.texture);
277        t.texture->GetLevelDesc(0, &desc);
278        t.scale = scaling/desc.Height;
279        t.centerX = desc.Width/2 * t.scale;
280        t.centerY = desc.Height/2 * t.scale;
281        t.x = 61*positionFactorX;
282        t.y = 50*positionFactorY;
283        t.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
284        Toasted.push_back(t);
285
286        Letter s2;
287        s2.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/s.dds");
288        Textures.push_back(s2.texture);
289        s2.texture->GetLevelDesc(0, &desc);
290        s2.scale = scaling/desc.Height;
291        s2.centerX = desc.Width/2 * s2.scale;
292        s2.centerY = desc.Height/2 * s2.scale;
293        s2.x = 51*positionFactorX;
294        s2.y = 50*positionFactorY;
295        s2.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
296        Toasted.push_back(s2);
297
298        Letter a;
299        a.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/a.dds");
300        Textures.push_back(a.texture);
301        a.texture->GetLevelDesc(0, &desc);
302        a.scale = scaling/desc.Height;
303        a.centerX = desc.Width/2 * a.scale;
304        a.centerY = desc.Height/2 * a.scale;
305        a.x = 38*positionFactorX;
306        a.y = 50*positionFactorY;
307        a.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
308        Toasted.push_back(a);
309
310        Letter o4;
311        o4.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/o.dds");
312        Textures.push_back(o4.texture);
313        o4.texture->GetLevelDesc(0, &desc);
314        o4.scale = scaling/desc.Height;
315        o4.centerX = desc.Width/2 * o4.scale;
316        o4.centerY = desc.Height/2 * o4.scale;
317        o4.x = 25*positionFactorX;
318        o4.y = 50*positionFactorY;
319        o4.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
320        Toasted.push_back(o4);
321
322        Letter t2;
323        t2.texture = this->myScene->manager->resManager.loadTexture("./media/textures/letters/t.dds");
324        Textures.push_back(t2.texture);
325        t2.texture->GetLevelDesc(0, &desc);
326        t2.scale = scaling/desc.Height;
327        t2.centerX = desc.Width/2 * t2.scale;
328        t2.centerY = desc.Height/2 * t2.scale;
329        t2.x = 13*positionFactorX;
330        t2.y = 50*positionFactorY;
331        t2.rotation = (((float)rand()/RAND_MAX)-0.5f) * maxRotation;
332        Toasted.push_back(t2);
333
334        //create renderer
335        SPTR<Renderer> renderer(new HUDRenderer);
336        renderer->setScene(*this->myScene);
337        this->myScene->connectNodeAndRenderer(*this, renderer);
338}
339
340HUD::~HUD(void)
341{
342}
343
344void HUD::setTextures(std::string texture0, std::string texture1, std::string texture2, std::string texture3, std::string texture4, float scaleUserPlayer, float scaleAIPlayer) {
345        this->texture0 = texture0;
346        this->texture1 = texture1;
347        this->texture2 = texture2;
348        this->texture3 = texture3;
349        this->texture4 = texture4;
350        this->scaleUserPlayer = scaleUserPlayer;
351        this->scaleAIPlayer = scaleAIPlayer;
352}
353
354/*LPD3DXSPRITE* HUD::getSprite() {
355        return &this->sprite;
356}*/
357
358void HUD::setCrosshair(std::string crosshair, float scaleX, float scaleY) {
359        this->crosshair = crosshair;
360        this->scaleCrosshairX = scaleX;
361        this->scaleCrosshairY = scaleY;
362}
363
364float HUD::getScaleCrosshairX() {
365        return this->scaleCrosshairX;
366}
367
368float HUD::getScaleCrosshairY() {
369        return this->scaleCrosshairY;
370}
371
372void HUD::setRadar(std::string radar, float scaleX, float scaleY, float RadarOffsetX, float RadarOffsetY) {
373        this->radar = radar;
374        this->scaleRadarX = scaleX;
375        this->scaleRadarY = scaleY;
376        this->RadarOffsetX = RadarOffsetX;
377        this->RadarOffsetY = RadarOffsetY;
378}
379
380float HUD::getScaleRadarX() {
381        return this->scaleRadarX;
382}
383
384float HUD::getScaleRadarY() {
385        return this->scaleRadarY;
386}
387
388float HUD::getRadarOffsetX() {
389        return this->RadarOffsetX;
390}
391
392float HUD::getRadarOffsetY() {
393        return this->RadarOffsetY;
394}
395
396float HUD::getScaleUserPlayer() {
397        return this->scaleUserPlayer;
398}
399
400float HUD::getScaleAIPlayer() {
401        return this->scaleAIPlayer;
402}
403
404void HUD::message(std::string _message, float _seconds, float _dt, bool _bHelp) {
405        this->bHelp = _bHelp;
406        this->messagetimer = 0;
407        this->messagethreshold = _seconds;
408        std::wstring bla(_message.begin(), _message.end());
409        this->messagestring = bla;
410        this->messagedt = _dt;
411}
412
413void HUD::setTime(int minutes, int seconds) {
414        this->minutes = minutes;
415        this->seconds = seconds;
416}
417
418void HUD::displayWin(float _seconds, float _dt) {
419        this->youwintimer = 0;
420        this->youwinthreshold = _seconds;
421        this->youwindt = _dt;
422}
423
424void HUD::displayLose(float _seconds, float _dt) {
425        this->youlosetimer= 0;
426        this->youlosethreshold = _seconds;
427        this->youlosedt = _dt;
428}
429
430void HUD::displayToasted(float _seconds, float _dt) {
431        this->toastedtimer= 0;
432        this->toastedthreshold = _seconds;
433        this->toasteddt = _dt;
434}
435
436void HUD::setAmmo(int amount) {
437        this->ammoAmount = amount;
438}
Note: See TracBrowser for help on using the repository browser.