]>
git.r.bdr.sh - rbdr/pico-engine/blob - map.cpp
5 height
= SCREEN_HEIGHT
/TILE_HEIGHT
;
6 width
= SCREEN_WIDTH
/TILE_WIDTH
;
29 sheet
= IMG_Load("./sprites/tilesheet.png");
30 // sheet = SDL_DisplayFormat(raw_sprite);
31 // SDL_FreeSurface(raw_sprite);
32 Uint32 colorkey
= SDL_MapRGB(sheet
->format
, 255, 0, 255);
33 SDL_SetColorKey(sheet
, SDL_SRCCOLORKEY
| SDL_RLEACCEL
, colorkey
);
35 std::ifstream
in("./map0.bin", std::ios::in
| std::ios::binary
);
40 in
.seekg (0, std::ios::end
);
42 in
.seekg (0, std::ios::beg
);
44 in
.read((char *) &tiles
, length
);
46 // see how many bytes have been read
47 std::cout
<< in
.gcount() << " bytes read\n";
53 void Map::drawmap(SDL_Surface
*viewport
){
55 int x1
, x2
, y1
, y2
, tx
, ty
;
58 x1
= (sx%TILE_WIDTH
) * -1;
59 x2
= x1
+ SCREEN_WIDTH
+ (x1
== 0 ? 0 : TILE_WIDTH
);
60 y1
= (sy%TILE_HEIGHT
) * -1;
61 y2
= y1
+ SCREEN_HEIGHT
+ (y1
== 0 ? 0 : TILE_WIDTH
);
63 for(int y
= y1
; y
<y2
; y
+=TILE_HEIGHT
){
65 for(int x
= x1
; x
<x2
; x
+=TILE_WIDTH
){
66 this->draw_tile(viewport
, tiles
[ty
][tx
], x
, y
);
73 void Map::draw_tile(SDL_Surface
*viewport
, int type
, int x
, int y
){
75 if(type
> 14 || type
< 0){
81 x_tile
= floor(type
/ 3) * TILE_HEIGHT
;
82 y_tile
= (type
% 3) * TILE_WIDTH
;
84 /*Draws a rectangular surface from sx,sy of swxsh dimensions to dx, dy*/
85 Gfx::drawsurface(y_tile
, x_tile
, TILE_WIDTH
, TILE_HEIGHT
, this->sheet
,
95 // /*boxRGBA(viewport,
98 // 255, 255, 255, 255);*/
105 // x+TILE_WIDTH, y+TILE_HEIGHT,
106 // 238, 0, 139, 255);
113 // x+TILE_WIDTH, y+TILE_HEIGHT,
120 int Map::get_passability(int x
, int y
){
122 return tileset
[tiles
[(sy
+y
)/TILE_HEIGHT
][(sx
+x
)/TILE_WIDTH
]];
125 int Map::get_tile(int x
, int y
){
126 return tiles
[(sy
+y
)/TILE_HEIGHT
][(sx
+x
)/TILE_WIDTH
];
137 void Map::set_sx(int x
){
141 void Map::set_sy(int y
){