How can I draw a circle of light around the hero?
A simple circle of light around the hero can be drawn using slices, as seen in House Escape.
See Callahat's Local Light Plotscripting article in HamsterSpeak for a much more advanced tile-based effect where the light is limited by walls, and there are other light sources.
Using slices instead of tiles lets the circle of light stay centered on the hero instead of moving a tile at a time.
If you want to use slices, and your hero is always in the middle of the screen, then this is very easy:
- paint a 320x200 overlay in an external program. Make sure that the center part is colour 0, transparent
- import it as a backdrop
- adapt this script:
global variable (1, flashlight circle) plotscript, setup flashlight, begin #change '3' to the backdrop ID flashlight circle := load backdrop sprite (3) end
And you can get rid of the effect later with "free slice (flashlight circle)". There are many other things you can do, if you understand how to use slices.
On the other hand, if you have a map set to 'Crop', then you need to continually keep the circle of light centered.
- in addition to the above, import a backdrop which is totally black (but not transparent)
- adapt these scripts
global variable (1, flashlight circle)
plotscript, setup flashlight, begin
if (slice is valid (flashlight circle)) then (exit script)
flashlight circle := create container
# Move this container above all map layers, but below anything else
move slice above (flashlight circle, last child (lookup slice (sl:map root)))
variable (sl)
### change '3' to the backdrop ID
sl := load backdrop sprite (3)
set parent (sl, flashlight circle)
put slice (sl, -160, -100)
# Create a 3x3 grid of black backdrops
variable (x, y)
for (x, -1, 1) do (
for (y, -1, 1) do (
# Don't place the centre piece
if (x == 0 && y == 0) then (continue)
### change '4' to the ID of the blank backdrop
sl := load backdrop sprite (4)
set parent (sl, flashlight circle)
put slice (sl, -160 + 320 * x, -100 + 200 * y)
)
)
end
plotscript, flashlight circle of light, begin
setup flashlight
### Change this from 'true' to some other condition like "current map == 4 || current map == 5"
### or "check tag(tag:in darkness)"
while (true) do (
# Keep moving above all other map slices, because the order could change when
# the map changes
if (flashlight circle <> last child (parent slice (flashlight circle))) then (
move slice above (flashlight circle, last child (lookup slice (sl:map root)))
)
# Because the slice is parented to the maproot its
# position is in map coordinates
put slice (flashlight circle, hero pixel x, hero pixel y)
wait
)
free slice (flashlight circle)
flashlight circle := 0
end
Then set "flashlight circle of light" as the map autorun script on affected maps or other suitable trigger. Change the "while (true)" as needed to cause the script to exit!