It is currently Tue May 23, 2017 9:44 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Kaboom(x,y) - explosion animation
Unread postPosted: Sat May 13, 2017 3:22 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 437
Here is a fun little explosion animation that I used in my Planet Mook game.
Just call kaboom(x,y) with the coordinates of where you want an explosion.
As an exercise, you might like to make the shape of the burst circular instead of square using trig functions.
As another exercise, you could make it so that you can run multiple explosions at the same time maybe by using ONTIMER and some bundles.

Code:
REM Start of BASIC! Program
gr.open 255,0,0,0

fn.def kaboom(x,y)
gr.screen w,h
gr.set.stroke 3
n=100
dim vx[n],vy[n],p[n],x[n],y[n]
for i=1 to n
vx[i]=rnd()*10-5
vy[i]=rnd()*10-5
x[i]=x
y[i]=y
if mod(i,1)=0 then gr.color 255,255,0,0
if mod(i,2)=0 then gr.color 255,0,255,0
if mod(i,3)=0 then gr.color 255,0,0,255
gr.point p[i],x,y
gr.show p[i]
next
gr.render
tmax=50
for t=1 to tmax
for i=1 to n
x[i]+=vx[i]
y[i]+=vy[i]
gr.modify p[i],"x",x[i],"y",y[i]
gr.modify p[i],"alpha",floor(255-t*(254/tmax))
next
gr.render
next
for i=1 to n
gr.hide p[i]
next
gr.render

fn.end

gr.screen w,h
do
kaboom(rnd()*w,rnd()*h)
until quit
exit

ongrtouch:
quit=1
Gr.onGrTouch.resume



Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred