Created
January 7, 2026 19:11
-
-
Save Achie72/82535ff632150945e9b94ac232cf9de5 to your computer and use it in GitHub Desktop.
Loading 8x8 maps for PICO-8
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
| function load_map(index) | |
| -- reset the won flag | |
| won = false | |
| --reset the map | |
| for i=0,7 do | |
| for j=0,7 do | |
| mset(i,j,0) | |
| end | |
| end | |
| -- we wan to copy the indexth map | |
| -- into the 0,8 area | |
| -- if we are on second or more rows | |
| -- we need to offset the y and reduce the index | |
| -- so x is added to correctly | |
| local y_offset = 0 | |
| if index >= 16 then | |
| y_offset = flr(index/16) | |
| index = index % 16 | |
| end | |
| sequence = {} | |
| for i=0,7 do | |
| local letter = mget(i + index*8, 0+y_offset*8) -- for now, later this needs offset as well. | |
| -- copy the tile sequence (the word) into ur goal checker | |
| if letter ~= 0 then | |
| add(sequence,letter) | |
| mset(i + index*8, 0+y_offset*8, 0) | |
| end | |
| end | |
| for i=0,7 do | |
| for j=0,7 do | |
| -- in the future consider second or more rows of maps | |
| -- for now only single row | |
| local tile = mget(i + 8*index, j+y_offset*8) | |
| -- check if this is the green player tile | |
| if tile == 2 then | |
| player.x = i | |
| player.y = j | |
| else | |
| -- set it otherwise | |
| mset(i,j,tile) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment