Re: Efektit
Posted: Wed Sep 17, 2008 4:59 pm
Syksyn pimeyteen hidas ilotulitus-efekti, klikkaamalla räjähdys
Code: Select all
Const SW = 800
Const SH = 600
Const MAX_PARTS_PER_EXPLOSION = 300
SCREEN SW,SH,0,0
Type raketti
Field x#
Field y#
Field sx#
Field sy#
Field r#
Field g#
Field b#
Field gs#
Field m
Field id As Integer
End Type
Type explosion
Field count As Short
End Type
Const GRAVITY = 0.02
PositionMouse SW/2,SH/2
Repeat
PutPixel MouseX(),MouseY(),16777215
If MouseHit(1) Then MakeExplosion()
UpdateAll()
Color 255,255,255
Text 0,0,FPS()
DrawScreen
Forever
Function UpdateAll()
Lock
For iR.raketti = Each raketti
tmp.explosion = ConvertToType(iR\id)
iR\x = iR\x + iR\sx
iR\y = iR\y + iR\sy+iR\gs
iR\gs=iR\gs+GRAVITY*(1.0-0.2*(iR\m=0))
iR\sx = iR\sx + (Abs(iR\sx)>=0.4) * -Sgn(iR\sx) * (0.3+0.1*(iR\m=0))
iR\sx = iR\sx + (Abs(iR\sx)<0.4) * -Sgn(iR\sx) * 0.001
iR\sy = iR\sy + (Abs(iR\sy)>=0.4) * -Sgn(iR\sy) * (0.3+0.1*(iR\m=0))
iR\sy = iR\sy + (Abs(iR\sy)<0.4) * -Sgn(iR\sy) * 0.001
If iR\m = 0 Then PutPixel iR\x,iR\y,Int(iR\r Shl 16 +iR\g Shl 8+iR\b)
If tmp\count<MAX_PARTS_PER_EXPLOSION And Rand(10)=0 And (iR\r>150 Or iR\g>150 Or iR\b>150) Then
PoE(iR\id,iR\x,iR\y,0,0,Max(0,iR\r-30),Max(0,iR\g-30),Max(0,iR\b-30),0,Rnd(0,0.5))
tmp\count = tmp\count + 1
EndIf
iR\r=Max(0,iR\r-1)
iR\g=Max(0,iR\g-1)
iR\b=Max(0,iR\b-1)
If iR\y > SH Or (iR\r<20 And iR\g<20 And iR\b<20) Then
Delete iR
tmp\count = tmp\count - 1
EndIf
Next iR
Unlock
For iR.raketti = Each raketti
If iR\m = 1 Then
Color iR\r,iR\g,iR\b
Line iR\x,iR\y,iR\x-iR\sx/2,iR\y-iR\sY/2
Color Max(0,iR\r-70),Max(0,iR\g-70),Max(0,iR\b-70)
Line iR\x-iR\sx/2,iR\y-iR\sY/2,iR\x-iR\sx,iR\y-iR\sY
EndIf
Next iR
Color cbwhite
If tmp<>NULL Then Text 0,15,tmp\count
End Function
Function Sgn(luku#)
Return (luku>0)-(luku<0)
End Function
Function MakeExplosion()
n.explosion=New(explosion)
mx#=MouseX()
my#=MouseY()
c=20
fact#=360.0/c
For a = 0 To c-1
r=Rand(220,255)
g=Rand(0,200)
b=Rand(200,240)
PoE(ConvertToInteger(n),mx,my,Cos((a+Rnd(-1,1)) * fact) * 8.0,Sin((a+Rnd(-1,1)) * fact) * 8.0,r,g,b,1)
Next a
End Function
Function PoE(_id As Integer,x#,y#,sx#,sy#,r,g,b,m,gs#=0)
tmp.explosion=ConvertToType(_id)
If tmp\count>MAX_PARTS_PER_EXPLOSION Then Return False
tmp\count = tmp\count + 1
n.raketti = New(raketti)
n\x=x
n\y=y
n\sx=sx
n\sy=sy
n\r=r
n\g=g
n\b=b
n\m=m
n\gs=gs
n\id=_id
Return ConvertToInteger(n)
End Function