Can the image interface work on canvases and, follow-up question, how would image[pos] work?
Viewing post in General Decker Question and Answer Thread
The Image Interface and Canvas Interface are different, but they do have things in common, like .outline[], .merge[], .copy[], and .paste[].
image[pos] is described like this:
The pattern index of an (x,y) pixel of the image. Reads nil out of bounds, ignores out of bounds writes. r/w.
canvas[pos] is described like this:
The pattern index of an (x,y) pixel of the canvas. Reads 0 out of bounds, ignores out of bounds writes. r/w.
The only difference is that canvas[pos] is described as returning 0 if you ask for a pixel outside the edges, but that seems to be incorrect - in my testing canvas[-1,-1] returns nil just like an image.
Yeah, I can work with that.
Okay. Here's the thing, I want to make a raycaster engine in Decker. I understand most of the tutorials that I've watched, except for one thing, making a tile map array. I think I can do it with a list of lists, like
list(list(1,1,1,1,1,1,1,1),list(1,0,0,0,0,0,0,1),list(1,0,0,0,0,0,0,1),list(1,0,0,0,0,0,0,1),list(1,0,0,0,0,0,0,1),list(1,0,0,0,0,0,0,1),list(1,1,1,1,1,1,1,1)
Am I on the right track? It'd make more sense if it was arranged in a block, but I don't think Lil allows for line brakes.
Lil allows line-breaks pretty much anywhere, except inside comments (the comment always ends at the end of the line). Here’s your example, broken over lines:
list(
list(1,1,1,1,1,1,1,1),
list(1,0,0,0,0,0,0,1),
list(1,0,0,0,0,0,0,1),
list(1,0,0,0,0,0,0,1),
list(1,0,0,0,0,0,0,1),
list(1,0,0,0,0,0,0,1),
list(1,1,1,1,1,1,1,1)
)
It doesn’t quite do what you want, though. Instead of making an eight-item list of eight-item lists, it makes a nine-element list where the first eight items are tile numbers, and the ninth item is a nine-element list where the first eight items are tile numbers, and the ninth item is a nine-element list…
You want something more like this:
(list 1,1,1,1,1,1,1,1),
(list 1,0,0,0,0,0,0,1),
(list 1,0,0,0,0,0,0,1),
(list 1,0,0,0,0,0,0,1),
(list 1,0,0,0,0,0,0,1),
(list 1,0,0,0,0,0,0,1),
list 1,1,1,1,1,1,1,1
Because Lil expressions are evaluated from right to left, this starts by stringing some 1s together to make an eight-element list representing the bottom row, then makes a one-element list wrapping the bottom-row list, then joins that wrapper with the one wrapping the second-bottom row, etc.
That will definitely work, but another thing you might consider is representing the tile map with an image. It is also a rectangular array of numbers, but stored more efficiently. It can also be easier to edit - .paste[] the image onto the background of a card, and you can use Decker’s built-in editing tools to draw the level, then .copy[] it back. Or better yet, if you have a card to store each level’s data, put the tilemap on the background image, and add a “Show: None” field named bounds to mark the bounds of the tilemap within the card. If the card representing the level you want to load is called level, you can get the tilemap with level.image.copy[level.widgets.bounds.pos level.widgets.bounds.size].
So... Let me get this straight, I could compress each tile in the map to a pixel and write a program that could read each one and and draw the map itself? The idea is appealing, and, maybe, I can double the number of possible tiles by having the program read the pixels two at a time, or sixteen times with four pixels. If that is possible.
The thing Is that I don't know how to write a program that could read the pixels and turn that into a full map. Maybe with an if-statement and some stored textures... I still don't know, yet.