prog8/examples/vm/bouncegfx.p8
2022-07-03 00:41:04 +02:00

60 lines
1.6 KiB
Lua

%import textio
%zeropage basicsafe
; NOTE: meant to test to virtual machine output target (use -target virtual)
main {
sub start() {
word[128] particleX
word[128] particleY
byte[128] particleDX
byte[128] particleDY
ubyte pi
for pi in 0 to 127 {
particleX[pi] = rndw() % 319 as word
particleY[pi] = rndw() % 240 as word
particleDX[pi] = (rnd() & 1)*2 as byte - 1
particleDY[pi] = (rnd() & 1)*2 as byte - 1
}
sys.gfx_enable(0) ; enable lo res screen
repeat {
fade()
plot_particles()
sys.waitvsync()
}
sub fade() {
uword xx
uword yy
for yy in 0 to 239 {
for xx in 0 to 319 {
ubyte pixel = sys.gfx_getpixel(xx, yy)
if pixel>4
pixel-=4
sys.gfx_plot(xx, yy, pixel)
}
}
}
sub plot_particles() {
for pi in 0 to 127 {
particleX[pi] += particleDX[pi]
particleY[pi] += particleDY[pi]
if particleX[pi]<0 or particleX[pi]>319 {
particleDX[pi] *= -1
particleX[pi] += particleDX[pi] * 2
}
if particleY[pi]<0 or particleY[pi]>239 {
particleDY[pi] *= -1
particleY[pi] += particleDY[pi] * 2
}
sys.gfx_plot(particleX[pi] as uword, particleY[pi] as uword, 255)
}
}
}
}