1 #include "Graphics.h"
2 #include "Maths.h"
3 #include "Entity.h"
4 #include "Map.h"
5 #include "Screen.h"
6
Graphics()7 Graphics::Graphics()
8 {
9 flipmode = false;
10 setRect(tiles_rect, 0,0,8,8);
11 setRect(sprites_rect, 0,0,32,32);
12 setRect(bfont_rect, 0,0,8,8);
13 setRect(bfontmask_rect, 0,0,8,8);
14 setRect(bg_rect, 0,0,320,240);
15 setRect(footerrect, 0, 230, 320, 10);
16 setRect(prect, 0, 0, 4, 4);
17 setRect(line_rect, 0,0,0,0);
18 setRect(tele_rect,0,0,96,96);
19
20
21 //We initialise a few things
22 //updatebackground = true;
23
24
25 //ct = new ColorTransform(0, 0, 0, 1, 255, 255, 255, 1); //Set to white
26
27 linestate = 0;
28
29
30 trinketcolset = false;
31
32 showcutscenebars = false;
33 cutscenebarspos = 0;
34
35 flipmode = false;
36 setflipmode = false;
37 //flipmatrix.scale(1, -1);
38 //flipmatrix.translate(0, 240);
39 //flipfontmatrix.scale(1, -1); flipfontmatrix.translate(0, 8);
40 //flipfontmatrix2.scale(1, -1); flipfontmatrix2.translate(0, 9);
41
42 //Background inits
43 for (int i = 0; i < 50; i++)
44 {
45 SDL_Rect s = {Sint16(fRandom() * 320), Sint16(fRandom() * 240), 2, 2};
46 int s2 = 4+(fRandom()*4);
47 stars.push_back(s);
48 starsspeed.push_back(s2);
49
50 SDL_Rect bb;
51 int bvx = 0;
52 int bvy = 0;
53 if(fRandom()*100 > 50)
54 {
55 bvx = 9 - (fRandom() * 19);
56 if (bvx > -6 && bvx < 6) bvx = 6;
57 bvx = bvx * 1.5;
58 setRect(bb, fRandom() * 320, fRandom() * 240, 32, 12);
59 }
60 else
61 {
62 bvy = 9 - (fRandom() * 19);
63 if (bvy > -6 && bvy < 6) bvy = 6;
64 bvy = bvy * 1.5;
65 setRect(bb, fRandom() * 320, fRandom() * 240, 12, 32) ;
66 }
67 float bint = 0.5 + ((fRandom() * 100) / 200);
68 backboxes.push_back(bb);
69 backboxvx.push_back(bvx);
70 backboxvy.push_back(bvy);
71 backboxint.push_back(bint);
72 }
73 //backboxrect = new Rectangle();
74 backoffset = 0;
75 backgrounddrawn = false;
76
77 warpskip = 0;
78 warpfcol = 0x000000;
79 warpbcol = 0x000000;
80
81 spcol = 0;
82 spcoldel = 0;
83 rcol = 0;
84
85 crewframe = 0;
86 crewframedelay = 4;
87 menuoffset = 0;
88 resumegamemode = false;
89
90 //Textboxes!
91 for (int i = 0; i < 30; i++)
92 {
93 textboxclass t;
94 textbox.push_back(t);
95 }
96 ntextbox = 0;
97
98 //Fading stuff
99 for (int i = 0; i < 15; i++)
100 {
101 fadebars.push_back(0);
102 }
103 fadeamount = 0;
104 fademode = 0;
105
106
107
108 }
109
~Graphics()110 Graphics::~Graphics()
111 {
112
113 }
114
drawspritesetcol(int x,int y,int t,int c,UtilityClass & help)115 void Graphics::drawspritesetcol(int x, int y, int t, int c, UtilityClass& help)
116 {
117 SDL_Rect rect;
118 setRect(rect,x,y,sprites_rect.w,sprites_rect.h);
119 setcol(c, help);
120
121 BlitSurfaceColoured(sprites[t],NULL,backBuffer, &rect, ct);
122 //.copyPixels(sprites[t], sprites_rect, backbuffer, tpoint);
123 }
124
Makebfont()125 void Graphics::Makebfont()
126 {
127 for (int j = 0; j < 16; j++)
128 {
129 for (int i = 0; i < 16; i++)
130 {
131
132 SDL_Surface* temp = GetSubSurface(grphx.im_bfont,i*8,j*8,8,8);
133 bfont.push_back(temp);
134
135 temp = GetSubSurface(grphx.im_bfont,i*8,j*8,8,8);
136 SDL_Surface* TempFlipped = FlipSurfaceVerticle(temp);
137
138 flipbfont.push_back(TempFlipped);
139 SDL_FreeSurface(temp);
140
141 }
142 }
143
144 //Ok, now we work out the lengths (this data string cortesy of a program I wrote!)
145 for (int i = 0; i < 256; i++)
146 {
147 bfontlen.push_back(6);
148 }
149
150
151 for(int k = 0; k < 96; k++)
152 {
153 bfontlen[k + 32] = 8;// int(maprow[k]);
154 }
155 }
156
MakeTileArray()157 void Graphics::MakeTileArray()
158 {
159 for(int j = 0; j <30; j++)
160 {
161 for(int i = 0; i <40; i++)
162 {
163 SDL_Surface* temp = GetSubSurface(grphx.im_tiles,i*8,j*8,8,8);
164 tiles.push_back(temp);
165 }
166 }
167 for(int j = 0; j <30; j++)
168 {
169 for(int i = 0; i <40; i++)
170 {
171 SDL_Surface* temp = GetSubSurface(grphx.im_tiles2,i*8,j*8,8,8);
172 tiles2.push_back(temp);
173 }
174 }
175
176 for(int j = 0; j <30; j++)
177 {
178 for(int i = 0; i <30; i++)
179 {
180 SDL_Surface* temp = GetSubSurface(grphx.im_tiles3,i*8,j*8,8,8);
181 tiles3.push_back(temp);
182 }
183 }
184
185 for(int j = 0; j <60; j++)
186 {
187 for(int i = 0; i <12; i++)
188 {
189 SDL_Surface* temp = GetSubSurface(grphx.im_entcolours,i*8,j*8,8,8);
190 entcolours.push_back(temp);
191 }
192 }
193 }
194
maketelearray()195 void Graphics::maketelearray()
196 {
197 for (int i = 0; i < 10; i++)
198 {
199 SDL_Surface* temp = GetSubSurface(grphx.im_teleporter,i*96,0,96,96);
200 tele.push_back(temp);
201 }
202 }
203
MakeSpriteArray()204 void Graphics::MakeSpriteArray()
205 {
206 for(int j = 0; j <16; j++)
207 {
208 for(int i = 0; i <12; i++)
209 {
210 SDL_Surface* temp = GetSubSurface(grphx.im_sprites,i*32,j*32,32,32);
211 sprites.push_back(temp);
212 temp = GetSubSurface(grphx.im_flipsprites,i*32,j*32,32,32);
213 flipsprites.push_back(temp);
214 }
215 }
216 }
217
218
Print(int _x,int _y,std::string _s,int r,int g,int b,bool cen)219 void Graphics::Print( int _x, int _y, std::string _s, int r, int g, int b, bool cen /*= false*/ )
220 {
221 r = clamp(r,0,255);
222 g = clamp(g,0,255);
223 b = clamp(b,0,255);
224
225 ct.colour = getRGB(r, g, b);
226
227 if (cen)
228 _x = ((160 ) - ((len(_s)) / 2));
229 int bfontpos = 0;
230 int curr;
231 for (unsigned int i = 0; i < _s.length(); i++)
232 {
233 curr = (_s.c_str())[i];
234 if (curr > 255 || curr < 0)
235 {
236 curr = '?';
237 }
238 point tpoint;
239 tpoint.x = _x + bfontpos;
240 tpoint.y = _y;
241
242 SDL_Rect fontRect = bfont_rect;
243 fontRect.x = tpoint.x ;
244 fontRect.y = tpoint.y ;
245
246 if (flipmode)
247 {
248 BlitSurfaceColoured( flipbfont[curr], NULL, backBuffer, &fontRect , ct);
249 }
250 else
251 {
252 BlitSurfaceColoured( bfont[curr], NULL, backBuffer, &fontRect , ct);
253 }
254 bfontpos+=bfontlen[curr] ;
255 }
256 }
257
258
bigprint(int _x,int _y,std::string _s,int r,int g,int b,bool cen,int sc)259 void Graphics::bigprint( int _x, int _y, std::string _s, int r, int g, int b, bool cen, int sc )
260 {
261 r = clamp(r,0,255);
262 g = clamp(g,0,255);
263 b = clamp(b,0,255);
264
265 ct.colour = getRGB(r, g, b);
266
267 if (cen)
268 {
269 _x = std::max(160 - (int((len(_s)/ 2.0)*sc)), 0 );
270 }
271
272 int bfontpos = 0;
273 int curr;
274 for (unsigned int i = 0; i < _s.length(); i++)
275 {
276 curr = (_s.c_str())[i];
277 if (curr > 255 || curr < 0)
278 {
279 curr = '?';
280 }
281
282 /*
283 point tpoint;
284 tpoint.x = _x + bfontpos;
285 tpoint.y = _y;
286
287 SDL_Rect fontRect = bfont_rect;
288 fontRect.x = tpoint.x ;
289 fontRect.y = tpoint.y ;
290 */
291
292 if (flipmode)
293 {
294 SDL_Surface* tempPrint = ScaleSurfaceSlow(flipbfont[curr], bfont[curr]->w *sc,bfont[curr]->h *sc);
295 SDL_Rect printrect = { Sint16((_x) + bfontpos), Sint16(_y) , Sint16(bfont_rect.w*sc), Sint16(bfont_rect.h * sc)};
296 BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct);
297 SDL_FreeSurface(tempPrint);
298 }
299 else
300 {
301 SDL_Surface* tempPrint = ScaleSurfaceSlow(bfont[curr], bfont[curr]->w *sc,bfont[curr]->h *sc);
302 SDL_Rect printrect = { static_cast<Sint16>((_x) + bfontpos), static_cast<Sint16>(_y) , static_cast<Sint16>((bfont_rect.w*sc)+1), static_cast<Sint16>((bfont_rect.h * sc)+1)};
303 BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct);
304 SDL_FreeSurface(tempPrint);
305 }
306 bfontpos+=bfontlen[curr] *sc;
307 }
308 }
309
len(std::string t)310 int Graphics::len(std::string t)
311 {
312 int bfontpos = 0;
313 for (unsigned int i = 0; i < t.length(); i++)
314 {
315 int cur = (t.c_str())[i];
316 bfontpos+= bfontlen[cur] ;
317 }
318 return bfontpos;
319 }
320
PrintOff(int _x,int _y,std::string _s,int r,int g,int b,bool cen)321 void Graphics::PrintOff( int _x, int _y, std::string _s, int r, int g, int b, bool cen /*= false*/ )
322 {
323 r = clamp(r,0,255);
324 g = clamp(g,0,255);
325 b = clamp(b,0,255);
326
327 ct.colour = getRGB(r, g, b);
328
329 if (cen)
330 _x = ((160) - (len(_s) / 2))+_x;
331 int bfontpos = 0;
332 int curr;
333 for (unsigned int i = 0; i < _s.length(); i++)
334 {
335 curr = (_s.c_str())[i];
336 if (curr > 255 || curr < 0)
337 {
338 curr = '?';
339 }
340 point tpoint;
341 tpoint.x = _x + bfontpos;
342 tpoint.y = _y;
343
344 SDL_Rect fontRect = bfont_rect;
345 fontRect.x = tpoint.x ;
346 fontRect.y = tpoint.y ;
347
348 if (flipmode)
349 {
350 //flipbfont[cur].colorTransform(bfont_rect, ct);
351 BlitSurfaceColoured( bfont[curr], NULL, backBuffer, &fontRect , ct);
352 }
353 else
354 {
355 //bfont[cur].colorTransform(bfont_rect, ct);
356 //backBuffer.copyPixels(bfont[cur], bfont_rect, tpoint);
357 BlitSurfaceColoured( bfont[curr], NULL, backBuffer, &fontRect , ct);
358 }
359 bfontpos+=bfontlen[curr] ;
360 }
361 }
362
bprint(int x,int y,std::string t,int r,int g,int b,bool cen)363 void Graphics::bprint( int x, int y, std::string t, int r, int g, int b, bool cen /*= false*/ )
364 {
365
366 //printmask(x, y, t, cen);
367 //Print(x, y - 1, t, 0, 0, 0, cen);
368 //if (cen)
369 //{
370 // //TODO find different
371 // PrintOff(-1, y, t, 0, 0, 0, cen);
372 // PrintOff(1, y, t, 0, 0, 0, cen);
373 //}
374 //else
375 //{
376 // Print(x -1, y, t, 0, 0, 0, cen);
377 // Print(x , y, t, 0, 0, 0, cen);
378 //}
379 //Print(x, y+1, t, 0, 0, 0, cen);
380
381 Print(x, y, t, r, g, b, cen);
382 }
383
RPrint(int _x,int _y,std::string _s,int r,int g,int b,bool cen)384 void Graphics::RPrint( int _x, int _y, std::string _s, int r, int g, int b, bool cen /*= false*/ )
385 {
386 r = clamp(r,0,255);
387 g = clamp(g,0,255);
388 b = clamp(b,0,255);
389 ct.colour = getRGB(r, g, b);
390
391 if (cen)
392 _x = ((308) - (_s.length() / 2));
393 int bfontpos = 0;
394 int curr;
395 for (unsigned int i = 0; i < _s.length(); i++)
396 {
397 curr = (_s.c_str())[i];
398 if (curr > 255 || curr < 0)
399 {
400 curr = '?';
401 }
402 point tpoint;
403 tpoint.x = _x + bfontpos;
404 tpoint.y = _y;
405
406 SDL_Rect fontRect = bfont_rect;
407 fontRect.x = tpoint.x ;
408 fontRect.y = tpoint.y ;
409
410 if (flipmode)
411 {
412 //flipbfont[cur].colorTransform(bfont_rect, ct);
413 BlitSurfaceColoured( flipbfont[curr], NULL, backBuffer, &fontRect , ct);
414 }
415 else
416 {
417 //bfont[cur].colorTransform(bfont_rect, ct);
418 //backBuffer.copyPixels(bfont[cur], bfont_rect, tpoint);
419 BlitSurfaceColoured( bfont[curr], NULL, backBuffer, &fontRect , ct);
420 }
421 bfontpos+=bfontlen[curr] ;
422 }
423 }
424
printcrewname(int x,int y,int t)425 void Graphics::printcrewname( int x, int y, int t )
426 {
427 //Print the name of crew member t in the right colour
428 switch(t)
429 {
430 case 0:
431 Print(x, y, "Viridian", 16, 240, 240,false );
432 break;
433 case 1:
434 Print(x, y, "Violet", 240, 16, 240,false);
435 break;
436 case 2:
437 Print(x, y, "Vitellary", 240, 240, 16,false);
438 break;
439 case 3:
440 Print(x, y, "Vermilion", 240, 16, 16,false);
441 break;
442 case 4:
443 Print(x, y, "Verdigris", 16, 240, 16,false);
444 break;
445 case 5:
446 Print(x, y, "Victoria", 16, 16, 240,false);
447 break;
448 }
449 }
450
printcrewnamedark(int x,int y,int t)451 void Graphics::printcrewnamedark( int x, int y, int t )
452 {
453 //Print the name of crew member t as above, but in black and white
454 switch(t)
455 {
456 case 0:
457 Print(x, y, "Viridian", 128,128,128,false);
458 break;
459 case 1:
460 Print(x, y, "Violet", 128,128,128,false);
461 break;
462 case 2:
463 Print(x, y, "Vitellary", 128,128,128,false);
464 break;
465 case 3:
466 Print(x, y, "Vermilion", 128,128,128,false);
467 break;
468 case 4:
469 Print(x, y, "Verdigris", 128,128,128,false);
470 break;
471 case 5:
472 Print(x, y, "Victoria", 128,128,128,false);
473 break;
474 }
475 }
476
printcrewnamestatus(int x,int y,int t)477 void Graphics::printcrewnamestatus( int x, int y, int t )
478 {
479 //Print the status of crew member t in the right colour
480 switch(t)
481 {
482 case 0:
483 Print(x, y, "(that's you!)", 12, 140, 140,false);
484 break;
485 case 1:
486 Print(x, y, "Rescued!", 140, 12, 140,false);
487 break;
488 case 2:
489 Print(x, y, "Rescued!", 140, 140, 12,false);
490 break;
491 case 3:
492 Print(x, y, "Rescued!", 140, 12, 12,false);
493 break;
494 case 4:
495 Print(x, y, "Rescued!", 12, 140, 12,false);
496 break;
497 case 5:
498 Print(x, y, "Rescued!", 12, 12, 140,false);
499 break;
500 }
501 }
502
drawsprite(int x,int y,int t,int r,int g,int b)503 void Graphics::drawsprite( int x, int y, int t, int r, int g, int b )
504 {
505 SDL_Rect rect = { Sint16(x), Sint16(y), sprites_rect.w, sprites_rect.h };
506 setcolreal(getRGB(r,g,b));
507 //sprites[t].colorTransform(sprites_rect, ct);
508 BlitSurfaceColoured(sprites[t], NULL, backBuffer, &rect, ct);
509 }
510
drawtile(int x,int y,int t,int r,int g,int b)511 void Graphics::drawtile( int x, int y, int t, int r, int g, int b )
512 {
513 SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
514 BlitSurfaceStandard(tiles[t], NULL, backBuffer, &rect);
515 }
516
517
drawtile2(int x,int y,int t,int r,int g,int b)518 void Graphics::drawtile2( int x, int y, int t, int r, int g, int b )
519 {
520 SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
521 BlitSurfaceStandard(tiles2[t], NULL, backBuffer, &rect);
522 }
523
524
525
drawtile3(int x,int y,int t,int off)526 void Graphics::drawtile3( int x, int y, int t, int off )
527 {
528 SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
529 BlitSurfaceStandard(tiles3[t+(off*30)], NULL, backBuffer, &rect);
530 }
531
drawentcolours(int x,int y,int t)532 void Graphics::drawentcolours( int x, int y, int t)
533 {
534 SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
535 BlitSurfaceStandard(entcolours[t], NULL, backBuffer, &rect);
536 }
537
drawtowertile(int x,int y,int t)538 void Graphics::drawtowertile( int x, int y, int t )
539 {
540 SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
541 BlitSurfaceStandard(tiles2[t], NULL, towerbuffer, &rect);
542 }
543
544
drawtowertile3(int x,int y,int t,int off)545 void Graphics::drawtowertile3( int x, int y, int t, int off )
546 {
547 SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
548 BlitSurfaceStandard(tiles3[t+(off*30)], NULL, towerbuffer, &rect);
549 }
550
drawgui(UtilityClass & help)551 void Graphics::drawgui( UtilityClass& help )
552 {
553 textboxcleanup();
554 //Draw all the textboxes to the screen
555 for (int i = 0; i<ntextbox; i++)
556 {
557 //This routine also updates the textboxs
558 textbox[i].update();
559 if (textbox[i].active)
560 {
561 if (textbox[i].r == 0 && textbox[i].g == 0 && textbox[i].b == 0)
562 {
563 if(flipmode)
564 {
565 for (j = 0; j < textbox[i].numlines; j++)
566 {
567 Print(textbox[i].xp + 8, textbox[i].yp + (textbox[i].numlines*8) - (j * 8), textbox[i].line[j], 196, 196, 255 - help.glow);
568 }
569 }
570 else
571 {
572 for (j = 0; j < textbox[i].numlines; j++)
573 {
574 Print(textbox[i].xp + 8, textbox[i].yp + 8 + (j * 8), textbox[i].line[j], 196, 196, 255 - help.glow);
575 }
576 }
577 }
578 else
579 {
580
581 FillRect(backBuffer,textbox[i].textrect, textbox[i].r/6, textbox[i].g/6, textbox[i].b / 6 );
582
583 drawcoloredtile(textbox[i].xp, textbox[i].yp, 40, textbox[i].r, textbox[i].g, textbox[i].b);
584 drawcoloredtile(textbox[i].xp+textbox[i].w-8, textbox[i].yp, 42, textbox[i].r, textbox[i].g, textbox[i].b);
585 drawcoloredtile(textbox[i].xp, textbox[i].yp+textbox[i].h-8, 45, textbox[i].r, textbox[i].g, textbox[i].b);
586 drawcoloredtile(textbox[i].xp+textbox[i].w-8, textbox[i].yp+textbox[i].h-8, 47, textbox[i].r, textbox[i].g, textbox[i].b);
587 for (int k = 0; k < textbox[i].lw; k++)
588 {
589 drawcoloredtile(textbox[i].xp + 8 + (k * 8), textbox[i].yp, 41, textbox[i].r, textbox[i].g, textbox[i].b);
590 drawcoloredtile(textbox[i].xp + 8 + (k * 8), textbox[i].yp+textbox[i].h-8, 46, textbox[i].r, textbox[i].g, textbox[i].b);
591 }
592 for (int k = 0; k < textbox[i].numlines; k++)
593 {
594 drawcoloredtile(textbox[i].xp, textbox[i].yp + 8 + (k * 8), 43, textbox[i].r, textbox[i].g, textbox[i].b);
595 drawcoloredtile(textbox[i].xp + textbox[i].w-8, textbox[i].yp + 8 + (k * 8), 44, textbox[i].r, textbox[i].g, textbox[i].b);
596 }
597
598 if(flipmode)
599 {
600 for (j = 0; j < textbox[i].numlines; j++)
601 {
602 Print(textbox[i].xp + 8, textbox[i].yp + (textbox[i].numlines*8) - (j * 8), textbox[i].line[j], textbox[i].r, textbox[i].g, textbox[i].b);
603 }
604 }
605 else
606 {
607 for (j = 0; j < textbox[i].numlines; j++)
608 {
609 Print(textbox[i].xp + 8, textbox[i].yp +8 + (j * 8), textbox[i].line[j], textbox[i].r, textbox[i].g, textbox[i].b);
610 }
611 }
612 }
613
614 if ((textbox[i].yp == 12 || textbox[i].yp == 180) && textbox[i].r == 165)
615 {
616 if (flipmode)
617 {
618 drawimage(5, 0, 180, true);
619 }
620 else
621 {
622 drawimage(0, 0, 12, true);
623 }
624 }
625 else if ((textbox[i].yp == 12 || textbox[i].yp == 180) && textbox[i].g == 165)
626 {
627 if (flipmode)
628 {
629 drawimage(6, 0, 180, true);
630 }
631 else
632 {
633 drawimage(4, 0, 12, true);
634 }
635 }
636 if (flipmode)
637 {
638 if (textbox[i].r == 175 && textbox[i].g == 175)
639 {
640 //purple guy
641 drawsprite(80 - 6, 64 + 48 + 4, 6, 220- help.glow/4 - int(fRandom()*20), 120- help.glow/4, 210 - help.glow/4);
642 }
643 else if (textbox[i].r == 175 && textbox[i].b == 175)
644 {
645 //red guy
646 drawsprite(80 - 6, 64 + 48+ 4, 6, 255 - help.glow/8, 70 - help.glow/4, 70 - help.glow / 4);
647 }
648 else if (textbox[i].r == 175)
649 {
650 //green guy
651 drawsprite(80 - 6, 64 + 48 + 4, 6, 120 - help.glow / 4 - int(fRandom() * 20), 220 - help.glow / 4, 120 - help.glow / 4);
652 }
653 else if (textbox[i].g == 175)
654 {
655 //yellow guy
656 drawsprite(80 - 6, 64 + 48+ 4, 6, 220- help.glow/4 - int(fRandom()*20), 210 - help.glow/4, 120- help.glow/4);
657 }
658 else if (textbox[i].b == 175)
659 {
660 //blue guy
661 drawsprite(80 - 6, 64 + 48+ 4, 6, 75, 75, 255- help.glow/4 - int(fRandom()*20));
662 }
663 }
664 else
665 {
666 if (textbox[i].r == 175 && textbox[i].g == 175)
667 {
668 //purple guy
669 drawsprite(80 - 6, 64 + 32 + 4, 0, 220- help.glow/4 - int(fRandom()*20), 120- help.glow/4, 210 - help.glow/4);
670 }
671 else if (textbox[i].r == 175 && textbox[i].b == 175)
672 {
673 //red guy
674 drawsprite(80 - 6, 64 + 32 + 4, 0, 255 - help.glow/8, 70 - help.glow/4, 70 - help.glow / 4);
675 }
676 else if (textbox[i].r == 175)
677 {
678 //green guy
679 drawsprite(80 - 6, 64 + 32 + 4, 0, 120 - help.glow / 4 - int(fRandom() * 20), 220 - help.glow / 4, 120 - help.glow / 4);
680 }
681 else if (textbox[i].g == 175)
682 {
683 //yellow guy
684 drawsprite(80 - 6, 64 + 32 + 4, 0, 220- help.glow/4 - int(fRandom()*20), 210 - help.glow/4, 120- help.glow/4);
685 }
686 else if (textbox[i].b == 175)
687 {
688 //blue guy
689 drawsprite(80 - 6, 64 + 32 + 4, 0, 75, 75, 255- help.glow/4 - int(fRandom()*20));
690 }
691 }
692 }
693 }
694 }
695
drawimagecol(int t,int xp,int yp,int r=0,int g=0,int b=0,bool cent)696 void Graphics::drawimagecol( int t, int xp, int yp, int r = 0, int g = 0, int b = 0, bool cent/*= false*/ )
697 {
698 SDL_Rect trect;
699 if(r+g+b != 0)
700 {
701 RGBf(r,g,b);
702 }
703
704 point tpoint;
705 if (cent)
706 {
707 tpoint.x = 160 - int(images[t]->w / 2);
708 tpoint.y = yp;
709 trect.x = tpoint.x ;
710 trect.y = tpoint.y;
711 trect.w = images[t]->w;
712 trect.h= images[t]->h;
713 BlitSurfaceColoured(images[t], NULL, backBuffer, &trect, ct);
714
715 }
716 else
717 {
718 trect.x = xp;
719 trect.y = yp;
720 trect.w = images[t]->w;
721 trect.h = images[t]->h;
722 BlitSurfaceColoured(images[t], NULL, backBuffer, &trect, ct);
723
724 }
725 }
726
drawimage(int t,int xp,int yp,bool cent)727 void Graphics::drawimage( int t, int xp, int yp, bool cent/*=false*/ )
728 {
729
730 SDL_Rect trect;
731 if (cent)
732 {
733 trect.x = 160 - int(images[t]->w / 2);
734 trect.y = yp;
735 trect.w = images[t]->w;
736 trect.h = images[t]->h;
737 BlitSurfaceStandard(images[t], NULL, backBuffer, &trect);
738 //backbuffer.copyPixels(images[t], trect, tpoint);
739 }
740 else
741 {
742
743 trect.x = xp;
744 trect.y = yp;
745 trect.w = images[t]->w;
746 trect.h= images[t]->h;
747
748 BlitSurfaceStandard(images[t], NULL, backBuffer, &trect);
749 }
750 }
751
drawpartimage(int t,int xp,int yp,int wp,int hp)752 void Graphics::drawpartimage( int t, int xp, int yp, int wp, int hp)
753 {
754 SDL_Rect trect;
755
756 trect.x = xp;
757 trect.y = yp;
758 trect.w = wp;
759 trect.h= hp;
760
761 SDL_Rect trect2;
762
763 trect2.x = 0;
764 trect2.y = 0;
765 trect2.w = wp;
766 trect2.h= hp;
767
768 BlitSurfaceStandard(images[t], &trect2, backBuffer, &trect);
769 }
770
cutscenebars()771 void Graphics::cutscenebars()
772 {
773 if (showcutscenebars)
774 {
775 cutscenebarspos += 25;
776 cutscenebarspos = std::min(cutscenebarspos, 361);
777 FillRect(backBuffer, 0, 0, cutscenebarspos, 16, 0x000000);
778 //backbuffer.fillRect(new Rectangle(0, 0, cutscenebarspos, 16), 0x000000);
779 FillRect(backBuffer, 360-cutscenebarspos, 224, cutscenebarspos, 16, 0x000000);
780 //backbuffer.fillRect(new Rectangle(360-cutscenebarspos, 224, cutscenebarspos, 16), 0x000000);
781 }
782 else
783 {
784 //disappearing
785 if (cutscenebarspos > 0)
786 {
787 cutscenebarspos -= 25;
788 cutscenebarspos = std::max(cutscenebarspos, 0);
789 //draw
790 FillRect(backBuffer, 0, 0, cutscenebarspos, 16, 0x000000);
791 //backbuffer.fillRect(new Rectangle(0, 0, cutscenebarspos, 16), 0x000000);
792 FillRect(backBuffer, 360-cutscenebarspos, 224, cutscenebarspos, 16, 0x000000);
793 //backbuffer.fillRect(new Rectangle(360-cutscenebarspos, 224, cutscenebarspos, 16), 0x000000);
794 }
795 }
796 }
797
drawcrewman(int x,int y,int t,bool act,UtilityClass & help,bool noshift)798 void Graphics::drawcrewman( int x, int y, int t, bool act, UtilityClass& help, bool noshift /*=false*/ )
799 {
800 if (!act)
801 {
802 if (noshift)
803 {
804 if (flipmode)
805 {
806 drawspritesetcol(x, y, 14, 19, help);
807 }
808 else
809 {
810 drawspritesetcol(x, y, 12, 19, help);
811 }
812 }
813 else
814 {
815 if (flipmode)
816 {
817 drawspritesetcol(x - 8, y, 14, 19, help);
818 }
819 else
820 {
821 drawspritesetcol(x - 8, y, 12, 19, help);
822 }
823 }
824 }
825 else
826 {
827 if (flipmode) crewframe += 6;
828
829 switch(t)
830 {
831 case 0:
832 drawspritesetcol(x, y, crewframe, 0 , help);
833 break;
834 case 1:
835 drawspritesetcol(x, y, crewframe, 20, help);
836 break;
837 case 2:
838 drawspritesetcol(x, y, crewframe, 14, help);
839 break;
840 case 3:
841 drawspritesetcol(x, y, crewframe, 15, help);
842 break;
843 case 4:
844 drawspritesetcol(x, y, crewframe, 13, help);
845 break;
846 case 5:
847 drawspritesetcol(x, y, crewframe, 16, help);
848 break;
849 }
850
851 if (flipmode) crewframe -= 6;
852 }
853 }
854
drawpixeltextbox(int x,int y,int w,int h,int w2,int h2,int r,int g,int b,int xo,int yo)855 void Graphics::drawpixeltextbox( int x, int y, int w, int h, int w2, int h2, int r, int g, int b, int xo, int yo )
856 {
857 //given these parameters, draw a textbox with a pixel width
858
859 //madrect.x = x; madrect.y = y; madrect.w = w; madrect.h = h;
860 //backbuffer.fillRect(madrect, RGB(r / 6, g / 6, b / 6));
861 FillRect(backBuffer,x,y,w,h, r/6, g/6, b/6 );
862
863 for (k = 0; k < w2-2; k++)
864 {
865 drawcoloredtile(x + 8-xo + (k * 8), y, 41, r, g, b);
866 drawcoloredtile(x + 8-xo + (k * 8), y + (h) - 8, 46, r, g, b);
867 }
868
869 for (k = 0; k < h2-2; k++)
870 {
871 drawcoloredtile(x, y + 8-yo + (k * 8), 43, r, g, b);
872 drawcoloredtile(x + (w) - 8, y + 8-yo + (k * 8), 44, r, g, b);
873 }
874
875 drawcoloredtile(x, y, 40, r, g, b);
876 drawcoloredtile(x + (w) - 8, y, 42, r, g, b);
877 drawcoloredtile(x, y + (h) - 8, 45, r, g, b);
878 drawcoloredtile(x + (w) - 8, y + (h) - 8, 47, r, g, b);
879 }
880
drawcustompixeltextbox(int x,int y,int w,int h,int w2,int h2,int r,int g,int b,int xo,int yo)881 void Graphics::drawcustompixeltextbox( int x, int y, int w, int h, int w2, int h2, int r, int g, int b, int xo, int yo )
882 {
883 //given these parameters, draw a textbox with a pixel width
884
885 //madrect.x = x; madrect.y = y; madrect.w = w; madrect.h = h;
886 //backbuffer.fillRect(madrect, RGB(r / 6, g / 6, b / 6));
887 FillRect(backBuffer,x,y,w,h, r/6, g/6, b/6 );
888
889 for (k = 0; k < w2-2; k++)
890 {
891 drawcoloredtile(x + 8-xo + (k * 8), y, 41, r, g, b);
892 drawcoloredtile(x + 8-xo + (k * 8), y + (h) - 8, 46, r, g, b);
893 }
894
895
896 drawcoloredtile(x+ (w) - 16, y, 41, r, g, b);
897 drawcoloredtile(x+ (w) - 16, y + (h) - 8, 46, r, g, b);
898 drawcoloredtile(x+ (w) - 24, y, 41, r, g, b);
899 drawcoloredtile(x+ (w) - 24, y + (h) - 8, 46, r, g, b);
900
901 for (k = 0; k < h2-2; k++)
902 {
903 drawcoloredtile(x, y + 8-yo + (k * 8), 43, r, g, b);
904 drawcoloredtile(x + (w) - 8, y + 8-yo + (k * 8), 44, r, g, b);
905 }
906
907 drawcoloredtile(x, y + (h) - 16, 43, r, g, b);
908 drawcoloredtile(x + (w) - 8, y + (h) - 16, 44, r, g, b);
909 drawcoloredtile(x, y + (h) - 24, 43, r, g, b);
910 drawcoloredtile(x + (w) - 8, y + (h) - 24, 44, r, g, b);
911
912 drawcoloredtile(x, y, 40, r, g, b);
913 drawcoloredtile(x + (w) - 8, y, 42, r, g, b);
914 drawcoloredtile(x, y + (h) - 8, 45, r, g, b);
915 drawcoloredtile(x + (w) - 8, y + (h) - 8, 47, r, g, b);
916 }
917
drawtextbox(int x,int y,int w,int h,int r,int g,int b)918 void Graphics::drawtextbox( int x, int y, int w, int h, int r, int g, int b )
919 {
920 //given these parameters, draw a textbox
921 //madrect.x = x; madrect.y = y; madrect.w = w*8; madrect.h = h*8;
922 //backbuffer.fillRect(madrect, RGB(r / 6, g / 6, b / 6));
923 FillRect(backBuffer,x,y,w*8,h*8, r/6, g/6, b/6 );
924
925 drawcoloredtile(x, y, 40, r, g, b);
926 drawcoloredtile(x + (w*8) - 8, y, 42, r, g, b);
927 drawcoloredtile(x, y + (h*8) - 8, 45, r, g, b);
928 drawcoloredtile(x + (w*8) - 8, y + (h*8) - 8, 47, r, g, b);
929
930 for (int k = 0; k < w-2; k++)
931 {
932 drawcoloredtile(x + 8 + (k * 8), y, 41, r, g, b);
933 drawcoloredtile(x + 8 + (k * 8), y + (h * 8) - 8, 46, r, g, b);
934 }
935
936 for (int k = 0; k < h-2; k++)
937 {
938 drawcoloredtile(x, y + 8 + (k * 8), 43, r, g, b);
939 drawcoloredtile(x + (w * 8) - 8, y + 8 + (k * 8), 44, r, g, b);
940 }
941 }
942
textboxactive()943 void Graphics::textboxactive()
944 {
945 //Remove all but the most recent textbox
946 for (int i = 0; i < ntextbox; i++)
947 {
948 if (m != i) textbox[i].remove();
949 }
950 }
951
textboxremovefast()952 void Graphics::textboxremovefast()
953 {
954 //Remove all textboxes
955 for (int i = 0; i < ntextbox; i++)
956 {
957 textbox[i].removefast();
958 }
959 }
960
textboxremove()961 void Graphics::textboxremove()
962 {
963 //Remove all textboxes
964 for (int i = 0; i < ntextbox; i++)
965 {
966 textbox[i].remove();
967 }
968 }
969
textboxtimer(int t)970 void Graphics::textboxtimer( int t )
971 {
972 textbox[m].timer=t;
973 }
974
addline(std::string t)975 void Graphics::addline( std::string t )
976 {
977 textbox[m].addline(t);
978 }
979
textboxadjust()980 void Graphics::textboxadjust()
981 {
982 textbox[m].adjust();
983 }
984
985
createtextbox(std::string t,int xp,int yp,int r,int g,int b)986 void Graphics::createtextbox( std::string t, int xp, int yp, int r/*= 255*/, int g/*= 255*/, int b /*= 255*/ )
987 {
988
989 if(ntextbox == 0)
990 {
991 //If there are no active textboxes, Z=0;
992 m = 0;
993 ntextbox++;
994 }
995 else
996 {
997 /*i = 0; m = -1;
998 while (i < ntextbox) {
999 if (!textbox[i].active) { m = i; i = ntextbox;}
1000 i++;
1001 }
1002 if (m == -1) {m = ntextbox; ntextbox++;}
1003 */
1004 m = ntextbox;
1005 ntextbox++;
1006 }
1007
1008 if(m<20)
1009 {
1010 textbox[m].clear();
1011 textbox[m].line[0] = t;
1012 textbox[m].xp = xp;
1013 if (xp == -1) textbox[m].xp = 160 - (((t.length() / 2) + 1) * 8);
1014 textbox[m].yp = yp;
1015 textbox[m].initcol(r, g, b);
1016 textbox[m].resize();
1017 }
1018 }
1019
drawfade()1020 void Graphics::drawfade()
1021 {
1022 if ((fademode == 1)||(fademode == 4))
1023 {
1024 FillRect(backBuffer, 0, 0, backBuffer->w, backBuffer->h, 0x000000);
1025 //backbuffer.fillRect(backbuffer.rect, 0x000000);
1026 }
1027 else if(fademode==3)
1028 {
1029 for (int i = 0; i < 15; i++)
1030 {
1031 FillRect(backBuffer, fadebars[i], i * 16, fadeamount, 16, 0x000000 );
1032 //backbuffer.fillRect(new Rectangle(, , , 16), 0x000000);
1033 }
1034 }
1035 else if(fademode==5 )
1036 {
1037 for (int i = 0; i < 15; i++)
1038 {
1039 FillRect(backBuffer, fadebars[i]-fadeamount, i * 16, 500, 16, 0x000000 );
1040 //backbuffer.fillRect(new Rectangle(fadebars[i]-fadeamount, i * 16, 500, 16), 0x000000);
1041 }
1042 }
1043
1044 }
1045
processfade()1046 void Graphics::processfade()
1047 {
1048 if (fademode > 1)
1049 {
1050 if (fademode == 2)
1051 {
1052 //prepare fade out
1053 for (int i = 0; i < 15; i++)
1054 {
1055 fadebars[i] = -int(fRandom() * 12) * 8;
1056 }
1057 fadeamount = 0;
1058 fademode = 3;
1059 }
1060 else if (fademode == 3)
1061 {
1062 fadeamount += 24;
1063 if (fadeamount > 416)
1064 {
1065 fademode = 1; //faded
1066 }
1067 }
1068 else if (fademode == 4)
1069 {
1070 //prepare fade in
1071 for (int i = 0; i < 15; i++)
1072 {
1073 fadebars[i] = 320 + int(fRandom() * 12) * 8;
1074 }
1075 fadeamount = 416;
1076 fademode = 5;
1077 }
1078 else if (fademode == 5)
1079 {
1080 fadeamount -= 24;
1081 if (fadeamount <= 0)
1082 {
1083 fademode = 0; //normal
1084 }
1085 }
1086 }
1087 }
1088
drawmenu(Game & game,int cr,int cg,int cb,int division)1089 void Graphics::drawmenu( Game& game, int cr, int cg, int cb, int division /*= 30*/ )
1090 {
1091 for (int i = 0; i < game.nummenuoptions; i++)
1092 {
1093 if (i == game.currentmenuoption)
1094 {
1095 //Draw it highlighted
1096 if (game.menuoptionsactive[i])
1097 {
1098 tempstring = game.menuoptions[i];
1099 std::transform(tempstring.begin(), tempstring.end(),tempstring.begin(), ::toupper);
1100 tempstring = std::string("[ ") + tempstring + std::string(" ]");
1101 Print(110 + (i * division) - 16 +game.menuxoff, 140 + (i * 12) +game.menuyoff, tempstring, cr, cg, cb);
1102 }
1103 else
1104 {
1105 tempstring = game.menuoptions[i];
1106 tempstring = "[ " + tempstring + " ]";
1107 //Draw it in gray
1108 Print(110 + (i * division) - 16 +game.menuxoff, 140 + (i * 12)+game.menuyoff, tempstring, 128, 128, 128);
1109 }
1110 }
1111 else
1112 {
1113 //Draw it normally
1114 if (game.menuoptionsactive[i])
1115 {
1116 Print(110 + (i * division) +game.menuxoff, 140 + (i * 12)+game.menuyoff, game.menuoptions[i], cr, cg, cb);
1117 }
1118 else
1119 {
1120 //Draw it in gray
1121 Print(110 + (i * division) +game.menuxoff, 140 + (i * 12)+game.menuyoff, game.menuoptions[i], 128, 128, 128);
1122 }
1123 }
1124 }
1125 }
1126
drawlevelmenu(Game & game,int cr,int cg,int cb,int division)1127 void Graphics::drawlevelmenu( Game& game, int cr, int cg, int cb, int division /*= 30*/ )
1128 {
1129 for (int i = 0; i < game.nummenuoptions; i++)
1130 {
1131 if (i == game.currentmenuoption)
1132 {
1133 if(game.nummenuoptions-i<=2){
1134 //Draw it highlighted
1135 if (game.menuoptionsactive[i])
1136 {
1137 tempstring = game.menuoptions[i];
1138 std::transform(tempstring.begin(), tempstring.end(),tempstring.begin(), ::toupper);
1139 tempstring = std::string("[ ") + tempstring + std::string(" ]");
1140 Print(110 + (i * division) - 16 +game.menuxoff, 140+8 + (i * 12) +game.menuyoff, tempstring, cr, cg, cb);
1141 }
1142 else
1143 {
1144 tempstring = game.menuoptions[i];
1145 tempstring = "[ " + tempstring + " ]";
1146 //Draw it in gray
1147 Print(110 + (i * division) - 16 +game.menuxoff, 140+8 + (i * 12)+game.menuyoff, tempstring, 128, 128, 128);
1148 }
1149 }else{
1150 //Draw it highlighted
1151 if (game.menuoptionsactive[i])
1152 {
1153 tempstring = game.menuoptions[i];
1154 std::transform(tempstring.begin(), tempstring.end(),tempstring.begin(), ::toupper);
1155 tempstring = std::string("[ ") + tempstring + std::string(" ]");
1156 Print(110 + (i * division) - 16 +game.menuxoff, 140 + (i * 12) +game.menuyoff, tempstring, cr, cg, cb);
1157 }
1158 else
1159 {
1160 tempstring = game.menuoptions[i];
1161 tempstring = "[ " + tempstring + " ]";
1162 //Draw it in gray
1163 Print(110 + (i * division) - 16 +game.menuxoff, 140 + (i * 12)+game.menuyoff, tempstring, 128, 128, 128);
1164 }
1165 }
1166 }
1167 else
1168 {
1169 if(game.nummenuoptions-i<=2){
1170 //Draw it normally
1171 if (game.menuoptionsactive[i])
1172 {
1173 Print(110 + (i * division) +game.menuxoff, 140+8 + (i * 12)+game.menuyoff, game.menuoptions[i], cr, cg, cb);
1174 }
1175 else
1176 {
1177 //Draw it in gray
1178 Print(110 + (i * division) +game.menuxoff, 140+8 + (i * 12)+game.menuyoff, game.menuoptions[i], 128, 128, 128);
1179 }
1180 }else{
1181 //Draw it normally
1182 if (game.menuoptionsactive[i])
1183 {
1184 Print(110 + (i * division) +game.menuxoff, 140 + (i * 12)+game.menuyoff, game.menuoptions[i], cr, cg, cb);
1185 }
1186 else
1187 {
1188 //Draw it in gray
1189 Print(110 + (i * division) +game.menuxoff, 140 + (i * 12)+game.menuyoff, game.menuoptions[i], 128, 128, 128);
1190 }
1191 }
1192 }
1193 }
1194 }
1195
1196
drawcoloredtile(int x,int y,int t,int r,int g,int b)1197 void Graphics::drawcoloredtile( int x, int y, int t, int r, int g, int b )
1198 {
1199 setcolreal(getRGB(r,g,b));
1200
1201 SDL_Rect rect;
1202 setRect(rect,x,y,tiles_rect.w,tiles_rect.h);
1203 BlitSurfaceColoured(tiles[t],NULL, backBuffer, &rect, ct );
1204 }
1205
1206
Hitest(SDL_Surface * surface1,point p1,int col,SDL_Surface * surface2,point p2,int col2)1207 bool Graphics::Hitest(SDL_Surface* surface1, point p1, int col, SDL_Surface* surface2, point p2, int col2)
1208 {
1209
1210 //find rectangle where they intersect:
1211
1212 int r1_left = p1.x;
1213 int r1_right = r1_left + surface1->w;
1214 int r2_left = p2.x;
1215 int r2_right = r2_left + surface2->w;
1216
1217 int r1_bottom = p1.y;
1218 int r1_top = p1.y + surface1->h;
1219 int r2_bottom = p2.y;
1220 int r2_top = p2.y + surface2->h;
1221
1222 bool intersection = intersectRect(r1_left, r1_right, r1_bottom, r1_top, r2_left, r2_right, r2_bottom, r2_top);
1223
1224 if(intersection)
1225 {
1226 int r3_left = std::max(r1_left, r2_left);
1227 int r3_top = std::min(r1_top, r2_top);
1228 int r3_right = std::min(r1_right, r2_right);
1229 int r3_bottom= std::max(r1_bottom, r2_bottom);
1230
1231 //for every pixel inside rectangle
1232 for(int x = r3_left; x < r3_right; x++)
1233 {
1234 for(int y = r3_bottom; y < r3_top; y++)
1235 {
1236 Uint32 pixel1 = ReadPixel(surface1 , x - p1.x, y - p1.y);
1237 Uint32 pixel2 = ReadPixel(surface2 , x - p2.x, y - p2.y);
1238 if ((pixel1 & 0x000000FF) && (pixel2 & 0x000000FF))
1239 {
1240 return true;
1241 }
1242 }
1243 }
1244 return false;
1245 }
1246 else
1247 {
1248 return false;
1249 }
1250
1251 }
1252
drawgravityline(int t,entityclass & obj)1253 void Graphics::drawgravityline( int t, entityclass& obj )
1254 {
1255 if (obj.entities[t].life == 0)
1256 {
1257 switch(linestate)
1258 {
1259 case 0:
1260 FillRect(backBuffer,line_rect, getRGB(200-20, 200-20, 200-20));
1261 break;
1262 case 1:
1263 FillRect(backBuffer,line_rect, getRGB(225-30, 245-30, 245-30));
1264 break;
1265 case 2:
1266 FillRect(backBuffer,line_rect, getRGB(245-30, 245-30, 225-30));
1267 break;
1268 case 3:
1269 FillRect(backBuffer,line_rect, getRGB(164-10, 200-20, 200-20));
1270 break;
1271 case 4:
1272 FillRect(backBuffer,line_rect, getRGB(224-20, 255-30, 196-20));
1273 break;
1274 case 5:
1275 FillRect(backBuffer,line_rect, getRGB(205-20, 235-30, 196-20));
1276 break;
1277 case 6:
1278 FillRect(backBuffer,line_rect, getRGB(164-10, 164-10, 164-10));
1279 break;
1280 case 7:
1281 FillRect(backBuffer,line_rect, getRGB(225-30, 245-30, 205-20));
1282 break;
1283 case 8:
1284 FillRect(backBuffer,line_rect, getRGB(205-20, 255-30, 225-30));
1285 break;
1286 case 9:
1287 FillRect(backBuffer,line_rect, getRGB(245-30, 245-30, 245-30));
1288 break;
1289 }
1290 }
1291 else
1292 {
1293 FillRect(backBuffer,line_rect, getRGB(96, 96, 96));
1294 }
1295 }
1296
drawtrophytext(entityclass & obj,UtilityClass & help)1297 void Graphics::drawtrophytext( entityclass& obj, UtilityClass& help )
1298 {
1299 int temp, temp2, temp3;
1300
1301 if (obj.trophytext < 15)
1302 {
1303 temp = (196 * obj.trophytext) / 15;
1304 temp2 = (196 * obj.trophytext) / 15;
1305 temp3 = ((255 - help.glow) * obj.trophytext) / 15;
1306 }
1307 else
1308 {
1309 temp = 196;
1310 temp2 = 196;
1311 temp3 = 255 - help.glow;
1312 }
1313 switch(obj.trophytype)
1314 {
1315 case 1:
1316 Print( -1, 6, "SPACE STATION 1 MASTERED", temp, temp2, temp3, true);
1317 Print( -1, 16, "Obtain a V Rank in this Time Trial", temp, temp2, temp3, true);
1318 break;
1319 case 2:
1320 Print( -1, 6, "LABORATORY MASTERED", temp, temp2, temp3, true);
1321 Print( -1, 16, "Obtain a V Rank in this Time Trial", temp, temp2, temp3, true);
1322 break;
1323 case 3:
1324 Print( -1, 6, "THE TOWER MASTERED", temp, temp2, temp3, true);
1325 Print( -1, 16, "Obtain a V Rank in this Time Trial", temp, temp2, temp3, true);
1326 break;
1327 case 4:
1328 Print( -1, 6, "SPACE STATION 2 MASTERED", temp, temp2, temp3, true);
1329 Print( -1, 16, "Obtain a V Rank in this Time Trial", temp, temp2, temp3, true);
1330 break;
1331 case 5:
1332 Print( -1, 6, "WARP ZONE MASTERED", temp, temp2, temp3, true);
1333 Print( -1, 16, "Obtain a V Rank in this Time Trial", temp, temp2, temp3, true);
1334 break;
1335 case 6:
1336 Print( -1, 6, "FINAL LEVEL MASTERED", temp, temp2, temp3, true);
1337 Print( -1, 16, "Obtain a V Rank in this Time Trial", temp, temp2, temp3, true);
1338 break;
1339 case 7:
1340 Print( -1, 6, "GAME COMPLETE", temp, temp2, temp3, true);
1341 Print( -1, 16, "Complete the game", temp, temp2, temp3, true);
1342 break;
1343 case 8:
1344 Print( -1, 6, "FLIP MODE COMPLETE", temp, temp2, temp3, true);
1345 Print( -1, 16, "Complete the game in flip mode", temp, temp2, temp3, true);
1346 break;
1347 case 9:
1348 Print( -1, 11, "Win with less than 50 deaths", temp, temp2, temp3, true);
1349 break;
1350 case 10:
1351 Print( -1, 11, "Win with less than 100 deaths", temp, temp2, temp3, true);
1352 break;
1353 case 11:
1354 Print( -1, 11, "Win with less than 250 deaths", temp, temp2, temp3, true);
1355 break;
1356 case 12:
1357 Print( -1, 11, "Win with less than 500 deaths", temp, temp2, temp3, true);
1358 break;
1359 case 13:
1360 Print( -1, 11, "Last 5 seconds on the Super Gravitron", temp, temp2, temp3, true);
1361 break;
1362 case 14:
1363 Print( -1, 11, "Last 10 seconds on the Super Gravitron", temp, temp2, temp3, true);
1364 break;
1365 case 15:
1366 Print( -1, 11, "Last 15 seconds on the Super Gravitron", temp, temp2, temp3, true);
1367 break;
1368 case 16:
1369 Print( -1, 11, "Last 20 seconds on the Super Gravitron", temp, temp2, temp3, true);
1370 break;
1371 case 17:
1372 Print( -1, 11, "Last 30 seconds on the Super Gravitron", temp, temp2, temp3, true);
1373 break;
1374 case 18:
1375 Print( -1, 11, "Last 1 minute on the Super Gravitron", temp, temp2, temp3, true);
1376 break;
1377 case 20:
1378 Print( -1, 6, "MASTER OF THE UNIVERSE", temp, temp2, temp3, true);
1379 Print( -1, 16, "Complete the game in no death mode", temp, temp2, temp3, true);
1380 break;
1381 }
1382 }
1383
drawentities(mapclass & map,entityclass & obj,UtilityClass & help)1384 void Graphics::drawentities( mapclass& map, entityclass& obj, UtilityClass& help )
1385 {
1386 //Update line colours!
1387 if (linedelay <= 0)
1388 {
1389 linestate++;
1390 if (linestate >= 10) linestate = 0;
1391 linedelay = 2;
1392 }
1393 else
1394 {
1395 linedelay--;
1396 }
1397
1398 point tpoint;
1399
1400 SDL_Rect drawRect;
1401
1402 trinketcolset = false;
1403
1404 for (int i = obj.nentity - 1; i >= 0; i--)
1405 {
1406 if (!obj.entities[i].invis && obj.entities[i].active)
1407 {
1408 if (obj.entities[i].size == 0)
1409 {
1410 // Sprites
1411 if (flipmode)
1412 {
1413 tpoint.x = obj.entities[i].xp;
1414 tpoint.y = obj.entities[i].yp;
1415 //
1416 setcol(obj.entities[i].colour, help);
1417 //flipsprites[obj.entities[i].drawframe].colorTransform(sprites_rect, ct);
1418 drawRect = sprites_rect;
1419 drawRect.x += tpoint.x;
1420 drawRect.y += tpoint.y;
1421 BlitSurfaceColoured(flipsprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1422 //backbuffer.copyPixels(flipsprites[obj.entities[i].drawframe], sprites_rect, tpoint);
1423 if (map.warpx)
1424 {
1425 //screenwrapping!
1426 if (tpoint.x < 0)
1427 {
1428 tpoint.x += 320;
1429 drawRect = sprites_rect;
1430 drawRect.x += tpoint.x;
1431 drawRect.y += tpoint.y;
1432 BlitSurfaceStandard(flipsprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1433 }
1434 if (tpoint.x > 300)
1435 {
1436 tpoint.x -= 320;
1437 drawRect = sprites_rect;
1438 drawRect.x += tpoint.x;
1439 drawRect.y += tpoint.y;
1440 BlitSurfaceStandard(flipsprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1441 }
1442 }
1443 else if (map.warpy)
1444 {
1445 if (tpoint.y < 0)
1446 {
1447 tpoint.y += 230;
1448 drawRect = sprites_rect;
1449 drawRect.x += tpoint.x;
1450 drawRect.y += tpoint.y;
1451 BlitSurfaceStandard(flipsprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1452 }
1453 if (tpoint.y > 210)
1454 {
1455 tpoint.y -= 230;
1456 drawRect = sprites_rect;
1457 drawRect.x += tpoint.x;
1458 drawRect.y += tpoint.y;
1459 BlitSurfaceStandard(flipsprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1460 }
1461 }
1462 }
1463 else
1464 {
1465 tpoint.x = obj.entities[i].xp;
1466 tpoint.y = obj.entities[i].yp;
1467 //
1468 setcol(obj.entities[i].colour, help);
1469 //sprites[obj.entities[i].drawframe].colorTransform(sprites_rect, ct);
1470
1471 drawRect = sprites_rect;
1472 drawRect.x += tpoint.x;
1473 drawRect.y += tpoint.y;
1474 BlitSurfaceColoured(sprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1475 if (map.warpx)
1476 {
1477 //screenwrapping!
1478 if (tpoint.x < 0)
1479 {
1480 tpoint.x += 320;
1481 drawRect = sprites_rect;
1482 drawRect.x += tpoint.x;
1483 drawRect.y += tpoint.y;
1484 BlitSurfaceColoured(sprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1485 }
1486 if (tpoint.x > 300)
1487 {
1488 tpoint.x -= 320;
1489 drawRect = sprites_rect;
1490 drawRect.x += tpoint.x;
1491 drawRect.y += tpoint.y;
1492 BlitSurfaceColoured(sprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1493 }
1494 }
1495 else if (map.warpy)
1496 {
1497 if (tpoint.y < 0)
1498 {
1499 tpoint.y += 230;
1500 drawRect = sprites_rect;
1501 drawRect.x += tpoint.x;
1502 drawRect.y += tpoint.y;
1503 BlitSurfaceColoured(sprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1504 }
1505 if (tpoint.y > 210)
1506 {
1507 tpoint.y -= 230;
1508 drawRect = sprites_rect;
1509 drawRect.x += tpoint.x;
1510 drawRect.y += tpoint.y;
1511 BlitSurfaceColoured(sprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1512 }
1513 }
1514 }
1515 }
1516 else if (obj.entities[i].size == 1)
1517 {
1518 // Tiles
1519 tpoint.x = obj.entities[i].xp;
1520 tpoint.y = obj.entities[i].yp;
1521 drawRect = tiles_rect;
1522 drawRect.x += tpoint.x;
1523 drawRect.y += tpoint.y;
1524 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1525 }
1526 else if (obj.entities[i].size == 2)
1527 {
1528 // Special: Moving platform, 4 tiles
1529 tpoint.x = obj.entities[i].xp;
1530 tpoint.y = obj.entities[i].yp;
1531 drawRect = tiles_rect;
1532 drawRect.x += tpoint.x;
1533 drawRect.y += tpoint.y;
1534 if(map.custommode){
1535 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1536 drawRect.x += 8;
1537 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1538 drawRect.x += 8;
1539 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1540 drawRect.x += 8;
1541 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1542 }else{
1543 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1544 drawRect.x += 8;
1545 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1546 drawRect.x += 8;
1547 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1548 drawRect.x += 8;
1549 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1550 }
1551 }
1552 else if (obj.entities[i].size == 3) // Big chunky pixels!
1553 {
1554 prect.x = obj.entities[i].xp;
1555 prect.y = obj.entities[i].yp;
1556 //A seperate index of colours, for simplicity
1557 if(obj.entities[i].colour==1)
1558 {
1559 //backbuffer.fillRect(prect, RGB(196 - (fRandom() * 64), 10, 10));
1560 FillRect(backBuffer, prect, (fRandom() * 64), 10, 10);
1561 }
1562 else if (obj.entities[i].colour == 2)
1563 {
1564 //backbuffer.fillRect(prect, RGB(160- help.glow/2 - (fRandom()*20), 200- help.glow/2, 220 - help.glow));
1565 FillRect(backBuffer,prect, int(160- help.glow/2 - (fRandom()*20)), 200- help.glow/2, 220 - help.glow);
1566 }
1567 }
1568 else if (obj.entities[i].size == 4) // Small pickups
1569 {
1570 drawhuetile(obj.entities[i].xp, obj.entities[i].yp, obj.entities[i].tile, obj.entities[i].colour);
1571 }
1572 else if (obj.entities[i].size == 5) //Horizontal Line
1573 {
1574 line_rect.x = obj.entities[i].xp;
1575 line_rect.y = obj.entities[i].yp;
1576 line_rect.w = obj.entities[i].w;
1577 line_rect.h = 1;
1578 drawgravityline(i, obj);
1579 }
1580 else if (obj.entities[i].size == 6) //Vertical Line
1581 {
1582 line_rect.x = obj.entities[i].xp;
1583 line_rect.y = obj.entities[i].yp;
1584 line_rect.w = 1;
1585 line_rect.h = obj.entities[i].h;
1586 drawgravityline(i, obj);
1587 }
1588 else if (obj.entities[i].size == 7) //Teleporter
1589 {
1590 drawtele(obj.entities[i].xp, obj.entities[i].yp, obj.entities[i].drawframe, obj.entities[i].colour, help);
1591 }
1592 else if (obj.entities[i].size == 8) // Special: Moving platform, 8 tiles
1593 {
1594 //TODO check this is correct game breaking moving paltform
1595 tpoint.x = obj.entities[i].xp;
1596 tpoint.y = obj.entities[i].yp;
1597 drawRect = sprites_rect;
1598 drawRect.x += tpoint.x;
1599 drawRect.y += tpoint.y;
1600
1601 if(map.custommode){
1602 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1603 drawRect.x += 8;
1604 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1605 drawRect.x += 8;
1606 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1607 drawRect.x += 8;
1608 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1609 drawRect.x += 8;
1610 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1611 drawRect.x += 8;
1612 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1613 drawRect.x += 8;
1614 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1615 drawRect.x += 8;
1616 BlitSurfaceStandard(entcolours[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1617 }else{
1618 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1619 drawRect.x += 8;
1620 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1621 drawRect.x += 8;
1622 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1623 drawRect.x += 8;
1624 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1625 drawRect.x += 8;
1626 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1627 drawRect.x += 8;
1628 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1629 drawRect.x += 8;
1630 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1631 drawRect.x += 8;
1632 BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect);
1633 }
1634 }
1635 else if (obj.entities[i].size == 9) // Really Big Sprite! (2x2)
1636 {
1637 if (flipmode)
1638 {
1639 setcol(obj.entities[i].colour, help);
1640
1641 tpoint.x = obj.entities[i].xp;
1642 tpoint.y = obj.entities[i].yp;
1643 //
1644 drawRect = sprites_rect;
1645 drawRect.x += tpoint.x;
1646 drawRect.y += tpoint.y;
1647 BlitSurfaceColoured(flipsprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1648
1649 tpoint.x = obj.entities[i].xp+32;
1650 tpoint.y = obj.entities[i].yp;
1651 //
1652 drawRect = sprites_rect;
1653 drawRect.x += tpoint.x;
1654 drawRect.y += tpoint.y;
1655 BlitSurfaceColoured(flipsprites[obj.entities[i].drawframe +1],NULL, backBuffer, &drawRect, ct);
1656
1657 tpoint.x = obj.entities[i].xp;
1658 tpoint.y = obj.entities[i].yp+32;
1659 //
1660 drawRect = sprites_rect;
1661 drawRect.x += tpoint.x;
1662 drawRect.y += tpoint.y;
1663 BlitSurfaceColoured(flipsprites[obj.entities[i].drawframe+ 12],NULL, backBuffer, &drawRect, ct);
1664
1665 tpoint.x = obj.entities[i].xp+32;
1666 tpoint.y = obj.entities[i].yp+32;
1667 //
1668 drawRect = sprites_rect;
1669 drawRect.x += tpoint.x;
1670 drawRect.y += tpoint.y;
1671 BlitSurfaceColoured(flipsprites[obj.entities[i].drawframe+ 13],NULL, backBuffer, &drawRect, ct);
1672 }
1673 else
1674 {
1675 setcol(obj.entities[i].colour, help);
1676
1677 tpoint.x = obj.entities[i].xp;
1678 tpoint.y = obj.entities[i].yp;
1679
1680 drawRect = sprites_rect;
1681 drawRect.x += tpoint.x;
1682 drawRect.y += tpoint.y;
1683 BlitSurfaceColoured(sprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1684
1685 tpoint.x = obj.entities[i].xp+32;
1686 tpoint.y = obj.entities[i].yp;
1687 //
1688 drawRect = sprites_rect;
1689 drawRect.x += tpoint.x;
1690 drawRect.y += tpoint.y;
1691 BlitSurfaceColoured(sprites[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct);
1692
1693 tpoint.x = obj.entities[i].xp;
1694 tpoint.y = obj.entities[i].yp+32;
1695 //
1696 drawRect = sprites_rect;
1697 drawRect.x += tpoint.x;
1698 drawRect.y += tpoint.y;
1699 BlitSurfaceColoured(sprites[obj.entities[i].drawframe+12],NULL, backBuffer, &drawRect, ct);
1700
1701 tpoint.x = obj.entities[i].xp+32;
1702 tpoint.y = obj.entities[i].yp+32;
1703 //
1704 drawRect = sprites_rect;
1705 drawRect.x += tpoint.x;
1706 drawRect.y += tpoint.y;
1707 BlitSurfaceColoured(sprites[obj.entities[i].drawframe + 13],NULL, backBuffer, &drawRect, ct);
1708 }
1709 }
1710 else if (obj.entities[i].size == 10) // 2x1 Sprite
1711 {
1712 if (flipmode)
1713 {
1714 setcol(obj.entities[i].colour, help);
1715
1716 tpoint.x = obj.entities[i].xp;
1717 tpoint.y = obj.entities[i].yp;
1718 //
1719 drawRect = sprites_rect;
1720 drawRect.x += tpoint.x;
1721 drawRect.y += tpoint.y;
1722 BlitSurfaceColoured(flipsprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1723
1724 tpoint.x = obj.entities[i].xp+32;
1725 tpoint.y = obj.entities[i].yp;
1726 //
1727 drawRect = sprites_rect;
1728 drawRect.x += tpoint.x;
1729 drawRect.y += tpoint.y;
1730 BlitSurfaceColoured(flipsprites[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct);
1731 }
1732 else
1733 {
1734 setcol(obj.entities[i].colour, help);
1735
1736 tpoint.x = obj.entities[i].xp;
1737 tpoint.y = obj.entities[i].yp;
1738 //
1739 drawRect = sprites_rect;
1740 drawRect.x += tpoint.x;
1741 drawRect.y += tpoint.y;
1742 BlitSurfaceColoured(sprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1743
1744 tpoint.x = obj.entities[i].xp+32;
1745 tpoint.y = obj.entities[i].yp;
1746 //
1747 drawRect = sprites_rect;
1748 drawRect.x += tpoint.x;
1749 drawRect.y += tpoint.y;
1750 BlitSurfaceColoured(sprites[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct);
1751 }
1752 }
1753 else if (obj.entities[i].size == 11) //The fucking elephant
1754 {
1755 //TODO elephant bug
1756 setcol(obj.entities[i].colour, help);
1757 drawimagecol(3, obj.entities[i].xp, obj.entities[i].yp);
1758 }
1759 else if (obj.entities[i].size == 12) // Regular sprites that don't wrap
1760 {
1761 if (flipmode)
1762 {
1763 //forget this for a minute;
1764 tpoint.x = obj.entities[i].xp;
1765 tpoint.y = obj.entities[i].yp;
1766 setcol(obj.entities[i].colour, help);
1767 //
1768
1769 drawRect = sprites_rect;
1770 drawRect.x += tpoint.x;
1771 drawRect.y += tpoint.y;
1772 BlitSurfaceColoured(flipsprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1773
1774 //if we're outside the screen, we need to draw indicators
1775 if (obj.entities[i].xp < -20 && obj.entities[i].vx > 0)
1776 {
1777 if (obj.entities[i].xp < -100)
1778 {
1779 tpoint.x = -5 + (int(( -obj.entities[i].xp) / 10));
1780 }
1781 else
1782 {
1783 tpoint.x = 5;
1784 }
1785
1786 tpoint.y = tpoint.y+4;
1787 setcol(23, help);
1788
1789 drawRect = tiles_rect;
1790 drawRect.x += tpoint.x;
1791 drawRect.y += tpoint.y;
1792 BlitSurfaceColoured(tiles[1167],NULL, backBuffer, &drawRect, ct);
1793
1794 }
1795 else if (obj.entities[i].xp > 340 && obj.entities[i].vx < 0)
1796 {
1797 if (obj.entities[i].xp > 420)
1798 {
1799 tpoint.x = 320 - (int(( obj.entities[i].xp-320) / 10));
1800 }
1801 else
1802 {
1803 tpoint.x = 310;
1804 }
1805
1806 tpoint.y = tpoint.y+4;
1807 setcol(23, help);
1808 //
1809
1810 drawRect = tiles_rect;
1811 drawRect.x += tpoint.x;
1812 drawRect.y += tpoint.y;
1813 BlitSurfaceColoured(tiles[1166],NULL, backBuffer, &drawRect, ct);
1814 }
1815 }
1816 else
1817 {
1818 tpoint.x = obj.entities[i].xp;
1819 tpoint.y = obj.entities[i].yp;
1820 setcol(obj.entities[i].colour, help);
1821 //
1822 drawRect = sprites_rect;
1823 drawRect.x += tpoint.x;
1824 drawRect.y += tpoint.y;
1825 BlitSurfaceColoured(sprites[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct);
1826
1827
1828 //if we're outside the screen, we need to draw indicators
1829
1830 if (obj.entities[i].xp < -20 && obj.entities[i].vx > 0)
1831 {
1832 if (obj.entities[i].xp < -100)
1833 {
1834 tpoint.x = -5 + (int(( -obj.entities[i].xp) / 10));
1835 }
1836 else
1837 {
1838 tpoint.x = 5;
1839 }
1840
1841 tpoint.y = tpoint.y+4;
1842 setcol(23, help);
1843
1844
1845 drawRect = tiles_rect;
1846 drawRect.x += tpoint.x;
1847 drawRect.y += tpoint.y;
1848 BlitSurfaceColoured(tiles[1167],NULL, backBuffer, &drawRect, ct);
1849
1850 }
1851 else if (obj.entities[i].xp > 340 && obj.entities[i].vx < 0)
1852 {
1853 if (obj.entities[i].xp > 420)
1854 {
1855 tpoint.x = 320 - (int(( obj.entities[i].xp-320) / 10));
1856 }
1857 else
1858 {
1859 tpoint.x = 310;
1860 }
1861
1862 tpoint.y = tpoint.y+4;
1863 setcol(23, help);
1864 //
1865
1866 drawRect = tiles_rect;
1867 drawRect.x += tpoint.x;
1868 drawRect.y += tpoint.y;
1869 BlitSurfaceColoured(tiles[1166],NULL, backBuffer, &drawRect, ct);
1870 }
1871 }
1872 }
1873 else if (obj.entities[i].size == 13)
1874 {
1875 //Special for epilogue: huge hero!
1876
1877 if (flipmode) {
1878
1879
1880
1881 //scaleMatrix.scale(6, 6);
1882 //bigbuffer.fillRect(bigbuffer.rect, 0x000000);
1883 FillRect(tempBuffer, 0x000000);
1884
1885 tpoint.x = obj.entities[i].xp; tpoint.y = obj.entities[i].yp;
1886 setcol(obj.entities[i].colour, help);
1887 //flipsprites[obj.entities[i].drawframe].colorTransform(sprites_rect, ct);
1888 //bigbuffer.copyPixels(flipsprites[obj.entities[i].drawframe], sprites_rect, new Point(0, 0));
1889 SDL_Rect drawRect = {Sint16(obj.entities[i].xp ), Sint16(obj.entities[i].yp), sprites_rect.x, sprites_rect.y };
1890 SDL_Surface* TempSurface = ScaleSurface( flipsprites[obj.entities[i].drawframe], 6* sprites_rect.w,6* sprites_rect.w );
1891 BlitSurfaceColoured(TempSurface, NULL , backBuffer, &drawRect, ct );
1892 SDL_FreeSurface(TempSurface);
1893 //scaleMatrix.translate(-obj.entities[i].xp, -obj.entities[i].yp);
1894 }
1895 else
1896 {
1897 //TODO checkthis
1898 tpoint.x = obj.entities[i].xp; tpoint.y = obj.entities[i].yp;
1899 setcol(obj.entities[i].colour, help);
1900 //flipsprites[obj.entities[i].drawframe].colorTransform(sprites_rect, ct);
1901 //bigbuffer.copyPixels(flipsprites[obj.entities[i].drawframe], sprites_rect, new Point(0, 0));
1902 SDL_Rect drawRect = {Sint16(obj.entities[i].xp ), Sint16(obj.entities[i].yp), Sint16(sprites_rect.x * 6), Sint16(sprites_rect.y * 6 ) };
1903 SDL_Surface* TempSurface = ScaleSurface( flipsprites[obj.entities[i].drawframe], 6 * sprites_rect.w,6* sprites_rect.h );
1904 BlitSurfaceColoured(TempSurface, NULL , backBuffer, &drawRect, ct );
1905 SDL_FreeSurface(TempSurface);
1906 }
1907
1908
1909
1910 }
1911 }
1912 }
1913 }
1914
drawbackground(int t,mapclass & map)1915 void Graphics::drawbackground( int t, mapclass& map )
1916 {
1917 int temp = 0;
1918
1919 switch(t)
1920 {
1921 case 1:
1922 //Starfield
1923 FillRect(backBuffer,0x00000);
1924 for (int i = 0; i < 50; i++)
1925 {
1926 stars[i].w = 2;
1927 stars[i].h = 2;
1928 if (starsspeed[i] <= 6)
1929 {
1930 FillRect(backBuffer,stars[i], getRGB(0x22,0x22,0x22));
1931 //backbuffer.fillRect(stars[i], 0x222222);
1932 }
1933 else
1934 {
1935 FillRect(backBuffer,stars[i], getRGB(0x55,0x55,0x55));
1936 }
1937 stars[i].x -= Sint16(starsspeed[i]);
1938 if (stars[i].x < -10)
1939 {
1940 stars[i].x += 340;
1941 stars[i].y = int(fRandom() * 240);
1942 stars[i].w = 2;
1943 starsspeed[i] = 4+int(fRandom()*4);
1944 }
1945 }
1946 break;
1947 case 2:
1948 //Lab
1949 switch(rcol)
1950 {
1951 //Akward ordering to match tileset
1952 case 0:
1953 bcol2 = RGBflip(0, 16*backboxint[0], 16*backboxint[0]);
1954 break; //Cyan
1955 case 1:
1956 bcol2 = RGBflip(16*backboxint[0], 0, 0);
1957 break; //Red
1958 case 2:
1959 bcol2 = RGBflip(16*backboxint[0], 0, 16*backboxint[0]);
1960 break; //Purple
1961 case 3:
1962 bcol2 = RGBflip(0, 0, 16*backboxint[0]);
1963 break; //Blue
1964 case 4:
1965 bcol2 = RGBflip(16*backboxint[0], 16*backboxint[0], 0);
1966 break; //Yellow
1967 case 5:
1968 bcol2 = RGBflip(0, 16 * backboxint[0], 0);
1969 break; //Green
1970 case 6:
1971 //crazy case
1972 spcoldel--;
1973 if (spcoldel <= 0)
1974 {
1975 spcoldel = 15;
1976 spcol++;
1977 if (spcol >= 12) spcol = 0;
1978 }
1979 switch(spcol)
1980 {
1981 case 0:
1982 bcol2 = RGBflip(0, 16*backboxint[0], 16*backboxint[0]);
1983 break; //Cyan
1984 case 1:
1985 bcol2 = RGBflip(0, (spcoldel+1)*backboxint[0], 16*backboxint[0]);
1986 break; //Cyan
1987 case 2:
1988 bcol2 = RGBflip(0, 0, 16*backboxint[0]);
1989 break; //Blue
1990 case 3:
1991 bcol2 = RGBflip((16-spcoldel)*backboxint[0], 0, 16*backboxint[0]);
1992 break; //Blue
1993 case 4:
1994 bcol2 = RGBflip(16*backboxint[0], 0, 16*backboxint[0]);
1995 break; //Purple
1996 case 5:
1997 bcol2 = RGBflip(16*backboxint[0], 0, (spcoldel+1)*backboxint[0]);
1998 break; //Purple
1999 case 6:
2000 bcol2 = RGBflip(16*backboxint[0], 0, 0);
2001 break; //Red
2002 case 7:
2003 bcol2 = RGBflip(16*backboxint[0], (16-spcoldel)*backboxint[0], 0);
2004 break; //Red
2005 case 8:
2006 bcol2 = RGBflip(16*backboxint[0], 16*backboxint[0], 0);
2007 break; //Yellow
2008 case 9:
2009 bcol2 = RGBflip((spcoldel+1)*backboxint[0], 16*backboxint[0], 0);
2010 break; //Yellow
2011 case 10:
2012 bcol2 = RGBflip(0, 16 * backboxint[0], 0);
2013 break; //Green
2014 case 11:
2015 bcol2 = RGBflip(0, 16 * backboxint[0], (16-spcoldel)*backboxint[0]);
2016 break; //Green
2017 }
2018 break;
2019 }
2020 FillRect(backBuffer,bcol2);
2021
2022 for (int i = 0; i < 18; i++)
2023 {
2024 switch(rcol)
2025 {
2026 //Akward ordering to match tileset
2027 case 0:
2028 bcol = RGBflip(16, 128*backboxint[0], 128*backboxint[0]);
2029 break; //Cyan
2030 case 1:
2031 bcol = RGBflip(128*backboxint[0], 16, 16);
2032 break; //Red
2033 case 2:
2034 bcol = RGBflip(128*backboxint[0], 16, 128*backboxint[0]);
2035 break; //Purple
2036 case 3:
2037 bcol = RGBflip(16, 16, 128*backboxint[0]);
2038 break; //Blue
2039 case 4:
2040 bcol = RGBflip(128*backboxint[0], 128*backboxint[0], 16);
2041 break; //Yellow
2042 case 5:
2043 bcol = RGBflip(16, 128 * backboxint[0], 16);
2044 break; //Green
2045 case 6:
2046 //crazy case
2047 switch(spcol)
2048 {
2049 case 0:
2050 bcol = RGBflip(16, 128*backboxint[0], 128*backboxint[0]);
2051 break; //Cyan
2052 case 1:
2053 bcol = RGBflip(16, ((spcoldel+1)*8)*backboxint[0], 128*backboxint[0]);
2054 break; //Cyan
2055 case 2:
2056 bcol = RGBflip(16, 16, 128*backboxint[0]);
2057 break; //Blue
2058 case 3:
2059 bcol = RGBflip((128-(spcoldel*8))*backboxint[0], 16, 128*backboxint[0]);
2060 break; //Blue
2061 case 4:
2062 bcol = RGBflip(128*backboxint[0], 16, 128*backboxint[0]);
2063 break; //Purple
2064 case 5:
2065 bcol = RGBflip(128*backboxint[0], 16, ((spcoldel+1)*8)*backboxint[0]);
2066 break; //Purple
2067 case 6:
2068 bcol = RGBflip(128*backboxint[0], 16, 16);
2069 break; //Red
2070 case 7:
2071 bcol = RGBflip(128*backboxint[0], (128-(spcoldel*8))*backboxint[0], 16);
2072 break; //Red
2073 case 8:
2074 bcol = RGBflip(128*backboxint[0], 128*backboxint[0], 16);
2075 break; //Yellow
2076 case 9:
2077 bcol = RGBflip(((spcoldel+1)*8)*backboxint[0], 128*backboxint[0], 16);
2078 break; //Yellow
2079 case 10:
2080 bcol = RGBflip(16, 128 * backboxint[0], 16);
2081 break; //Green
2082 case 11:
2083 bcol = RGBflip(16, 128 * backboxint[0], (128-(spcoldel*8))*backboxint[0]);
2084 break; //Green
2085 }
2086 break;
2087 }
2088 FillRect(backBuffer, backboxes[i], bcol);
2089 backboxrect.x = backboxes[i].x + 1;
2090 backboxrect.y = backboxes[i].y + 1;
2091 backboxrect.w = backboxes[i].w - 2;
2092 backboxrect.h = backboxes[i].h - 2;
2093 FillRect(backBuffer,backboxrect, bcol2);
2094
2095 backboxes[i].x += backboxvx[i];
2096 backboxes[i].y += backboxvy[i];
2097 if (backboxes[i].x < -40)
2098 {
2099 backboxes[i].x = 320;
2100 backboxes[i].y = fRandom() * 240;
2101 }
2102 if (backboxes[i].x > 320)
2103 {
2104 backboxes[i].x = -32;
2105 backboxes[i].y = fRandom() * 240;
2106 }
2107 if (backboxes[i].y < -40)
2108 {
2109 backboxes[i].y = 240;
2110 backboxes[i].x = fRandom() * 320;
2111 }
2112 if (backboxes[i].y > 260)
2113 {
2114 backboxes[i].y = -32;
2115 backboxes[i].x = fRandom() * 320;
2116 }
2117 }
2118 break;
2119 case 3: //Warp zone (horizontal)
2120 backoffset+=3;
2121 if (backoffset >= 16) backoffset -= 16;
2122
2123 if (backgrounddrawn)
2124 {
2125 //TODO Scroll?
2126 //towerbuffer.scroll( -3, 0);
2127 ScrollSurface(towerbuffer, -3, 0 );
2128 for (int j = 0; j < 15; j++)
2129 {
2130 temp = 680 + (rcol * 3);
2131 drawtowertile(317 - backoffset, (j * 16), temp+40); //20*16 = 320
2132 drawtowertile(317 - backoffset + 8, (j * 16), temp + 41);
2133 drawtowertile(317 - backoffset, (j * 16) + 8, temp + 80);
2134 drawtowertile(317 - backoffset + 8, (j * 16) + 8, temp + 81);
2135 }
2136 }
2137 else
2138 {
2139 //draw the whole thing for the first time!
2140 backoffset = 0;
2141 FillRect(towerbuffer, 0x000000);
2142 for (int j = 0; j < 15; j++)
2143 {
2144 for (int i = 0; i < 21; i++)
2145 {
2146 temp = 680 + (rcol * 3);
2147 drawtowertile((i * 16) - backoffset, (j * 16), temp+40);
2148 drawtowertile((i * 16) - backoffset + 8, (j * 16), temp + 41);
2149 drawtowertile((i * 16) - backoffset, (j * 16) + 8, temp + 80);
2150 drawtowertile((i * 16) - backoffset + 8, (j * 16) + 8, temp + 81);
2151 }
2152 }
2153 backgrounddrawn = true;
2154 }
2155 //TODO this is why map breaks
2156
2157 //backbuffer.copyPixels(towerbuffer, towerbuffer.rect, tl);
2158 BlitSurfaceStandard(towerbuffer, NULL, backBuffer, NULL);
2159 break;
2160 case 4: //Warp zone (vertical)
2161 backoffset+=3;
2162 if (backoffset >= 16) backoffset -= 16;
2163
2164 if (backgrounddrawn)
2165 {
2166 //TODO scroll?!
2167 //towerbuffer.scroll(0, -3);
2168 ScrollSurface(towerbuffer,0,-3);
2169 for (int i = 0; i < 21; i++)
2170 {
2171 temp = 760 + (rcol * 3);
2172 drawtowertile((i * 16), 237 - backoffset, temp + 40); //14*17=240 - 3
2173 drawtowertile((i * 16) + 8, 237 - backoffset, temp + 41);
2174 drawtowertile((i * 16), 237 - backoffset + 8, temp + 80);
2175 drawtowertile((i * 16) + 8, 237 - backoffset + 8, temp + 81);
2176 }
2177 }
2178 else
2179 {
2180 //draw the whole thing for the first time!
2181 backoffset = 0;
2182 FillRect(towerbuffer,0x000000 );
2183 for (j = 0; j < 15; j++)
2184 {
2185 for (int i = 0; i < 21; i++)
2186 {
2187 temp = 760 + (rcol * 3);
2188 drawtowertile((i * 16), (j * 16)- backoffset, temp+40);
2189 drawtowertile((i * 16)+ 8, (j * 16)- backoffset, temp + 41);
2190 drawtowertile((i * 16), (j * 16)- backoffset + 8, temp + 80);
2191 drawtowertile((i * 16)+ 8, (j * 16)- backoffset + 8, temp + 81);
2192 }
2193 }
2194 backgrounddrawn = true;
2195 }
2196
2197 SDL_BlitSurface(towerbuffer,NULL, backBuffer,NULL);
2198 break;
2199 case 5:
2200 //Warp zone, central
2201 switch(rcol)
2202 {
2203 //Akward ordering to match tileset
2204 case 0:
2205 warpbcol = RGBflip(0x0A, 0x10, 0x0E);
2206 warpfcol = RGBflip(0x10, 0x22, 0x21);
2207 break; //Cyan
2208 case 1:
2209 warpbcol = RGBflip(0x11, 0x09, 0x0B);
2210 warpfcol = RGBflip(0x22, 0x10, 0x11);
2211 break; //Red
2212 case 2:
2213 warpbcol = RGBflip(0x0F, 0x0A, 0x10);
2214 warpfcol = RGBflip(0x22,0x10,0x22);
2215 break; //Purple
2216 case 3:
2217 warpbcol = RGBflip(0x0A, 0x0B, 0x10);
2218 warpfcol = RGBflip(0x10, 0x10, 0x22);
2219 break; //Blue
2220 case 4:
2221 warpbcol = RGBflip(0x10, 0x0D, 0x0A);
2222 warpfcol = RGBflip(0x22, 0x1E, 0x10);
2223 break; //Yellow
2224 case 5:
2225 warpbcol = RGBflip(0x0D, 0x10, 0x0A);
2226 warpfcol = RGBflip(0x14, 0x22, 0x10);
2227 break; //Green
2228 case 6:
2229 warpbcol = RGBflip(0x0A, 0x0A, 0x0A);
2230 warpfcol = RGBflip(0x12, 0x12, 0x12);
2231 break; //Gray
2232 default:
2233 warpbcol = RGBflip(0xFF, 0xFF, 0xFF);
2234 warpfcol = RGBflip(0xFF, 0xFF, 0xFF);
2235 }
2236
2237 backoffset += 1;
2238 if (backoffset >= 16)
2239 {
2240 backoffset -= 16;
2241 warpskip = (warpskip + 1) % 2;
2242 }
2243
2244 for (int i = 10 ; i >= 0; i--)
2245 {
2246 temp = (i << 4) + backoffset;
2247 setwarprect(160 - temp, 120 - temp, temp * 2, temp * 2);
2248 if (i % 2 == warpskip)
2249 {
2250 FillRect(backBuffer, warprect, warpbcol);
2251 }
2252 else
2253 {
2254 FillRect(backBuffer,warprect, warpfcol);
2255 }
2256 }
2257 break;
2258 case 6:
2259 //Final Starfield
2260 FillRect(backBuffer,0x000000);
2261 for (int i = 0; i < 50; i++)
2262 {
2263 if (starsspeed[i] <= 8)
2264 {
2265 FillRect(backBuffer, stars[i], getRGB(0x22, 0x22, 0x22));
2266 }
2267 else
2268 {
2269 FillRect(backBuffer, stars[i], getRGB(0x55, 0x55, 0x55));
2270 }
2271 stars[i].y -= starsspeed[i];
2272 if (stars[i].y < -10)
2273 {
2274 stars[i].y += 260;
2275 stars[i].x = fRandom() * 320;
2276 starsspeed[i] = 5+(fRandom()*5);
2277 }
2278 }
2279 break;
2280 case 7:
2281 //Static, unscrolling section of the tower
2282 for (int j = 0; j < 30; j++)
2283 {
2284 for (int i = 0; i < 40; i++)
2285 {
2286 drawtile3(i * 8, j * 8, map.tower.backat(i, j, 200), 15);
2287 }
2288 }
2289 break;
2290 case 8:
2291 //Static, unscrolling section of the tower
2292 for (int j = 0; j < 30; j++)
2293 {
2294 for (int i = 0; i < 40; i++)
2295 {
2296 drawtile3(i * 8, j * 8, map.tower.backat(i, j, 200), 10);
2297 }
2298 }
2299 break;
2300 case 9:
2301 //Static, unscrolling section of the tower
2302 for (int j = 0; j < 30; j++)
2303 {
2304 for (int i = 0; i < 40; i++)
2305 {
2306 drawtile3(i * 8, j * 8, map.tower.backat(i, j, 600), 0);
2307 }
2308 }
2309 break;
2310 default:
2311 FillRect(backBuffer, 0x000000 );
2312 //TODO
2313 //backbuffer.copyPixels(backgrounds[t], bg_rect, tl);
2314 BlitSurfaceStandard(backgrounds[t], NULL, backBuffer, &bg_rect);
2315
2316 break;
2317 }
2318 }
2319
drawmap(mapclass & map)2320 void Graphics::drawmap( mapclass& map )
2321 {
2322 ///TODO forground once;
2323 if (!foregrounddrawn)
2324 {
2325 FillRect(forgroundBuffer, 0xDEADBEEF);
2326 if(map.tileset==0)
2327 {
2328 for (j = 0; j < 29+map.extrarow; j++)
2329 {
2330 for (int i = 0; i < 40; i++)
2331 {
2332 if(map.contents[i + map.vmult[j]]>0) drawforetile(i * 8, j * 8, map.contents[i + map.vmult[j]]);
2333 }
2334 }
2335 }
2336 else if (map.tileset == 1)
2337 {
2338 for (int jt = 0; jt < 29+map.extrarow; jt++)
2339 {
2340 for (int it = 0; it < 40; it++)
2341 {
2342 if(map.contents[it + map.vmult[jt]]>0) drawforetile2(it * 8, jt * 8, map.contents[it + map.vmult[jt]]);
2343 }
2344 }
2345 }
2346 else if (map.tileset == 2)
2347 {
2348 for (j = 0; j < 29+map.extrarow; j++)
2349 {
2350 for (int i = 0; i < 40; i++)
2351 {
2352 if(map.contents[i + map.vmult[j]]>0) drawforetile3(i * 8, j * 8, map.contents[i + map.vmult[j]],map.rcol);
2353 }
2354 }
2355 }
2356 foregrounddrawn = true;
2357 }
2358 OverlaySurfaceKeyed(forgroundBuffer, backBuffer, 0xDEADBEEF);
2359 //SDL_BlitSurface(forgroundBuffer, NULL, backBuffer, NULL);
2360
2361 }
2362
drawfinalmap(mapclass & map)2363 void Graphics::drawfinalmap(mapclass & map)
2364 {
2365 //Update colour cycling for final level
2366 if (map.final_colormode) {
2367 map.final_aniframedelay--;
2368 if(map.final_aniframedelay==0)
2369 {
2370 foregrounddrawn=false;
2371 }
2372 if (map.final_aniframedelay <= 0) {
2373 map.final_aniframedelay = 2;
2374 map.final_aniframe++;
2375 if (map.final_aniframe >= 4)
2376 map.final_aniframe = 0;
2377 }
2378 }
2379
2380 if (!foregrounddrawn) {
2381 FillRect(forgroundBuffer, 0xDEADBEEF);
2382 if(map.tileset==0){
2383 for (int j = 0; j < 29+map.extrarow; j++) {
2384 for (int i = 0; i < 40; i++) {
2385 if((map.contents[i + map.vmult[j]])>0)
2386 drawforetile(i * 8, j * 8, map.finalat(i,j));
2387 }
2388 }
2389 }else if (map.tileset == 1) {
2390 for (int j = 0; j < 29+map.extrarow; j++) {
2391 for (int i = 0; i < 40; i++) {
2392 if((map.contents[i + map.vmult[j]])>0)
2393 drawforetile2(i * 8, j * 8, map.finalat(i,j));
2394 }
2395 }
2396 }
2397 foregrounddrawn=true;
2398 }
2399
2400 OverlaySurfaceKeyed(forgroundBuffer, backBuffer, 0xDEADBEEF);
2401 }
2402
drawtowermap(mapclass & map)2403 void Graphics::drawtowermap( mapclass& map )
2404 {
2405 int temp;
2406 for (int j = 0; j < 30; j++)
2407 {
2408 for (int i = 0; i < 40; i++)
2409 {
2410 temp = map.tower.at(i, j, map.ypos);
2411 if (temp > 0) drawtile3(i * 8, (j * 8) - ((int)map.ypos % 8), temp, map.colstate);
2412 }
2413 }
2414 }
2415
drawtowermap_nobackground(mapclass & map)2416 void Graphics::drawtowermap_nobackground( mapclass& map )
2417 {
2418 int temp;
2419 for (j = 0; j < 30; j++)
2420 {
2421 for (int i = 0; i < 40; i++)
2422 {
2423 temp = map.tower.at(i, j, map.ypos);
2424 if (temp > 0 && temp<28) drawtile3(i * 8, (j * 8) - ((int)map.ypos % 8), temp, map.colstate);
2425 }
2426 }
2427 }
2428
drawtowerentities(mapclass & map,entityclass & obj,UtilityClass & help)2429 void Graphics::drawtowerentities( mapclass& map, entityclass& obj, UtilityClass& help )
2430 {
2431 //Update line colours!
2432 if (linedelay <= 0)
2433 {
2434 linestate++;
2435 if (linestate >= 10) linestate = 0;
2436 linedelay = 2;
2437 }
2438 else
2439 {
2440 linedelay--;
2441 }
2442 point tpoint;
2443 SDL_Rect trect;
2444
2445 for (int i = 0; i < obj.nentity; i++)
2446 {
2447 if (!obj.entities[i].invis && obj.entities[i].active)
2448 {
2449 if (obj.entities[i].size == 0) // Sprites
2450 {
2451 trinketcolset = false;
2452 tpoint.x = obj.entities[i].xp;
2453 tpoint.y = obj.entities[i].yp-map.ypos;
2454 setcol(obj.entities[i].colour, help);
2455 setRect(trect, tpoint.x, tpoint.y, sprites_rect.w, sprites_rect.h);
2456 BlitSurfaceColoured(sprites[obj.entities[i].drawframe], NULL, backBuffer, &trect, ct);
2457 //screenwrapping!
2458 if (!map.minitowermode)
2459 {
2460 if ( map.ypos >= 500 && map.ypos <= 5000) //The "wrapping" area of the tower
2461 {
2462 if (tpoint.x < 0)
2463 {
2464 tpoint.x += 320;
2465 setRect(trect, tpoint.x, tpoint.y, sprites_rect.w, sprites_rect.h);
2466 BlitSurfaceColoured(sprites[obj.entities[i].drawframe], NULL, backBuffer, &trect, ct);
2467 }
2468 if (tpoint.x > 300)
2469 {
2470 tpoint.x -= 320;
2471 setRect(trect, tpoint.x, tpoint.y, sprites_rect.w, sprites_rect.h);
2472 BlitSurfaceColoured(sprites[obj.entities[i].drawframe], NULL, backBuffer, &trect, ct);
2473 }
2474 }
2475 }
2476 }
2477 else if (obj.entities[i].size == 1)
2478 {
2479 // Tiles
2480 tpoint.x = obj.entities[i].xp;
2481 tpoint.y = obj.entities[i].yp-map.ypos;
2482 setRect(trect,tiles_rect.w, tiles_rect.h, tpoint.x, tpoint.y);
2483 BlitSurfaceColoured(tiles[obj.entities[i].drawframe], NULL, backBuffer, &trect, ct);
2484 }
2485 else if (obj.entities[i].size == 2)
2486 {
2487 // Special: Moving platform, 4 tiles
2488 tpoint.x = obj.entities[i].xp;
2489 tpoint.y = obj.entities[i].yp-map.ypos;
2490 setRect(trect,tiles_rect.w, tiles_rect.h, tpoint.x, tpoint.y);
2491 BlitSurfaceColoured(tiles[obj.entities[i].drawframe], NULL, backBuffer, &trect, ct);
2492 tpoint.x += 8;
2493 setRect(trect,sprites_rect.w, sprites_rect.h, tpoint.x, tpoint.y);
2494 BlitSurfaceColoured(tiles[obj.entities[i].drawframe], NULL, backBuffer, &trect, ct);
2495 tpoint.x += 8;
2496 setRect(trect,sprites_rect.w, sprites_rect.h, tpoint.x, tpoint.y);
2497 BlitSurfaceColoured(tiles[obj.entities[i].drawframe], NULL, backBuffer, &trect, ct);
2498 tpoint.x += 8;
2499 setRect(trect,sprites_rect.w, sprites_rect.h, tpoint.x, tpoint.y);
2500 BlitSurfaceColoured(tiles[obj.entities[i].drawframe], NULL, backBuffer, &trect, ct);
2501
2502 }
2503 else if (obj.entities[i].size == 3) // Big chunky pixels!
2504 {
2505 prect.x = obj.entities[i].xp;
2506 prect.y = obj.entities[i].yp-map.ypos;
2507 //A seperate index of colours, for simplicity
2508 if(obj.entities[i].colour==1)
2509 {
2510 FillRect(backBuffer, prect, getRGB(196 - (fRandom() * 64), 10, 10));
2511 }
2512 else if (obj.entities[i].colour == 2)
2513 {
2514 FillRect(backBuffer, prect, getRGB(160- help.glow/2 - (fRandom()*20), 200- help.glow/2, 220 - help.glow));
2515 }
2516 }
2517 else if (obj.entities[i].size == 4) // Small pickups
2518 {
2519 drawhuetile(obj.entities[i].xp, obj.entities[i].yp-map.ypos, obj.entities[i].tile, obj.entities[i].colour);
2520 }
2521 else if (obj.entities[i].size == 5) //Horizontal Line
2522 {
2523 line_rect.x = obj.entities[i].xp;
2524 line_rect.y = obj.entities[i].yp-map.ypos;
2525 line_rect.w = obj.entities[i].w;
2526 line_rect.h = 1;
2527 drawgravityline(i, obj);
2528 }
2529 else if (obj.entities[i].size == 6) //Vertical Line
2530 {
2531 line_rect.x = obj.entities[i].xp;
2532 line_rect.y = obj.entities[i].yp-map.ypos;
2533 line_rect.w = 1;
2534 line_rect.h = obj.entities[i].h;
2535 drawgravityline(i, obj);
2536 }
2537 }
2538 }
2539 }
2540
drawtowerspikes(mapclass & map)2541 void Graphics::drawtowerspikes( mapclass& map )
2542 {
2543 for (int i = 0; i < 40; i++)
2544 {
2545 drawtile3(i * 8, -8+map.spikeleveltop, 9, map.colstate);
2546 drawtile3(i * 8, 230-map.spikelevelbottom, 8, map.colstate);
2547 }
2548 }
2549
drawtowerbackgroundsolo(mapclass & map)2550 void Graphics::drawtowerbackgroundsolo( mapclass& map )
2551 {
2552 if (map.bypos < 0)
2553 {
2554 map.bypos += 120 * 8;
2555 }
2556
2557 int temp = 0;
2558
2559 if (map.tdrawback)
2560 {
2561 //Draw the whole thing; needed for every colour cycle!
2562 for (int j = 0; j < 31; j++)
2563 {
2564 for (int i = 0; i < 40; i++)
2565 {
2566 temp = map.tower.backat(i, j, map.bypos);
2567 drawtowertile3(i * 8, (j * 8) - (map.bypos % 8), temp, map.colstate);
2568 }
2569 }
2570 SDL_BlitSurface(towerbuffer,NULL, backBuffer,NULL);
2571 map.tdrawback = false;
2572 }
2573 else
2574 {
2575 //just update the bottom
2576 ScrollSurface(towerbuffer,0, -map.bscroll);
2577 for (int i = 0; i < 40; i++)
2578 {
2579 temp = map.tower.backat(i, 0, map.bypos);
2580 drawtowertile3(i * 8, -(map.bypos % 8), temp, map.colstate);
2581 }
2582
2583 SDL_BlitSurface(towerbuffer, NULL, backBuffer,NULL);
2584 }
2585 }
2586
drawtowerbackground(mapclass & map)2587 void Graphics::drawtowerbackground( mapclass& map )
2588 {
2589 //TODO
2590 int temp;
2591
2592 if (map.bypos < 0) map.bypos += 120 * 8;
2593
2594 if (map.scrolldir == 1) map.tdrawback = true;
2595
2596 if (map.tdrawback)
2597 {
2598 //Draw the whole thing; needed for every colour cycle!
2599 for (j = 0; j < 30; j++)
2600 {
2601 for (int i = 0; i < 40; i++)
2602 {
2603 temp = map.tower.backat(i, j, map.bypos);
2604 drawtowertile3(i * 8, (j * 8) - (map.bypos % 8), temp, map.colstate);
2605 }
2606 }
2607
2608 //backbuffer.copyPixels(towerbuffer, towerbuffer.rect, tl, null, null, false);
2609 SDL_BlitSurface(towerbuffer,NULL, backBuffer,NULL);
2610
2611 map.tdrawback = false;
2612 }
2613 else
2614 {
2615 //just update the bottom
2616 //TODO SCOLL
2617 //towerbuffer.scroll(0, -map.bscroll);
2618 ScrollSurface(towerbuffer, 0, -map.bscroll);
2619 for (int i = 0; i < 40; i++)
2620 {
2621 temp = map.tower.backat(i, 0, map.bypos);
2622 drawtowertile3(i * 8, -(map.bypos % 8), temp, map.colstate);
2623 }
2624
2625 //backbuffer.copyPixels(towerbuffer, towerbuffer.rect, tl, null, null, false);
2626 SDL_BlitSurface(towerbuffer,NULL, backBuffer,NULL);
2627 }
2628 }
2629
setcol(int t,UtilityClass & help)2630 void Graphics::setcol( int t, UtilityClass& help )
2631 {
2632 int temp;
2633
2634 //Setup predefinied colours as per our zany palette
2635 switch(t)
2636 {
2637 //Player Normal
2638 case 0:
2639 ct.colour = getRGB(160- help.glow/2 - (fRandom()*20), 200- help.glow/2, 220 - help.glow);
2640 break;
2641 //Player Hurt
2642 case 1:
2643 ct.colour = getRGB(196 - (fRandom() * 64), 10, 10);
2644 break;
2645 //Enemies and stuff
2646 case 2:
2647 ct.colour = getRGB(225-(help.glow/2), 75, 30);
2648 break;
2649 case 3: //Trinket
2650 if (!trinketcolset)
2651 {
2652 trinketr = 200 - (fRandom() * 64);
2653 trinketg = 200 - (fRandom() * 128);
2654 trinketb = 164 + (fRandom() * 60);
2655 trinketcolset = true;
2656 }
2657 ct.colour = getRGB(trinketr, trinketg, trinketb);
2658 break;
2659 case 4: //Inactive savepoint
2660 temp = (help.glow/2) + (fRandom() * 8);
2661 ct.colour = getRGB(80 + temp, 80 + temp, 80 + temp);
2662 break;
2663 case 5: //Active savepoint
2664 ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
2665 break;
2666 case 6: //Enemy : Red
2667 ct.colour = getRGB(250 - help.glow/2, 60- help.glow/2, 60 - help.glow/2);
2668 break;
2669 case 7: //Enemy : Green
2670 ct.colour = getRGB(100 - help.glow/2 - (fRandom()*30), 250 - help.glow/2, 100 - help.glow/2 - (fRandom()*30));
2671 break;
2672 case 8: //Enemy : Purple
2673 ct.colour = getRGB(250 - help.glow/2, 20, 128 - help.glow/2 + (fRandom()*30));
2674 break;
2675 case 9: //Enemy : Yellow
2676 ct.colour = getRGB(250 - help.glow/2, 250 - help.glow/2, 20);
2677 break;
2678 case 10: //Warp point (white)
2679 ct.colour = getRGB(255 - (fRandom() * 64), 255 - (fRandom() * 64), 255 - (fRandom() * 64));
2680 break;
2681 case 11: //Enemy : Cyan
2682 ct.colour = getRGB(20, 250 - help.glow/2, 250 - help.glow/2);
2683 break;
2684 case 12: //Enemy : Blue
2685 ct.colour = getRGB(90- help.glow/2, 90 - help.glow/2, 250 - help.glow/2);
2686 break;
2687 //Crew Members
2688 //green
2689 case 13:
2690 ct.colour = getRGB(120- help.glow/4 - (fRandom()*20), 220 - help.glow/4, 120- help.glow/4);
2691 break;
2692 //Yellow
2693 case 14:
2694 ct.colour = getRGB(220- help.glow/4 - (fRandom()*20), 210 - help.glow/4, 120- help.glow/4);
2695 break;
2696 //pink
2697 case 15:
2698 ct.colour = getRGB(255 - help.glow/8, 70 - help.glow/4, 70 - help.glow / 4);
2699 break;
2700 //Blue
2701 case 16:
2702 ct.colour = getRGB(75, 75, 255- help.glow/4 - (fRandom()*20));
2703 break;
2704
2705
2706 case 17: //Enemy : Orange
2707 ct.colour = getRGB(250 - help.glow/2, 130 - help.glow/2, 20);
2708 break;
2709 case 18: //Enemy : Gray
2710 ct.colour = getRGB(130- help.glow/2, 130 - help.glow/2, 130 - help.glow/2);
2711 break;
2712 case 19: //Enemy : Dark gray
2713 ct.colour = getRGB(60- help.glow/8, 60 - help.glow/8, 60 - help.glow/8);
2714 break;
2715 //Purple
2716 case 20:
2717 ct.colour = getRGB(220 - help.glow / 4 - (fRandom() * 20), 120 - help.glow / 4, 210 - help.glow / 4);
2718 break;
2719
2720 case 21: //Enemy : Light Gray
2721 ct.colour = getRGB(180- help.glow/2, 180 - help.glow/2, 180 - help.glow/2);
2722 break;
2723 case 22: //Enemy : Indicator Gray
2724 ct.colour = getRGB(230- help.glow/2, 230- help.glow/2, 230- help.glow/2);
2725 break;
2726 case 23: //Enemy : Indicator Gray
2727 ct.colour = getRGB(255- help.glow/2 - (fRandom() * 40) , 255- help.glow/2 - (fRandom() * 40), 255- help.glow/2 - (fRandom() * 40));
2728 break;
2729
2730 //Trophies
2731 //cyan
2732 case 30:
2733 ct.colour = RGBf(160, 200, 220);
2734 break;
2735 //Purple
2736 case 31:
2737 ct.colour = RGBf(220, 120, 210);
2738 break;
2739 //Yellow
2740 case 32:
2741 ct.colour = RGBf(220, 210, 120);
2742 break;
2743 //red
2744 case 33:
2745 ct.colour = RGBf(255, 70, 70);
2746 break;
2747 //green
2748 case 34:
2749 ct.colour = RGBf(120, 220, 120);
2750 break;
2751 //Blue
2752 case 35:
2753 ct.colour = RGBf(75, 75, 255);
2754 break;
2755 //Gold
2756 case 36:
2757 ct.colour = getRGB(180, 120, 20);
2758 break;
2759 case 37: //Trinket
2760 if (!trinketcolset)
2761 {
2762 trinketr = 200 - (fRandom() * 64);
2763 trinketg = 200 - (fRandom() * 128);
2764 trinketb = 164 + (fRandom() * 60);
2765 trinketcolset = true;
2766 }
2767 ct.colour = RGBf(trinketr, trinketg, trinketb);
2768 break;
2769 //Silver
2770 case 38:
2771 ct.colour = RGBf(196, 196, 196);
2772 break;
2773 //Bronze
2774 case 39:
2775 ct.colour = RGBf(128, 64, 10);
2776 break;
2777 //Awesome
2778 case 40: //Teleporter in action!
2779 temp = fRandom() * 150;
2780 if(temp<33)
2781 {
2782 ct.colour = RGBf(255 - (fRandom() * 64), 64 + (fRandom() * 64), 64 + (fRandom() * 64));
2783 }
2784 else if (temp < 66)
2785 {
2786 ct.colour = RGBf(64 + (fRandom() * 64), 255 - (fRandom() * 64), 64 + (fRandom() * 64));
2787 }
2788 else if (temp < 100)
2789 {
2790 ct.colour = RGBf(64 + (fRandom() * 64), 64 + (fRandom() * 64), 255 - (fRandom() * 64));
2791 }
2792 else
2793 {
2794 ct.colour = RGBf(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
2795 }
2796 break;
2797
2798 case 100: //Inactive Teleporter
2799 temp = (help.glow/2) + (fRandom() * 8);
2800 ct.colour = getRGB(42 + temp, 42 + temp, 42 + temp);
2801 break;
2802 case 101: //Active Teleporter
2803 ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
2804 break;
2805 case 102: //Teleporter in action!
2806 temp = fRandom() * 150;
2807 if(temp<33)
2808 {
2809 ct.colour = getRGB(255 - (fRandom() * 64), 64 + (fRandom() * 64), 64 + (fRandom() * 64));
2810 }
2811 else if (temp < 66)
2812 {
2813 ct.colour = getRGB(64 + (fRandom() * 64), 255 - (fRandom() * 64), 64 + (fRandom() * 64));
2814 }
2815 else if (temp < 100)
2816 {
2817 ct.colour = getRGB(64 + (fRandom() * 64), 64 + (fRandom() * 64), 255 - (fRandom() * 64));
2818 }
2819 else
2820 {
2821 ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
2822 }
2823 break;
2824
2825 default:
2826 ct.colour = 0xFFFFFF;
2827 break;
2828 }
2829 //ct.color = endian_swap(ct.color);
2830 }
2831
menuoffrender()2832 void Graphics::menuoffrender()
2833 {
2834 //TODO
2835 //screenbuffer.lock();
2836 //screenbuffer.copyPixels(menubuffer, menubuffer.rect, tl, null, null, false);
2837 //screenbuffer->UpdateScreen(menubuffer,NULL);
2838 SDL_Rect offsetRect1;
2839 setRect (offsetRect1, 0, 0, backBuffer->w ,backBuffer->h);
2840
2841 //put the back buffer in the menubuffer
2842 BlitSurfaceStandard(backBuffer, NULL, menubuffer, NULL);
2843
2844
2845
2846 if(flipmode)
2847 {
2848 // flipmatrix.translate(0, menuoffset);
2849 // screenbuffer.draw(backbuffer, flipmatrix);
2850 // flipmatrix.translate(0, -menuoffset);
2851 SDL_Surface* tempbufferFlipped = FlipSurfaceVerticle(tempBuffer);
2852 //put the stored backbuffer in the backbuffer.
2853 SDL_FillRect(backBuffer, NULL, 0x00000000);
2854 BlitSurfaceStandard(tempbufferFlipped, NULL, backBuffer, NULL);
2855 SDL_FreeSurface(tempbufferFlipped);
2856 SDL_Rect offsetRect;
2857 setRect (offsetRect, 0, menuoffset, backBuffer->w ,backBuffer->h);
2858 SDL_Surface* temp = FlipSurfaceVerticle(menubuffer);
2859 BlitSurfaceStandard(temp,NULL,backBuffer,&offsetRect);
2860 SDL_FreeSurface(temp);
2861 }
2862 else
2863 {
2864 //put the stored backbuffer in the backbuffer.
2865 BlitSurfaceStandard(tempBuffer, NULL, backBuffer, NULL);
2866
2867 //screenbuffer.copyPixels(backbuffer, backbuffer.rect, new Point(0, menuoffset), null, null, false);
2868 SDL_Rect offsetRect;
2869 setRect (offsetRect, 0, menuoffset, backBuffer->w ,backBuffer->h);
2870 BlitSurfaceStandard(menubuffer,NULL,backBuffer,&offsetRect);
2871 }
2872
2873 //screenbuffer.unlock();
2874 SDL_Rect rect;
2875 setRect(rect, 0, 0, backBuffer->w, backBuffer->h);
2876 screenbuffer->UpdateScreen(backBuffer,&rect);
2877 //backbuffer.lock();
2878 //backbuffer.fillRect(backbuffer.rect, 0x000000);
2879 FillRect(backBuffer, 0x000000);
2880 //backbuffer.unlock();
2881 }
2882
drawhuetile(int x,int y,int t,int c)2883 void Graphics::drawhuetile( int x, int y, int t, int c )
2884 {
2885 point tpoint;
2886 tpoint.x = x;
2887 tpoint.y = y;
2888 switch(c)
2889 {
2890 case 0:
2891 setcolreal(getRGB(250-int(fRandom()*32), 250-int(fRandom()*32), 10));
2892 break;
2893 case 1:
2894 setcolreal(getRGB(250-int(fRandom()*32), 250-int(fRandom()*32), 10));
2895 break;
2896 default:
2897 setcolreal(getRGB(250-int(fRandom()*32), 250-int(fRandom()*32), 10));
2898 break;
2899 }
2900
2901
2902 SDL_Rect rect;
2903 setRect(rect,tpoint.x,tpoint.y,tiles_rect.w, tiles_rect.h);
2904 BlitSurfaceColoured(tiles[t],NULL,backBuffer, &rect, ct);
2905 }
2906
setwarprect(int a,int b,int c,int d)2907 void Graphics::setwarprect( int a, int b, int c, int d )
2908 {
2909 warprect.x = a;
2910 warprect.y = b;
2911 warprect.w = c;
2912 warprect.h = d;
2913 }
2914
textboxcleanup()2915 void Graphics::textboxcleanup()
2916 {
2917 int i = ntextbox - 1;
2918 while (i >= 0 && !textbox[i].active)
2919 {
2920 ntextbox--;
2921 i--;
2922 }
2923 }
2924
textboxcenter()2925 void Graphics::textboxcenter()
2926 {
2927 textbox[m].centerx();
2928 textbox[m].centery();
2929 }
2930
textboxcenterx()2931 void Graphics::textboxcenterx()
2932 {
2933 textbox[m].centerx();
2934 }
2935
textboxwidth()2936 int Graphics::textboxwidth()
2937 {
2938 return textbox[m].w;
2939 }
2940
textboxmove(int xo,int yo)2941 void Graphics::textboxmove(int xo, int yo)
2942 {
2943 textbox[m].xp += xo;
2944 textbox[m].yp += yo;
2945 }
2946
textboxmoveto(int xo)2947 void Graphics::textboxmoveto(int xo)
2948 {
2949 textbox[m].xp = xo;
2950 }
2951
textboxcentery()2952 void Graphics::textboxcentery()
2953 {
2954 textbox[m].centery();
2955 }
2956
crewcolour(const int t)2957 int Graphics::crewcolour(const int t)
2958 {
2959 //given crewmate t, return colour in setcol
2960 if (t == 0) return 0;
2961 if (t == 1) return 20;
2962 if (t == 2) return 14;
2963 if (t == 3) return 15;
2964 if (t == 4) return 13;
2965 if (t == 5) return 16;
2966 return 0;
2967 }
2968
flashlight()2969 void Graphics::flashlight()
2970 {
2971 FillRect(backBuffer, 0xBBBBBBBB);
2972 }
2973
screenshake()2974 void Graphics::screenshake()
2975 {
2976 point tpoint;
2977 //screenbuffer.lock();
2978 if(flipmode)
2979 {
2980 // tpoint.x = int((Math.random() * 7) - 4); tpoint.y = int((Math.random() * 7) - 4);
2981 // flipmatrix.translate(tpoint.x, tpoint.y);
2982 // screenbuffer.draw(backbuffer, flipmatrix);
2983 // flipmatrix.translate(-tpoint.x, -tpoint.y);
2984
2985 screenbuffer->ClearScreen(0x000);
2986 tpoint.x = (fRandom() * 7) - 4;
2987 tpoint.y = (fRandom() * 7) - 4;
2988 SDL_Rect shakeRect;
2989 setRect(shakeRect,tpoint.x, tpoint.y, backBuffer->w, backBuffer->h);
2990 SDL_Surface* flipBackBuffer = FlipSurfaceVerticle(backBuffer);
2991 screenbuffer->UpdateScreen( flipBackBuffer, &shakeRect);
2992 SDL_FreeSurface(flipBackBuffer);
2993 }
2994 else
2995 {
2996 //FillRect(screenbuffer, 0x000);
2997 //SDL_Rect rect;
2998 //setRect(rect, blackBars/2, 0, screenbuffer->w, screenbuffer->h);
2999 //SDL_BlitSurface(backBuffer, NULL, screenbuffer, &rect);
3000 screenbuffer->ClearScreen(0x000);
3001 tpoint.x = static_cast<Sint32>((fRandom() * 7) - 4);
3002 tpoint.y = static_cast<Sint32>((fRandom() * 7) - 4);
3003 SDL_Rect shakeRect;
3004 setRect(shakeRect,tpoint.x, tpoint.y, backBuffer->w, backBuffer->h);
3005 screenbuffer->UpdateScreen( backBuffer, &shakeRect);
3006 // screenbuffer.copyPixels(backbuffer, backbuffer.rect, tpoint, null, null, false);
3007 }
3008 //screenbuffer.unlock();
3009
3010 //backbuffer.lock();
3011 FillRect(backBuffer, 0x000000 );
3012 //backbuffer.fillRect(backbuffer.rect, 0x000000);
3013 //backbuffer.unlock();
3014 }
3015
render()3016 void Graphics::render()
3017 {
3018 if(screenbuffer == NULL)
3019 {
3020 return;
3021 }
3022 if(flipmode)
3023 {
3024 SDL_Rect rect;
3025 setRect(rect, 0, 0, backBuffer->w, backBuffer->h);
3026 //setRect(rect, 0, 0, backBuffer->w, backBuffer->h);
3027 //SDL_BlitSurface(backBuffer, NULL, screenbuffer, &rect);
3028 SDL_Surface* tempsurface = FlipSurfaceVerticle(backBuffer);
3029 if(tempsurface != NULL)
3030 {
3031 screenbuffer->UpdateScreen( tempsurface, &rect);
3032 SDL_FreeSurface(tempsurface);
3033 }
3034 }
3035 else
3036 {
3037 SDL_Rect rect;
3038 setRect(rect, 0, 0, backBuffer->w, backBuffer->h);
3039 //setRect(rect, 0, 0, backBuffer->w, backBuffer->h);
3040 //SDL_BlitSurface(backBuffer, NULL, screenbuffer, &rect);
3041 screenbuffer->UpdateScreen( backBuffer, &rect);
3042 }
3043 }
3044
bigrprint(int x,int y,std::string & t,int r,int g,int b,bool cen,float sc)3045 void Graphics::bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen, float sc)
3046 {
3047 if (r < 0) r = 0;
3048 if (g < 0) g = 0;
3049 if (b < 0) b = 0;
3050 if (r > 255) r = 255;
3051 if (g > 255) g = 255;
3052 if (b > 255) b = 255;
3053 ct.colour = getRGB(r, g, b);
3054
3055 x = x / (sc);
3056
3057 x -= (len(t));
3058
3059 if (r < -1) r = -1; if (g < 0) g = 0; if (b < 0) b = 0;
3060 if (r > 255) r = 255; if (g > 255) g = 255; if (b > 255) b = 255;
3061 ct.colour = getRGB(r, g, b);
3062
3063 if (cen)
3064 {
3065 x = std::max(160 - (int((len(t)/ 2.0)*sc)), 0 );
3066 }
3067 else
3068 {
3069 x *= (sc);
3070 }
3071
3072 int bfontpos = 0;
3073 int cur;
3074 for (size_t i = 0; i < t.length(); i++)
3075 {
3076 cur = (t.c_str())[i];
3077 if (cur > 255 || cur < 0)
3078 {
3079 cur = '?';
3080 }
3081 if (flipmode)
3082 {
3083 SDL_Surface* tempPrint = ScaleSurfaceSlow(flipbfont[cur], bfont[cur]->w *sc,bfont[cur]->h *sc);
3084 SDL_Rect printrect = { Sint16(x + bfontpos), Sint16(y) , Sint16(bfont_rect.w*sc), Sint16(bfont_rect.h * sc)};
3085 BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect ,ct);
3086 SDL_FreeSurface(tempPrint);
3087 }
3088 else
3089 {
3090 SDL_Surface* tempPrint = ScaleSurfaceSlow(bfont[cur], bfont[cur]->w *sc,bfont[cur]->h *sc);
3091 SDL_Rect printrect = { Sint16((x) + bfontpos), Sint16(y) , Sint16(bfont_rect.w*sc), Sint16(bfont_rect.h * sc)};
3092 BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct);
3093 SDL_FreeSurface(tempPrint);
3094 }
3095 bfontpos+=bfontlen[cur]* sc;
3096 }
3097 }
3098
drawtele(int x,int y,int t,int c,UtilityClass & help)3099 void Graphics::drawtele(int x, int y, int t, int c, UtilityClass& help)
3100 {
3101 setcolreal(getRGB(16,16,16));
3102
3103 SDL_Rect telerect;
3104 setRect(telerect, x , y, tele_rect.w, tele_rect.h );
3105 BlitSurfaceColoured(tele[0], NULL, backBuffer, &telerect, ct);
3106
3107 setcol(c, help);
3108 if (t > 9) t = 8;
3109 if (t < 0) t = 0;
3110
3111 BlitSurfaceColoured(tele[t], NULL, backBuffer, &telerect, ct);
3112 }
3113
getRGB(Uint8 r,Uint8 g,Uint8 b)3114 Uint32 Graphics::getRGB(Uint8 r, Uint8 g, Uint8 b)
3115 {
3116 return SDL_MapRGB(backBuffer->format, b, g, r);
3117 }
3118
getBGR(Uint8 r,Uint8 g,Uint8 b)3119 Uint32 Graphics::getBGR(Uint8 r, Uint8 g, Uint8 b)
3120 {
3121 return SDL_MapRGB(backBuffer->format, r, g, b);
3122 }
3123
getRGB(Uint32 _col)3124 Uint32 Graphics::getRGB(Uint32 _col)
3125 {
3126 return ( _col);
3127 }
3128
RGBflip(Uint8 r,Uint8 g,Uint8 b)3129 Uint32 Graphics::RGBflip(Uint8 r, Uint8 g, Uint8 b)
3130 {
3131 return SDL_MapRGB(backBuffer->format, r, g, b);
3132 }
3133
RGBf(int r,int g,int b)3134 Uint32 Graphics::RGBf(int r, int g, int b)
3135 {
3136 r = (r+128) / 3;
3137 g = (g+128) / 3;
3138 b = (b+128) / 3;
3139 return SDL_MapRGB(backBuffer->format, r, g, b);
3140 }
3141
setcolreal(Uint32 t)3142 void Graphics::setcolreal(Uint32 t)
3143 {
3144 ct.colour = t;
3145 }
3146
drawtile(int x,int y,int t)3147 void Graphics::drawtile(int x, int y, int t)
3148 {
3149 SDL_Rect drawRect;
3150 setRect(drawRect,x,y, tiles_rect.w, tiles_rect.h );
3151 BlitSurfaceStandard(tiles[t] ,NULL, backBuffer,&drawRect);
3152 }
3153
drawforetile(int x,int y,int t)3154 void Graphics::drawforetile(int x, int y, int t)
3155 {
3156 //frontbuffer.copyPixels(tiles[t], tiles_rect, tpoint);
3157 SDL_Rect rect;
3158 setRect(rect, x,y,tiles_rect.w, tiles_rect.h);
3159 BlitSurfaceStandard(tiles[t],NULL, forgroundBuffer, &rect );
3160 }
3161
drawforetile2(int x,int y,int t)3162 void Graphics::drawforetile2(int x, int y, int t)
3163 {
3164 //frontbuffer.copyPixels(tiles2[t], tiles_rect, tpoint);
3165 SDL_Rect rect;
3166 setRect(rect, x,y,tiles_rect.w, tiles_rect.h);
3167 BlitSurfaceStandard(tiles2[t],NULL, forgroundBuffer, &rect );
3168 }
3169
drawforetile3(int x,int y,int t,int off)3170 void Graphics::drawforetile3(int x, int y, int t, int off)
3171 {
3172 SDL_Rect rect;
3173 setRect(rect, x,y,tiles_rect.w, tiles_rect.h);
3174 BlitSurfaceStandard(tiles3[t+(off*30)],NULL, forgroundBuffer, &rect );
3175 //frontbuffer.copyPixels(tiles3[t+(off*30)], tiles_rect, tpoint);
3176 }
3177
drawrect(int x,int y,int w,int h,int r,int g,int b)3178 void Graphics::drawrect(int x, int y, int w, int h, int r, int g, int b)
3179 {
3180 SDL_Rect madrect;
3181 //Draw the retangle indicated by that object
3182 madrect.x = x;
3183 madrect.y = y;
3184 madrect.w = w;
3185 madrect.h = 1;
3186 //backbuffer.fillRect(madrect, RGB(r,g,b));
3187 FillRect(backBuffer, madrect, getRGB(b,g,r));
3188
3189 madrect.w = 1;
3190 madrect.h = h;
3191 FillRect(backBuffer, madrect, getRGB(b,g,r));
3192
3193 madrect.x = x + w - 1;
3194 madrect.w = 1;
3195 madrect.h = h;
3196 FillRect(backBuffer, madrect, getRGB(b,g,r));
3197 madrect.x = x;
3198 madrect.y = y + h - 1;
3199 madrect.w = w;
3200 madrect.h = 1;
3201 FillRect(backBuffer, madrect, getRGB(b,g,r));
3202 }
3203
onscreen(int t)3204 bool Graphics::onscreen(int t)
3205 {
3206 return (t >= -40 && t <= 280);
3207 }
3208