Table of Contents
Drawing the Map in Darkness
Considering there is a callback function when calling the map function, it may be possible to configure an array corresponding to each map tile to be drawn. The array can mark if the tile should be shown or not. If it should be drawn, then the tile is drawn. If not, then the tile should be just a black tile. The challenge here is that the map function returns a tile, and not a coordinate.
It might be preferable to instead draw the map with our own function. This would allow us to modify it on draw, and also only draw it when things change. Rather, we won't be drawing the map with our own function, but updating the map memory.
Maybe there's a way to use bankswitching to solve this: Use the map in bank 2 as the real-time map, and the map in bank 1 as the original map. Then, have an array of lighting status. Whenever the map should be updated, call an update function to evaluate the lighting array against the bank 2 tiles. If it should be lit, then pull it from bank 1. If it shouldn't, then leave it as is. Once updated, draw the new map.
Considering palette swapping again. If I have the color, then a light grey, a dark grey, and a black, I think I can accomplish what I want. The light green will be one of 4 colors: light green, light grey, dark grey, or black. Sand will follow: brown, light grey, dark grey, black. The other colors start off darker, and so transition more rapidly: water goes from blue, to dark grey, to black; dark green to dark grey to black. In the latter case, there are still 4 shades, just the last two are black. Thus there is an array for each color:
{
{short {<light_green>, <light_grey>, <dark_grey>, <black>}}
{long {<dark_green>, <dark_grey>, <black>, <black>}}
{sand {<brown>, <light_grey>, <dark_grey>, <black>}}
{water {<blue>, <dark_grey>, <black>, <black>}}
}
Every time a tile is drawn, check the light level, and set the corresponding palette color accordingly. This doesn't have to happen every tick, though. The map only changes during certain scenarios: when the map is first drawn, to account for initial light sources; when the ball is hit, to account for the ball lighting up the course; when the player uses their flashlight. When these events happen, the map tiles can be updated. Otherwise, everything is set in memory, and no changes need to be made, just draw what's there.
Update: This kind of works! Except, it's palette swapping, not palette replacing. What I actually want is to replace the palette colors. Notably, I fixed my map call to only draw the map being shown on the display. This, in turn, made the callback function actually performant when changing memory values. Because I can read values, I can easily read the values from the palette that I need, and then apply them when necessary. Instead of programming everything, I can just read it and save it.
local light_grey = peek4(mem)
Repeat for everything.
Update: this also works, kind of. The tiles use whatever the current values of the palette are. Thus, I think the way to handle this is two-fold. First, leverage both vbanks. vbank(0) will be the map. The palette will reflect this. vbank(1) will be everything else. I think for events, the pause screen, etc.. I can leverage the additional memory banks. However, I can also just draw the stuff without having to rely on the various "helper" functions. Putting the events into their own memory banks might allow me to do some cool pixel art though.
Lighting as an overlay makes sense in this game. Anywhere there's light, it will display the full-color. Anywhere there isn't light, it will be grey-scale. Light = vbank(1); Grey = vbank(0)