VERSIÓ 1.4.7
- [NEW] map.cell() per a establir o llegir el tamany dels tiles del mapa
This commit is contained in:
35
mini.cpp
35
mini.cpp
@@ -60,6 +60,8 @@ surface_t *screen_surface = &surfaces[0];
|
||||
surface_t *dest_surface = screen_surface;
|
||||
surface_t *source_surface = NULL;
|
||||
surface_t *map_surface = NULL;
|
||||
uint8_t tile_width = 8;
|
||||
uint8_t tile_height = 8;
|
||||
|
||||
font_t fonts[MAX_FONTS];
|
||||
font_t *current_font;
|
||||
@@ -1308,10 +1310,10 @@ void sset(int x, int y, uint8_t color) {
|
||||
|
||||
void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
|
||||
if (!source_surface) return;
|
||||
int tx = (n%(source_surface->w >> 3))<<3;
|
||||
int ty = (n/(source_surface->w >> 3))<<3;
|
||||
int tw = w*8 - 1;
|
||||
int th = h*8 - 1;
|
||||
int tx = (n%(source_surface->w / tile_width))*tile_width;
|
||||
int ty = (n/(source_surface->w / tile_height))*tile_height;
|
||||
int tw = w*tile_width - 1;
|
||||
int th = h*tile_height - 1;
|
||||
//int tx2 = tx1 + tw;
|
||||
//int ty2 = ty1 + th;
|
||||
int txd = 1;
|
||||
@@ -1444,6 +1446,13 @@ void mset(int celx, int cely, uint8_t snum) {
|
||||
TILES(celx, cely) = snum;
|
||||
}
|
||||
|
||||
uint8_t gettilew() { return tile_width; }
|
||||
uint8_t gettileh() { return tile_height; }
|
||||
void settilesize(int w, int h) {
|
||||
tile_width = w;
|
||||
tile_height = h;
|
||||
}
|
||||
|
||||
void map() { //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer) {
|
||||
if (map_surface==NULL) return;
|
||||
int celw = map_surface->w;// >> 3;
|
||||
@@ -1452,28 +1461,28 @@ void map() { //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, u
|
||||
int cely = 0;
|
||||
//if (celw <= 0 || celh <= 0 || celw >= TILES_WIDTH || celh >= TILES_HEIGHT) return;
|
||||
int sx = ds::origin[0]; int sy = ds::origin[1];
|
||||
if (sx+celw*8 < ds::clip[0] || sx > ds::clip[2] || sy+celh*8 < ds::clip[1] || sy > ds::clip[3]) return;
|
||||
if (sx+celw*tile_width < ds::clip[0] || sx > ds::clip[2] || sy+celh*tile_height < ds::clip[1] || sy > ds::clip[3]) return;
|
||||
if (sx<0) {
|
||||
int diff = -sx/8;
|
||||
int diff = -sx/tile_width;
|
||||
celx += diff;
|
||||
celw -= diff;
|
||||
sx += diff*8;
|
||||
sx += diff*tile_width;
|
||||
}
|
||||
if (sy<0) {
|
||||
int diff = -sy/8;
|
||||
int diff = -sy/tile_height;
|
||||
cely += diff;
|
||||
celh -= diff;
|
||||
sy += diff*8;
|
||||
sy += diff*tile_height;
|
||||
}
|
||||
sx -= ds::origin[0]; sy -= ds::origin[1];
|
||||
for (int y=0; y<celh; ++y) {
|
||||
for (int x=0; x<celw; ++x) {
|
||||
const uint8_t tile = mget(celx+x, cely+y);
|
||||
if (tile==0) continue;
|
||||
const int fx = sx+(x*8)+ds::origin[0];
|
||||
const int fy = sy+(y*8)+ds::origin[1];
|
||||
if ( (fx+8<ds::clip[0]) || (fy+8<ds::clip[1]) || (fx>ds::clip[2]) || (fy>ds::clip[3]) ) continue;
|
||||
spr(tile, sx+x*8, sy+y*8);
|
||||
const int fx = sx+(x*tile_width)+ds::origin[0];
|
||||
const int fy = sy+(y*tile_height)+ds::origin[1];
|
||||
if ( (fx+tile_width<ds::clip[0]) || (fy+tile_height<ds::clip[1]) || (fx>ds::clip[2]) || (fy>ds::clip[3]) ) continue;
|
||||
spr(tile, sx+x*tile_width, sy+y*tile_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user