Starting to fill out the various spell effects. Here's one I just added last night... wherever your spell hits, it begins to snow. π
Here's the code that makes that happen:
snow = []
toSpawn = 600
while toSpawn > 0 or snow
if toSpawn > 0 then
x = round(self.x / gfx.scale + rnd * 100 - 50)
y = round(self.y / gfx.scale + rnd * 100)
if gfx.pixel(x,y) == skyColor then
snow.push {"x":x, "y":y}
toSpawn = toSpawn - 1
end if
end if
if snow.len <= 0 then continue
for i in range(snow.len-1)
p = snow[i]
x = p.x + (rnd < 0.3) - (rnd < 0.3)
y = p.y - 1
if gfx.pixel(x,y) != skyColor then
// Maybe hit something... try a bit to the left or right
if gfx.pixel(x-1,y) == skyColor then
x = x - 1
else if gfx.pixel(x+1,y) == skyColor then
x = x + 1
else
// if still can't fall, then this snowflake is done
snow.remove i
end if
else
gfx.setPixel p.x, p.y, skyColor // erase at old position
gfx.setPixel x, y, color.white // draw at new position
p.x = x
p.y = y
end if
end for
yield
end while
I was worried animating and sky-checking all these snowflakes might be too slow, but it's just fine! π