]>
Commit | Line | Data |
---|---|---|
1 | #include "stdafx.h"\r | |
2 | \r | |
3 | Map::Map(void)\r | |
4 | {\r | |
5 | height = SCREEN_HEIGHT/TILE_HEIGHT;\r | |
6 | width = SCREEN_WIDTH/TILE_WIDTH;\r | |
7 | sx = 0;\r | |
8 | sy = 0;\r | |
9 | \r | |
10 | \r | |
11 | //Passability\r | |
12 | tileset[0] = 0;\r | |
13 | tileset[1] = 0;\r | |
14 | tileset[2] = 0;\r | |
15 | tileset[3] = 0;\r | |
16 | tileset[4] = 0;\r | |
17 | tileset[5] = 0;\r | |
18 | tileset[6] = 1;\r | |
19 | tileset[7] = 1;\r | |
20 | tileset[8] = 1;\r | |
21 | tileset[9] = 1;\r | |
22 | tileset[10] = 1;\r | |
23 | tileset[11] = 1;\r | |
24 | tileset[12] = 1;\r | |
25 | tileset[13] = 1;\r | |
26 | tileset[14] = 1;\r | |
27 | \r | |
28 | \r | |
29 | //Get the Sheet\r | |
30 | sheet = IMG_Load("./sprites/tilesheet.gif");\r | |
31 | Uint32 colorkey = SDL_MapRGB(sheet->format, 255, 0, 255);\r | |
32 | SDL_SetColorKey(sheet, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); //le ponemos al buddy el colorkey para las transparencias\r | |
33 | \r | |
34 | std::ifstream in("./map0.bin", std::ios::in | std::ios::binary);\r | |
35 | \r | |
36 | int length;\r | |
37 | \r | |
38 | //get the size\r | |
39 | in.seekg (0, std::ios::end);\r | |
40 | length = in.tellg();\r | |
41 | in.seekg (0, std::ios::beg);\r | |
42 | \r | |
43 | in.read((char *) &tiles, length);\r | |
44 | \r | |
45 | // see how many bytes have been read\r | |
46 | std::cout << in.gcount() << " bytes read\n";\r | |
47 | \r | |
48 | in.close();\r | |
49 | \r | |
50 | }\r | |
51 | \r | |
52 | void Map::drawmap(SDL_Surface *viewport){\r | |
53 | \r | |
54 | int x1, x2, y1, y2, tx, ty;\r | |
55 | tx = sx/TILE_WIDTH;\r | |
56 | ty = sy/TILE_HEIGHT;\r | |
57 | x1 = (sx%TILE_WIDTH) * -1;\r | |
58 | x2 = x1 + SCREEN_WIDTH + (x1 == 0 ? 0 : TILE_WIDTH);\r | |
59 | y1 = (sy%TILE_HEIGHT) * -1;\r | |
60 | y2 = y1 + SCREEN_HEIGHT + (y1 == 0 ? 0 : TILE_WIDTH);\r | |
61 | \r | |
62 | for(int y = y1; y<y2; y+=TILE_HEIGHT){\r | |
63 | tx = sx/TILE_WIDTH;\r | |
64 | for(int x = x1; x<x2; x+=TILE_WIDTH){\r | |
65 | this->draw_tile(viewport, tiles[ty][tx], x, y);\r | |
66 | tx++;\r | |
67 | }\r | |
68 | ty++;\r | |
69 | }\r | |
70 | }\r | |
71 | \r | |
72 | void Map::draw_tile(SDL_Surface *viewport, int type, int x, int y){\r | |
73 | \r | |
74 | if(type > 14 || type < 0){\r | |
75 | type = 0;\r | |
76 | }\r | |
77 | \r | |
78 | int x_tile, y_tile;\r | |
79 | \r | |
80 | x_tile = floor(type / 3) * TILE_HEIGHT;\r | |
81 | y_tile = (type % 3) * TILE_WIDTH;\r | |
82 | \r | |
83 | /*Draws a rectangular surface from sx,sy of swxsh dimensions to dx, dy*/\r | |
84 | Gfx::drawsurface(y_tile, x_tile, TILE_WIDTH, TILE_HEIGHT, this->sheet,\r | |
85 | x, y, viewport);\r | |
86 | \r | |
87 | // switch (type) {\r | |
88 | // \r | |
89 | // \r | |
90 | // \r | |
91 | // case 0:\r | |
92 | // case 1:\r | |
93 | // case 2:\r | |
94 | // /*boxRGBA(viewport,\r | |
95 | // x, y,\r | |
96 | // x+25, y+25,\r | |
97 | // 255, 255, 255, 255);*/\r | |
98 | // break;\r | |
99 | // case 3:\r | |
100 | // case 4:\r | |
101 | // case 5:\r | |
102 | // boxRGBA(viewport,\r | |
103 | // x, y,\r | |
104 | // x+TILE_WIDTH, y+TILE_HEIGHT,\r | |
105 | // 238, 0, 139, 255);\r | |
106 | // break;\r | |
107 | // case 6:\r | |
108 | // case 7:\r | |
109 | // case 8:\r | |
110 | // boxRGBA(viewport,\r | |
111 | // x, y,\r | |
112 | // x+TILE_WIDTH, y+TILE_HEIGHT,\r | |
113 | // 34, 34, 34, 255);\r | |
114 | // break;\r | |
115 | // }\r | |
116 | \r | |
117 | }\r | |
118 | \r | |
119 | int Map::get_passability(int x, int y){\r | |
120 | \r | |
121 | return tileset[tiles[(sy+y)/TILE_HEIGHT][(sx+x)/TILE_WIDTH]];\r | |
122 | }\r | |
123 | \r | |
124 | int Map::get_tile(int x, int y){\r | |
125 | return tiles[(sy+y)/TILE_HEIGHT][(sx+x)/TILE_WIDTH];\r | |
126 | }\r | |
127 | \r | |
128 | int Map::get_sx(){\r | |
129 | return sx;\r | |
130 | }\r | |
131 | \r | |
132 | int Map::get_sy(){\r | |
133 | return sy;\r | |
134 | }\r | |
135 | \r | |
136 | void Map::set_sx(int x){\r | |
137 | sx = x;\r | |
138 | }\r | |
139 | \r | |
140 | void Map::set_sy(int y){\r | |
141 | sy = y;\r | |
142 | }\r | |
143 | \r | |
144 | Map::~Map(void){\r | |
145 | \r | |
146 | } |