1 // BlinkenSisters - Hunt for the Lost Pixels
2 // Bringing back the fun of the 80s
3 //
4 // (C) 2005-07 Rene Schickbauer, Wolfgang Dautermann
5 //
6 // See License.txt for licensing information
7 //
8
9
10 #include "globals.h"
11 #include "tiles.h"
12 #include "levelhandler.h"
13 #include "blending.h"
14 #include "errorhandler.h"
15 #include "engine.h"
16 #include "convert.h"
17
18 SDL_Surface *TILES_Surface;
19
initTiles(const char * fname)20 void initTiles(const char *fname) {
21 char fullfname[MAX_FNAME_LENGTH];
22 sprintf(fullfname, "%s", configGetPath(fname));
23 SDL_Surface* temp = IMG_Load(fullfname);
24 if(!temp) {
25 DIE(ERROR_IMAGE_READ, fullfname);
26 }
27 TILES_Surface = convertToBSSurface(temp);
28 SDL_FreeSurface(temp);
29 }
30
deInitTiles()31 void deInitTiles() {
32 SDL_FreeSurface(TILES_Surface);
33 }
34
paintSingleTile(const Uint32 num,const Sint32 x,const Sint32 y)35 void paintSingleTile(const Uint32 num, const Sint32 x, const Sint32 y) {
36 if(num >= (Uint32)(TILES_Surface->h / TILESIZE)) {
37 return; // Illegal tile
38 }
39
40 if(x < (1 - TILESIZE) ||
41 y < (1 - TILESIZE) ||
42 x > SCR_WIDTH ||
43 y > SCR_HEIGHT) {
44 return; // Tile is invisible so we ignore it
45 }
46
47 static SDL_Rect src;
48 static SDL_Rect dest;
49
50 src.x = 0;
51 src.y = TILESIZE * num;
52 src.w = dest.w = src.h = dest.h = TILESIZE;
53 dest.x = x;
54 dest.y = y;
55
56 SDL_BlitSurface(TILES_Surface, &src, gScreen, &dest);
57
58 return;
59 }
60
getNumOfTiles()61 Uint32 getNumOfTiles() {
62 return (TILES_Surface->h / TILESIZE + 1);
63 }
64
65
paintLevelTiles(const Uint32 xoffs,const Uint32 yoffs)66 void paintLevelTiles(const Uint32 xoffs, const Uint32 yoffs) {
67 DISPLAYLIST *tthis = lhandle.dlist;
68 Sint32 xpos;
69 Sint32 ypos;
70
71 if (SDL_MUSTLOCK(TILES_Surface))
72 if (SDL_LockSurface(TILES_Surface) < 0)
73 return;
74
75 while(tthis) {
76 xpos = tthis->x - xoffs;
77 ypos = tthis->y - yoffs;
78 if(tthis->type < 10 && xpos > -TILESIZE && xpos < SCR_WIDTH && ypos > -TILESIZE && ypos < SCR_HEIGHT) {
79 paintSingleTile(tthis->type, xpos, ypos);
80 }
81 tthis = tthis->next;
82 }
83
84 // Unlock if needed
85 if (SDL_MUSTLOCK(TILES_Surface))
86 SDL_UnlockSurface(TILES_Surface);
87
88
89 }
90