2D explosions gen

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

Jan_

Ehemaliger Admin

Betreff: 2D explosions gen

BeitragFr, Jul 30, 2004 11:27
Antworten mit Zitat
Benutzer-Profile anzeigen
hier wieder mal was aus meiner persönlichen functionen Sammlung

Erstellt Explosionen mit meiner eigenen Formel.

Hier der Beispielcode:
BlitzBasic: [AUSKLAPPEN]
Graphics 640,480,32,2
Include "Explosions_Partikel_Engine_2D.bb"
Bank=CreateBank (8)

;Explosion 1 erstellen
CreateExplosion(200,200,3,Bank)
Image=PeekInt (Bank, 0)
Frames=PeekInt (Bank, 4)

CreatePixel(200,200,3,5000,255,0,0,0,0,0,0,20,10)
DrawExplosion(IMaGe,200,200)
DeleteTypes()

CreatePixel(200,200,3,500,255,200,0,0,0,0,0,5,6)
DrawExplosion(IMaGe,200,200)
DeleteTypes()

MaskImage Image,0,0,0

;Explosion 2 erstellen
image2=CreateExplosion(200,200,2,Bank)
Frames2=PeekInt (Bank, 4)

CreatePixel(200,200,2,5000,255,100,255,0,0,0)
DrawExplosion(IMaGe2,200,200)
DeleteTypes()

CreatePixel(200,200,2,5000,255,0,255,50,0,50,1.75,0,0)
DrawExplosion(IMaGe2,200,200)
DeleteTypes()

MaskImage Image2,0,0,0

;Explosion 3 erstellen
image3=CreateExplosion(200,200,1,Bank)
Image3=PeekInt (Bank, 0)
Frames3=PeekInt (Bank, 4)

; CreatePixel(200,200,1,2500,255,255,0,255,0,0,0.25,1,1)
CreatePixel(200,200,1,2500,255,255,0,255,0,0,0.25,2,1)
DrawExplosion(IMaGe3,200,200)
DeleteTypes()

MaskImage Image3,0,0,0

;Explosion 4 erstellen
CreateExplosion(200,200,0.5,Bank)
Image4=PeekInt (Bank, 0)
Frames4=PeekInt (Bank, 4)

CreatePixel(200,200,0.5,2500,255,255,255,0,55,0,0.25,5,1)
DrawExplosion(IMaGe4,200,200)
DeleteTypes()

MaskImage Image4,0,0,0

SetBuffer BackBuffer()
I = 0
G = 0
J = 0
K = 0
Repeat
Cls

DrawImage IMaGe, 0,20,I
Text 0,0,"Frame: " + I
I=I+1
If i > frames-1 Then i=0

DrawImage IMaGe2, 220,20,G
Text 220,0,"Frame: " + G
G=G+1
If G > frames2-1 Then G=0

DrawImage IMaGe3, 0,240,J
Text 0,220,"Frame: " + J
J=J+1
If J > frames3-1 Then J=0

DrawImage IMaGe4, 300,240,K
Text 300,220,"Frame: " + K
K=K+1
If K > frames4-1 Then K=0

Flip
Until KeyHit(1)


und hier die Lib:

Explosions_Partikel_Engine_2D.bb
BlitzBasic: [AUSKLAPPEN]
Global Partikel_MaxTime
SeedRnd MilliSecs()
Type Partikel
Field activ
Field x#
Field y#
Field Speed#
Field Grad#
Field Aktuelle_Color_R#
Field Aktuelle_Color_G#
Field Aktuelle_Color_B#
Field Change_Color_R#
Field Change_Color_G#
Field Change_Color_B#
Field Time
End Type

Function CreatePixel(MaxX,MaxY,Speed#,Anzahl,StartColorR,StartColorG,StartColorB,EndColorR,EndColorG,EndColorB,Start#=0,Form=0,FormAbschwachung#=5)
Local X2,Y2
Local I,G
Local Ungenau#

X2=MaxX/2 : Y2=MaxY/2
G = Rand(0,360)

For i = 0 To Anzahl
Pixel.Partikel = New Partikel
Pixel\Grad# = Rnd#(0,360)
If Form = 0 Then
Ungenau = 1
Else
Ungenau#=(Sin((Pixel\Grad#+G)*Form)+FormAbschwachung#)/(FormAbschwachung#+1.0)
End If
Pixel\Speed# = Rnd#(Start#,Speed# * 1)*Ungenau
Pixel\Activ = 1
Pixel\X# = X2
Pixel\Y# = Y2
Pixel\Aktuelle_Color_R = StartColorR
Pixel\Aktuelle_Color_G = StartColorG
Pixel\Aktuelle_Color_B = StartColorB
Pixel\Change_Color_R# = Float#(((EndColorR*4+Rand(0,255))/5) - StartColorR)/Float#(Partikel_MaxTime)
Pixel\Change_Color_G# = Float#(((EndColorG*4+Rand(0,255))/5) - StartColorG)/Float#(Partikel_MaxTime)
Pixel\Change_Color_B# = Float#(((EndColorB*4+Rand(0,255))/5) - StartColorB)/Float#(Partikel_MaxTime)
Pixel\Time = 0
Next

End Function

Function CreateExplosion(MaxX,MaxY,Speed#,Bank)
Local X2, Y2
Local Image
Local MaxTime

X2=MaxX/2 : Y2=MaxY/2
MaxTime = ((X2+Y2)/2)/Speed#
PokeInt Bank, 4, MaxTime

Image = CreateImage(MaxX,MaxY,MaxTime)
PokeInt Bank, 0, Image
Partikel_MaxTime=MaxTime
Return Image

End Function

Function DrawExplosion(Partikel_Image,MaxX,MaxY,Divi#=1)
Local RGB
Local FR,FG,FB
Local I,G
Local X,Y
G=0
DebugLog Partikel_MaxTime
For G = 0 To Partikel_MaxTime -1
For Pixel.Partikel = Each Partikel
If Pixel\Activ = 1 Then
; UnlockBuffer ImageBuffer(Partikel_Image,Pixel\Time)
SetBuffer ImageBuffer(Partikel_Image,Pixel\Time)
; LockBuffer ImageBuffer(Partikel_Image,Pixel\Time)
FR = Floor(Pixel\Aktuelle_Color_R)-10 : FG = Floor(Pixel\Aktuelle_Color_G)-10 : FB = Floor(Pixel\Aktuelle_Color_B)-10
If FR < 0 Then FR = 0
If FG < 0 Then FG = 0
If FB < 0 Then FB = 0
RGB = FR*$10000 + FG*$100 + FB
WritePixel Int(Pixel\X# + ((Sin#(Pixel\Grad#)*Pixel\Speed#)/Divi#)),Int(Pixel\Y# + ((Cos#(Pixel\Grad#)*Pixel\Speed#)/Divi#)),RGB
FR = Floor(Pixel\Aktuelle_Color_R)-5 : FG = Floor(Pixel\Aktuelle_Color_G)-5 : FB = Floor(Pixel\Aktuelle_Color_B)-5
If FR < 0 Then FR = 0
If FG < 0 Then FG = 0
If FB < 0 Then FB = 0
RGB = FR*$10000 + FG*$100 + FB
WritePixel Int(Pixel\X#),Int(Pixel\Y#),RGB
Pixel\Aktuelle_Color_R# = Pixel\Aktuelle_Color_R# + Pixel\Change_Color_R#
Pixel\Aktuelle_Color_G# = Pixel\Aktuelle_Color_G# + Pixel\Change_Color_G#
Pixel\Aktuelle_Color_B# = Pixel\Aktuelle_Color_B# + Pixel\Change_Color_B#
If Pixel\Aktuelle_Color_R# < 0 Then Pixel\Aktuelle_Color_R# = 0
If Pixel\Aktuelle_Color_G# < 0 Then Pixel\Aktuelle_Color_G# = 0
If Pixel\Aktuelle_Color_B# < 0 Then Pixel\Aktuelle_Color_B# = 0
Pixel\X# = Pixel\X# + ((Sin#(Pixel\Grad#)*Pixel\Speed#)/Divi#)
Pixel\Y# = Pixel\Y# + ((Cos#(Pixel\Grad#)*Pixel\Speed#)/Divi#)
RGB = Floor(Pixel\Aktuelle_Color_R)*$10000 + Floor(Pixel\Aktuelle_Color_G)*$100 + Floor(Pixel\Aktuelle_Color_B)
WritePixel Int(Pixel\X#),Int(Pixel\Y#),RGB
If Pixel\Time> Partikel_MaxTime -1 Then
Pixel\Activ = 0
End If
Pixel\Time = Pixel\Time + 1
End If
Next
Next

End Function

Function DeleteTypes()
For Pixel.Partikel = Each Partikel
Delete Pixel.Partikel
Next
End Function
between angels and insects

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group