Created
January 5, 2026 19:36
-
-
Save Achie72/5cb3ca6f4ecebd73a5d24de03159af07 to your computer and use it in GitHub Desktop.
Word Sokoban flood fill for the word
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- here these numbers are a bit weird, due to how i have my sprite sheet, | |
| -- letters start at tile 16, so WIN spelled out with tile numbers is this | |
| -- sequence trust me. W = 38, I = 24 etc... | |
| sequence = {38,24,29} | |
| won = false | |
| function check_for_sequence(x,y,index) | |
| -- the char matches the winning words char | |
| if mget(x,y) == sequence[index] then | |
| -- if this is the last char in | |
| -- the word, return | |
| if index == #sequence then | |
| printh("found") | |
| won = true | |
| end | |
| -- now check if one of the | |
| -- neighbours is the next letter | |
| index += 1 | |
| check_for_sequence(x-1,y,index) | |
| check_for_sequence(x,y-1,index) | |
| check_for_sequence(x+1,y,index) | |
| check_for_sequence(x,y+1,index) | |
| end | |
| end | |
| function _update() | |
| pressed = false | |
| if btnp(0) then | |
| player.direction = directions.left | |
| pressed = true | |
| elseif btnp(1) then | |
| player.direction = directions.right | |
| pressed = true | |
| elseif btnp(2) then | |
| player.direction = directions.up | |
| pressed = true | |
| elseif btnp(3) then | |
| player.direction = directions.down | |
| pressed = true | |
| end | |
| if pressed then | |
| local newx = player.x+dir_table[player.direction][1] | |
| local newy = player.y+dir_table[player.direction][2] | |
| -- not a wall | |
| if mget(newx,newy) ~= 1 then | |
| -- check if it is a box | |
| if mget(newx,newy) > 15 then | |
| -- check if the box can move as well | |
| local newbx = newx+dir_table[player.direction][1] | |
| local newby = newy+dir_table[player.direction][2] | |
| if mget(newbx,newby) == 0 or mget(newbx,newby) == 4 then | |
| -- move box | |
| -- save tile first | |
| local tile = mget(newx,newy) | |
| mset(newbx,newby,tile) | |
| mset(newx,newy,0) | |
| -- move player | |
| player.x = newx | |
| player.y = newy | |
| end | |
| -- only check for sequence on push | |
| printh("____") | |
| -- check for the word pls | |
| for i=0,8 do | |
| for j=0,6 do | |
| check_for_sequence(i,j,1) | |
| end | |
| end | |
| else -- not box, so move | |
| player.x = newx | |
| player.y = newy | |
| end | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made for my Kofi article about a sokoban word puzzle game: https://ko-fi.com/post/PICO-ASCII-Jam-0--In-the-beningi-G2G11RQH04