Skip to content

Instantly share code, notes, and snippets.

@root42
Created December 30, 2020 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save root42/a1478d74841077c2c9043ba7b30a0850 to your computer and use it in GitHub Desktop.
Save root42/a1478d74841077c2c9043ba7b30a0850 to your computer and use it in GitHub Desktop.
Let's Code MS-DOS 0x19: Fireworks in PowerBasic
$CPU 80286
$LIB EGA ON
$ERROR ALL OFF
$OPTIMIZE SPEED
$COMPILE EXE
defint A-Z
REM =================
REM Global variables
REM =================
dim x#(256)
dim y#(256)
dim x0#(256)
dim y0#(256)
dim vx0#(256)
dim vy0#(256)
active = 1
visible = 0
frame = 1
n = 1
is_exploded = 0
t# = 1.0
dt# = 0.5
g# = 0.00981
sub vsync inline
REM while (inp(&h3da) and 8) = 1 : wend
REM while (inp(&h3da) and 8) = 0 : wend
! cli
! mov dx, &h3da
vsync1:
! in al, dx
! and al, 8
! jnz vsync1
vsync2:
! in al, dx
! and al, 8
! jz vsync2
! sti
end sub
sub init_new_rocket( x0#(1), y0#(1), vx0#(1), vy0#(1) )
x0#(0) = 120.0 + 80.0 * rnd
y0#(0) = 0
vx0#(0) = 2.0 * rnd - 1.0
vy0#(0) = 2.0 * rnd + 1.0
end sub
sub update_particles( x#(1), y#(1), x0#(1), y0#(1), vx0#(1), vy0#(1), t#, n )
shared g#
for i = 0 to n - 1
x#(i) = x0#(i) + vx0#(i) * t#
y#(i) = y0#(i) + vy0#(i) * t# - 0.5 * g# * t# * t#
next i
end sub
sub draw_particles(x#(1), y#(1), n, col)
for i = 0 to n - 1
pset (x#(i), 199 - y#(i)), col
next i
end sub
sub init_explosion(x#(1), y#(1), x0#(1), y0#(1), vx0#(1), vy0#(1), n)
x1# = x#(0)
y1# = y#(0)
for i = 0 to n - 1
v0# = 1.5 * rnd + 0.5
theta# = 6.283185 * rnd
x0#(i) = x1#
y0#(i) = y1#
vx0#(i) = v0# * cos(theta#)
vy0#(i) = v0# * sin(theta#)
next i
end sub
randomize timer
call init_new_rocket(x0#(), y0#(), vx0#(), vy0#())
REM =============
REM Main Program
REM =============
screen 7
do
call update_particles(x#(), y#(), x0#(), y0#(), vx0#(), vy0#(), t#, n)
call draw_particles(x#(), y#(), n, (frame mod 15) + 1)
if frame mod 170 = 0 then
t# = 0.0
if is_exploded = 1 then
is_exploded = 0
n = 1
call init_new_rocket(x0#(), y0#(), vx0#(), vy0#())
else
is_exploded = 1
n = 100
call init_explosion(x#(), y#(), x0#(), y0#(), vx0#(), vy0#(), n)
end if
else
t# = t# + dt#
end if
incr frame
swap active,visible
screen ,,active,visible
call vsync
cls graphics
loop until instat
screen 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment