]>
git.r.bdr.sh - rbdr/pico-engine/blob - map.cpp
99b7b29625c323fca9e26d1f269ee57d93b347b3
5 height
= SCREEN_HEIGHT
/TILE_HEIGHT
;
6 width
= SCREEN_WIDTH
/TILE_WIDTH
;
30 sheet
= IMG_Load("./sprites/tilesheet.gif");
31 Uint32 colorkey
= SDL_MapRGB(sheet
->format
, 255, 0, 255);
32 SDL_SetColorKey(sheet
, SDL_SRCCOLORKEY
| SDL_RLEACCEL
, colorkey
); //le ponemos al buddy el colorkey para las transparencias
34 std::ifstream
in("./map0.bin", std::ios::in
| std::ios::binary
);
39 in
.seekg (0, std::ios::end
);
41 in
.seekg (0, std::ios::beg
);
43 in
.read((char *) &tiles
, length
);
45 // see how many bytes have been read
46 std::cout
<< in
.gcount() << " bytes read\n";
52 void Map::drawmap(SDL_Surface
*viewport
){
54 int x1
, x2
, y1
, y2
, tx
, ty
;
57 x1
= (sx%TILE_WIDTH
) * -1;
58 x2
= x1
+ SCREEN_WIDTH
+ (x1
== 0 ? 0 : TILE_WIDTH
);
59 y1
= (sy%TILE_HEIGHT
) * -1;
60 y2
= y1
+ SCREEN_HEIGHT
+ (y1
== 0 ? 0 : TILE_WIDTH
);
62 for(int y
= y1
; y
<y2
; y
+=TILE_HEIGHT
){
64 for(int x
= x1
; x
<x2
; x
+=TILE_WIDTH
){
65 this->draw_tile(viewport
, tiles
[ty
][tx
], x
, y
);
72 void Map::draw_tile(SDL_Surface
*viewport
, int type
, int x
, int y
){
74 if(type
> 14 || type
< 0){
80 x_tile
= floor(type
/ 3) * TILE_HEIGHT
;
81 y_tile
= (type
% 3) * TILE_WIDTH
;
83 /*Draws a rectangular surface from sx,sy of swxsh dimensions to dx, dy*/
84 Gfx::drawsurface(y_tile
, x_tile
, TILE_WIDTH
, TILE_HEIGHT
, this->sheet
,
94 // /*boxRGBA(viewport,
97 // 255, 255, 255, 255);*/
104 // x+TILE_WIDTH, y+TILE_HEIGHT,
105 // 238, 0, 139, 255);
112 // x+TILE_WIDTH, y+TILE_HEIGHT,
119 int Map::get_passability(int x
, int y
){
121 return tileset
[tiles
[(sy
+y
)/TILE_HEIGHT
][(sx
+x
)/TILE_WIDTH
]];
124 int Map::get_tile(int x
, int y
){
125 return tiles
[(sy
+y
)/TILE_HEIGHT
][(sx
+x
)/TILE_WIDTH
];
136 void Map::set_sx(int x
){
140 void Map::set_sy(int y
){