diff --git a/src/global.h b/src/global.h index 961722b6..b8423bf9 100644 --- a/src/global.h +++ b/src/global.h @@ -353,6 +353,7 @@ GFX2_GLOBAL T_Tile * Main_tilemap; GFX2_GLOBAL short Main_tilemap_width; GFX2_GLOBAL short Main_tilemap_height; +GFX2_GLOBAL byte Main_tilemap_allow_flip; ///< 0:no, 1:horizontally, 2:vertically, 3:both // -- Spare page data diff --git a/src/struct.h b/src/struct.h index 78b3e7d5..b9c0ff51 100644 --- a/src/struct.h +++ b/src/struct.h @@ -547,6 +547,7 @@ typedef struct { int Previous; int Next; + byte Flipped; ///< 0:no, 1:horizontally, 2:vertically, 3:both } T_Tile; #endif diff --git a/src/tiles.c b/src/tiles.c index 9d8a55fa..40b6d2c1 100644 --- a/src/tiles.c +++ b/src/tiles.c @@ -144,13 +144,32 @@ void Tilemap_draw(word x, word y, byte color) return; tile = first_tile = TILE_FOR_COORDS(x,y); + rel_x = (x - Snap_offset_X + Snap_width) % Snap_width; rel_y = (y - Snap_offset_Y + Snap_height) % Snap_height; do { int xx,yy; - xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + rel_x; - yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + rel_y; + switch(Main_tilemap[tile].Flipped ^ Main_tilemap[first_tile].Flipped) + { + case 0: // no + default: + xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + rel_x; + yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + rel_y; + break; + case 1: // horizontal + xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + Snap_width-rel_x-1; + yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + rel_y; + break; + case 2: // vertical + xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + rel_x; + yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + Snap_height - rel_y - 1; + break; + case 3: // both + xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + Snap_width-rel_x-1; + yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + Snap_height - rel_y - 1; + break; + } Pixel_in_current_screen(xx,yy,color,yy>=Limit_top&&yy<=Limit_bottom&&xx>=Limit_left&&xx<=Limit_right); tile = Main_tilemap[tile].Next; } while (tile != first_tile); @@ -175,6 +194,23 @@ int Tile_is_same(int t1, int t2) return 1; } +/// +int Tile_is_same_y(int t1, int t2) +{ + byte *bmp1,*bmp2; + int y; + + bmp1 = Main_backups->Pages->Image[Main_current_layer].Pixels+(TILE_Y(t1))*Main_image_width+(TILE_X(t1)); + bmp2 = Main_backups->Pages->Image[Main_current_layer].Pixels+(TILE_Y(t2)+Snap_height-1)*Main_image_width+(TILE_X(t2)); + + for (y=0; y < Snap_height; y++) + { + if (memcmp(bmp1+y*Main_image_width, bmp2-y*Main_image_width, Snap_width)) + return 0; + } + return 1; +} + /// Create or update a tilemap based on current screen pixels. void Tilemap_create(void) { @@ -217,43 +253,66 @@ void Tilemap_create(void) Main_tilemap_width=width; Main_tilemap_height=height; - // Init array with all tiles unique by default + // Initialize array with all tiles unique by default for (tile=0; tile=tile) - { - // This tile is really unique. - // Nothing to do at the moment - break; + break; // stop loop on ref_tile } } + if (ref_tile