Retrogamecoding(.org) > Examples

Devilish Particles

(1/1)

Peter:
Hi,

some devilish particles for Christmas.

--- Code: ---screen(640,480,0,"Particles")
backcolor(0,0,0)
setframetimer(60)
mousehide()

function distance(x1,y1,x2,y2)
   local dx, dy
   dx=x1-x2
   dy=y1-y2
   return math.sqrt(dx*dx+dy*dy)
end

function xMove(x3,w,s)
  return x3 + cosin[w]*s
end

function yMove(y3,w,s)
  return y3 + sinus[w]*s
end

function rand(minZahl,maxZahl)
  maxZahl=(maxZahl-minZahl)
  return int(rnd()*maxZahl+minZahl)
end

anzahl,i,aSpeed,xscreen,yscreen = 1000,0,0,640,480
xmitte,ymitte,devil,p,col = 0,0,0,0,0
xmitte = xscreen/2
ymitte = yscreen/2
x={}; y={}; winkel={}; speed={}; sinus={}; cosin={}

for i=1,anzahl do
  x[i] = xmitte
  y[i] = ymitte
  speed[i] = rand(1,3)
  winkel[i]= rand(1,360)
end
for i=1,360 do
  sinus[i] = sin(math.rad(i))
  cosin[i] = cos(math.rad(i))
end

devil=loadimage("devil.png")

repeat
p=getkey()
alphachannel(255)
cls()
putimage(mousex() -32,mousey() -48,devil)
for i=1,anzahl do
   aSpeed = distance(xmitte,ymitte,x[i],y[i]) /200 * speed[i]+1
   x[i] = xMove(x[i], winkel[i], aSpeed)
   y[i] = yMove(y[i], winkel[i], aSpeed)
   if x[i] < 0 or x[i] > xscreen or y[i] < 0 or y[i] > yscreen then
      x[i] = xmitte
      y[i] = ymitte
      winkel[i]= rand(1,360)
      speed[i] = rand(1,3)
   end
   col=speed[i]*100-55
   alphachannel(100)
   color(col,col,col)
   fillellipse(x[i],y[i],4,4)
end
xmitte = mousex()
ymitte = mousey()
redraw()
until p==27
closewindow()

--- End code ---

Cybermonkey:
What about a mousehide() ?  ;)

Navigation

[0] Message Index

Go to full version