What I will love is on a 4 x 4 grid (or an image cut into a tile), numbered from 1 to 15 and the 16th remains empty, by clicking on a number (imperatively next to the empty spirte), this number and the empty sprite exchange their positions.
I try to reproduce the “taquin game” (“jeu du taquin” in french), but I block for the exchange of positions. Do you have an idea please?
I’ll show you the screenshots of the tests I’m doing, as well as the .aia if that helps you.
where every number represents blocks of this type:
In a global variable, store the indices of the current “empty” tile (say, i=4, j=4).
When a sprite is touched, get the i (row) and j (column) indices from the list, let’s call these a and b for the time being.
Now, with a, b being indices of the touched tile and i, j being the indices of the empty tile,
if ((|a - i| = 1) and (|b - j| = 1)) {
variable touched_tile = <touched sprite>.image
set <touched sprite>.image to empty_tile.png
set <previously empty tile>.image to variable touched_tile
i = a
j = b // keeping track of the tile that is now empty
}