2D Partikel Engine

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

coolo

Betreff: 2D Partikel Engine

BeitragSo, Aug 31, 2008 19:00
Antworten mit Zitat
Benutzer-Profile anzeigen
Eine 2D Partikel Engine.
Beispiele liegen bei, Ansonsten Selbsterklärend.

Download: https://www.blitzforum.de/upload/file.php?id=3355
Code: [AUSKLAPPEN]

;Partikel Engine 5.9.1
;Credits: Robert Fischer (Coolo)
;Eine sehr sehr schnelle 2D Partikel engine!!!
;Sie kann bis zu 10 000 Partikel ohne Ruckeln "rendern"
SeedRnd MilliSecs()

Const vers$="0.9.1"
Const CallFunc=0 ;Soll eine funktion gerufen werden beim updaten

;TEMPLATE VARIABLEN
Type template
   Field img ; das Bild
   Field image[9] ; die 9 Bilder die zur Auswahl stahen
   Field minspeedx#,maxspeedx# ;min und max speed der x Koordinaten
   Field maxspeedy#,minspeedy# ;min und max speed der y koordinbaten
   Field snow ; Schnee Effekt
   Field maxangle#,minangle# ;Max und min wert des Winkels
   Field minaspeed#,maxaspeed# ; Geschwindigkeit
   Field maxr,maxg,maxb ;r g b Werte minimum
   Field minr,ming,minb ; r g b  Werte Maximum
   Field maxlive,minlive ;Min und maximale Lebensdauer
   Field transparent ; Transparent
End Type
Global temp.template
;PARTIKEL VARIABLEN
Type particle
   Field x#,y# ;x,y position
   Field dazux#,dazuy# ;wie viel pro aufruf dazugerechnet wird
   Field img ;das Bild
   Field image ;das 2. Bild
   Field angle# ;der Winkel
   Field aspeed# ;die Winkelgeschwindigkeit
   Field snow ;schnee effekt
   Field maxlive ;wie lange esmaximal lebt
   Field live ;wie lange es schon gelebt hat
   Field bildw,bildh ;die breiteund höhe des Bildes
   Field transparent ;Ob es transparent ist
   Field father ;von welchem template es stammt
   Field mother ; von welchem emitter es stammt
End Type
Global par.particle
Global Partikel
;EMITTER VARIABLEN
Type emitter
   Field x,y
   Field w,he,h;h=Haandle, w=breite, he=height
   Field a;anzahl der partikel, die pro schleifenaufruf erzeugt werden
   Field stopped ;ob er läuft oder nicht
End Type
Global em.emitter
Global emitter
;sonstiges
Global height=GraphicsHeight()
Global width=GraphicsWidth()
Global endheight=height
Global endwidth=width
Global startx=1,starty=1


Function count_all()
   For par=Each particle
      i=i+1
   Next
   For em=Each emitter
      i=i+1
   Next
   For temp=Each template
      i=i+1
   Next
   Return i
End Function

Function get_emitterreturn(h)
   em.emitter=Object.emitter(h)
   If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
   Return em\h
End Function

Function count_particle(h=0,emit=0)
   If h<>0
      temp.template=Object.template(h)
      If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   EndIf
   If emit<>0
      em.emitter=Object.emitter(emit)
      If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
   EndIf
   For par=Each particle
      If (par\father=h Or h=0) And (par\mother=emit Or emit=0) Then i=i+1
   Next
   Return i
End Function

Function init_particleengine(eheight=0,ewidth=0,startxx=0,startyy=0)
   height=GraphicsHeight()
   width=GraphicsWidth()
   endheight=eheight
   endwidth=ewidth
   If startxx<>0 And startyy<>0
      startx=startxx
      starty=startyy
   Else
      startx=height
      starty=width
   EndIf
End Function

Function delete_particleengine()
   Delete Each emitter
   Delete Each template
   Delete Each particle
   height=GraphicsHeight()
   width=GraphicsWidth()
   endheight=height
   endwidth=width
   startx=1
   starty=1
   Partikel=0
   emitter=0
End Function


Function set_viewport(x,y,w,h)
   startx=x
   starty=y
   endheight=h
   endwidth=w
End Function

Function get_version()
   Return vers$
End Function

Function check_all_collision(img,x,y,temp=0,frame=0)
   For par=Each particle
      If par\father=temp Or temp=0
         If frame=0
            If ImagesOverlap(img,x,y,par\img,par\x,par\y) Then Return 1 Else Return 0
         Else
            If ImagesCollide(img,x,y,frame,par\img,par\x,par\y,0) Then Return 1 Else Return 0
         EndIf
      EndIf
   Next
End Function

Function check_collision(h,img,x,y,frame=0)
   par.particle=Object.particle(h)
   If ImagesCollide(par\img,par\x,par\y,0,img,x,y,frame) Then Return 1 Else Return 0 ;Or ImagesCollide(par\image,par\x,par\y,0,img,x,y,frame)
End Function

Function get_template()
   For temp=Each template
      i=i+1
   Next
   Return i
End Function

Function get_emitter()
   Return emitter
End Function

Function get_Particle()
   Return Partikel
End Function

Function get_state(h)
   em.emitter=Object.emitter(h)
   If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
   Return em\stopped
End Function

Function state_emitter(h)
   em.emitter=Object.emitter(h)
   If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
   If em\stopped Then em\stopped=0 Else em\stopped=1
End Function

Function delete_each(h)
   For par=Each particle
      If h=par\father Then Delete par.particle:Partikel=Partikel-1
   Next
End Function

Function delete_particle(h)
   par.particle=Object.particle(h)
   If par.particle=Null Then RuntimeError "Das angegebene Partikel existiert nicht!"
   Partikel=Partikel-1
   Delete par.particle
End Function

Function delete_emitter(h)
   em.emitter=Object.emitter(h)
   If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
   emitter=emitter-1
   Delete em.emitter
End Function


Function delete_template(h)
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   Delete temp.template
End Function

Function set_emitter(h,par,x,y,w,he,a)
   em.emitter=Object.emitter(h)
   If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
   em\x=x
   em\y=y
   em\w=w
   em\he=he
   em\h=par
   em\a=a
End Function

Function create_emitter(h,x,y,w,he,a)
   em.emitter=New emitter
   em\x=x
   em\y=y
   em\h=h
   em\w=w
   em\he=he
   em\a=a
   emitter=emitter+1
   Return Handle(em)
End Function

Function update_emitter()
   For em=Each emitter
      If em\stopped=0
         For i=0 To em\a
            create_particle(em\h,Rand(em\x,em\x+em\w),Rand(em\y,em\y+em\he))
            par\mother=Handle(em)
         Next
      EndIf
   Next
End Function

Function update_Particle(emitt=1)
   
   If emitt=1
      For em=Each emitter
         If em\stopped=0
            For i=0 To em\a
               create_particle(em\h,Rand(em\x,em\x+em\w),Rand(em\y,em\y+em\he))
               par\mother=Handle(em)
            Next
         EndIf
      Next
   EndIf
   For par=Each particle
      If par\x>startx And par\y>starty And par\x<endwidth+startx And par\y<endheight+starty; Or startx=0 And starty=0 And endwidth=0 And endheight=0
         If par\image=0
            If par\transparent=0
               DrawImage par\img,par\x,par\y
            Else
               DrawBlock par\img,par\x,par\y
            EndIf
         Else
            If par\transparent=0
               DrawImage par\image,par\x,par\y
            Else
               DrawBlock par\image,par\x,par\y
            EndIf
         EndIf
      EndIf
      If par\angle<>0 Or par\aspeed<>0
         par\x=par\x+par\dazux+Cos(par\angle#)*par\aspeed
         par\y=par\y+par\dazuy+Sin(par\angle#)*-par\aspeed
      Else
         par\x=par\x+par\dazux
         par\y=par\y+par\dazuy
      EndIf
      par\live=par\live+1
      If par\snow<0 Then par\x=par\x-Rand(par\snow,Abs(par\snow))
      If snow>0 Then snow=-snow
      If par\x<-par\bildw Or par\x>width+par\bildw Or par\y<-par\bildw Or par\y>height+par\bildh Or par\live=par\maxlive Then
         Delete par.particle
         Partikel=Partikel-1
      EndIf
      If CallFunc=1
         update_func()
      EndIf
   Next
End Function

Function create_particle(h,x#,y#)
   par.particle=New particle
   par\x#=x#
   par\y#=y#
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   par\dazux=Rnd(temp\minspeedx,temp\maxspeedx)
   par\dazuy=Rnd(temp\minspeedy,temp\maxspeedy)
   par\maxlive=Rand(temp\minlive,temp\maxlive)
   par\angle#=Rnd(temp\minangle,temp\maxangle)
   par\aspeed=Rnd(temp\minaspeed,temp\maxaspeed)
   par\snow=temp\snow
   par\father=Handle(temp)
   If temp\image[0]<>0
      For i=0 To 9
         If temp\image[i]=0 And i>0 Then
            par\image=temp\image[Rand(0,i)]
         EndIf
      Next
   EndIf
   
   If temp\img=0
      If temp\maxr>255 Or temp\minr<0 Or temp\maxg>255 Or temp\ming<0 Or temp\minb<0 Or temp\maxb>255 Then RuntimeError "Die angegebenen rgb werte sind ungültig."
      temp\img=CreateImage(1,1)
      SetBuffer ImageBuffer(temp\img)
      Color Rand(temp\minr,temp\maxr),Rand(temp\ming,temp\maxg),Rand(temp\minb,temp\maxb)
      Plot 0,0
      SetBuffer BackBuffer()
      par\transparent=1
   Else
      par\transparent=temp\transparent
   EndIf
   par\img=temp\img
   par\bildw=ImageWidth(par\img)
   par\bildh=ImageHeight(par\img)
   Partikel=Partikel+1
   Return
End Function

Function create_template()
   temp=New template
   temp\transparent=1
   Return Handle(temp)
End Function

Function set_image(h,img,image0=0,image1=0,image2=0,image3=0,image4=0,image5=0,image6=0,image7=0,image8=0,image9=0)
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   temp\img=img
   temp\image[0]=image0
   temp\image[1]=image1
   temp\image[2]=image2
   temp\image[3]=image3
   temp\image[4]=image4
   temp\image[5]=image5
   temp\image[6]=image6
   temp\image[7]=image7
   temp\image[8]=image8
   temp\image[9]=image9
End Function

Function set_transparent(h,transparent)
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   temp\transparent=transparent
End Function

Function set_rgb(h,minr,ming,minb,maxr,maxg,maxb)
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   temp\maxr=minr
   temp\maxg=ming
   temp\maxb=minb
   temp\minr=maxr
   temp\ming=maxg
   temp\minb=maxb
End Function

Function set_live(h,minlive,maxlive)
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   temp\minlive=minlive
   temp\maxlive=maxlive
End Function

Function set_angle(h,minangle,maxangle,minaspeed,maxaspeed)
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   temp\minangle=minangle
   temp\maxangle=maxangle
   temp\minaspeed=minaspeed
   temp\maxaspeed=maxaspeed
End Function

Function set_snow(h,snow)
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   temp\snow=snow
End Function

Function set_speedxy(h,minspeedx,maxspeedx,minspeedy,maxspeedy)
   temp.template=Object.template(h)
   If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
   temp\minspeedx=minspeedx
   temp\maxspeedx=maxspeedx
   temp\minspeedy=minspeedy
   temp\maxspeedy=maxspeedy
End Function

Function update_func()
   RuntimeError "Bitte überschreiben Sie diese Funktion"
End Function


Function create_snow_template()
   temp.template=New template
   temp\minspeedx=0
   temp\maxspeedx=0
   temp\minspeedy=1
   temp\maxspeedy=5
   temp\snow=-1
   temp\maxangle=0
   temp\minangle=0
   temp\minaspeed=0
   temp\maxaspeed=0
   temp\maxr=255
   temp\maxg=0
   temp\maxb=0
   temp\minr=200
   temp\ming=0
   temp\minb=0
   temp\minlive=1
   temp\maxlive=180
   temp\img=LoadImage("partikel/snow.png")
   Return Handle(temp)
End Function

Function create_fire_template()
   temp.template=New template
   temp\maxangle=0
   temp\minangle=0
   temp\minaspeed=0
   temp\maxaspeed=0
   temp\minspeedx=-2
   temp\maxspeedx=2
   temp\minspeedy=-1
   temp\maxspeedy=-4
   temp\snow=0
   temp\maxr=255
   temp\maxg=0
   temp\maxb=0
   temp\minr=200
   temp\ming=0
   temp\minb=0
   temp\minlive=1
   temp\maxlive=100
   temp\img=LoadImage("partikel/fire.png")
   temp\transparent=1
   Return Handle(temp)
End Function

Function create_glut_template()
   temp.template=New template
   temp\maxangle=0
   temp\minangle=0
   temp\minaspeed=0
   temp\maxaspeed=0
   temp\minspeedx=-2
   temp\maxspeedx=2
   temp\minspeedy=-1
   temp\maxspeedy=-4
   temp\snow=0
   temp\maxr=255
   temp\maxg=0
   temp\maxb=0
   temp\minr=200
   temp\ming=0
   temp\minb=0
   temp\minlive=1
   temp\maxlive=50
   temp\img=LoadImage("partikel/glut.png")
   temp\transparent=1
   Return Handle(temp)
End Function

Function create_rain_template()
   temp.template=New template
   temp\minspeedx=0
   temp\maxspeedx=0
   temp\minspeedy=1
   temp\maxspeedy=5
   temp\snow=0
   temp\maxangle=0
   temp\minangle=0
   temp\minaspeed=0
   temp\maxaspeed=0
   temp\maxr=255
   temp\maxg=0
   temp\maxb=0
   temp\minr=200
   temp\ming=0
   temp\minb=0
   temp\minlive=0
   temp\maxlive=0
   temp\img=LoadImage("partikel/water.png")
   Return Handle(temp)
End Function

Function create_explosion_template()
   temp.template=New template
   temp\minspeedx=0
   temp\maxspeedx=0
   temp\minspeedy=0
   temp\maxspeedy=0
   temp\snow=0
   temp\maxangle=0
   temp\minangle=360
   temp\minaspeed=1
   temp\maxaspeed=5
   temp\maxr=255
   temp\maxg=0
   temp\maxb=0
   temp\minr=200
   temp\ming=0
   temp\minb=0
   temp\minlive=0
   temp\maxlive=100
   temp\img=LoadImage("partikel/stone.png")
   Return Handle(temp)
End Function


Todo:
Manual schreiben
Tutorials schreiben
Animierte Partikel
http://programming-with-design.at/ <-- Der Preis ist heiß!
That's no bug, that's my project!
"Eigenzitate sind nur was für Deppen" -Eigenzitat
  • Zuletzt bearbeitet von coolo am Sa, Jan 10, 2009 16:48, insgesamt einmal bearbeitet

ToeB

BeitragSo, Aug 31, 2008 19:26
Antworten mit Zitat
Benutzer-Profile anzeigen
[Ähem] Sieht gut aus, aber was ist daran so besonders ? [/Ähem]


mfg ToeB
Religiöse Kriege sind Streitigkeiten erwachsener Männer darum, wer den besten imaginären Freund hat.
Race-Project - Das Rennspiel der etwas anderen Art
SimpleUDP3.0 - Neuste Version der Netzwerk-Bibliothek
Vielen Dank an dieser Stelle nochmal an Pummelie, welcher mir einen Teil seines VServers für das Betreiben meines Masterservers zur verfügung stellt!
 

da_poller

BeitragSo, Aug 31, 2008 19:42
Antworten mit Zitat
Benutzer-Profile anzeigen
Zitat:
;Sie kann bis zu 10 000 Partikel ohne Ruckeln "rendern"


10.000 partikel: 100ms framezeit..

und das bei nem 64bit quad core?

sorry dachte nciht das das so ruckelt aber herbe schnell ist die nicht.. wobei ich selber noch nie mich an sowas gewagt habe .. jedoch nur mal meine kritik...

coolo

BeitragSo, Aug 31, 2008 19:50
Antworten mit Zitat
Benutzer-Profile anzeigen
Das war natürlich etwas gelogen Smile aber 2000-3000 schafft sie schon.

Aber die 10 000 Waren mein Ziel, aber dieses Ziel kann ich nur dann erreichen, wenn ich von Type's auf Array's umsteige.
http://programming-with-design.at/ <-- Der Preis ist heiß!
That's no bug, that's my project!
"Eigenzitate sind nur was für Deppen" -Eigenzitat
 

da_poller

BeitragSo, Aug 31, 2008 20:11
Antworten mit Zitat
Benutzer-Profile anzeigen
lügen? sry aber spar dir lügen sonst nimmt dich bald keiner mehr für voll so wie ich..

ich kaufe auch keinen karton mit 10 eiern wo dann nur 4 drin sind...

ist eig (da du es ja wusstest) schlichtweg betrug!

coolo

BeitragMo, Sep 01, 2008 12:02
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich hab je nicht geschrieben 10 000, es steht halt im Quellcode, ich kanns gerne ändern, aber als Betrug würde ich das nicht nennen. Schaut euch doch mal diese "Fachzeitschriften" an, da steht 10000 Musikstücke zum downloaden, was zeigen die dann, irgend sonen RadioStream Aufnehmer. Als ich diese Partikel Engine geschrieben habe, hatte ich nur nen EeePc übrig, und auf dem lief es bei 1500 Partikel flüssig, da dachte ich auf nen Quad Duo läufts mit 10 000, hab mich also ein bisschen verschätzt.

Ausserdem, wen juckts, ob ich 10 000 oder 3000 schreibe ist es eh egal.
http://programming-with-design.at/ <-- Der Preis ist heiß!
That's no bug, that's my project!
"Eigenzitate sind nur was für Deppen" -Eigenzitat
  • Zuletzt bearbeitet von coolo am Mo, Sep 01, 2008 17:13, insgesamt einmal bearbeitet
 

Speed><Coder

BeitragMo, Sep 01, 2008 13:23
Antworten mit Zitat
Benutzer-Profile anzeigen
Genau^^ aber gut ausgedachteer Code

Du hast meinen RESPECT, Alter xD

achja, bei mir hat er bei 5200 aufgehört zu zählen^^ Aber es lief trotzdem weiter^^
(Also es schwankte dannn immer zwischen 4800 und 5200)
World of Warcraft Süchtlinge:
1.Süchtling:"Ey leutz ich heut was von n 'Reallife' gehört."
2.Süchtling:"Was is das???
3.Süchtling:"LINK????"

coolo

BeitragMo, Sep 01, 2008 14:26
Antworten mit Zitat
Benutzer-Profile anzeigen
Danke Speed<>Coder, das hört man gerne!

Ausserdem, habe ich schon angeangen ein paar Tutorials zu schreiben. Es ist schon einer fertig gestellt. Es wird erklärt wie man einen Schneeeffekt schreibt.
http://programming-with-design.at/ <-- Der Preis ist heiß!
That's no bug, that's my project!
"Eigenzitate sind nur was für Deppen" -Eigenzitat
 

MLi-media.de | laurenz

Betreff: 10000 Partikel sind möglich

BeitragMo, Sep 01, 2008 22:12
Antworten mit Zitat
Benutzer-Profile anzeigen
Hmm weiß ja nicht ob ich vlt was falsch mache Embarassed

aber bei mir läuft noch alles flüssig bei 10000 Partikeln (Intel E6600 auf 2,7ghz)
täusch ich mich oder würde ein Quad nicht so viel mehr Leisten da ja ehh nur 2 Kerne genutzt werden ?!?!

aber mir gefällt das Engine gut Smile


Habe ihn meinen PC noch ein wenig mehr geärgert und bin vorerst mal auf das Limit von 25000 Partikeln gestoßen ... teste morgen mal weiter Wink
 

Speed><Coder

BeitragMo, Sep 01, 2008 22:18
Antworten mit Zitat
Benutzer-Profile anzeigen
Idea Kann ich bitte mal dein 1. Tut anguggn? BÜDDÖ!!
^^
*Wissenshungrig*

Muss ma wissn wie sowas geht^^

thx im Vorraus
Fallst du aber nicht wilst, dann auch gut Smile
World of Warcraft Süchtlinge:
1.Süchtling:"Ey leutz ich heut was von n 'Reallife' gehört."
2.Süchtling:"Was is das???
3.Süchtling:"LINK????"

coolo

BeitragSo, Sep 28, 2008 11:15
Antworten mit Zitat
Benutzer-Profile anzeigen
Neue Version:

Code: [AUSKLAPPEN]

;Partikel Engine 0.9.5
;Credits: Robert Fischer (Coolo)
;Eine sehr sehr schnelle 2D Partikel engine!!!
;Sie kann bis zu 10 000 Partikel ohne Ruckeln "rendern"
SeedRnd MilliSecs()

Const vers$="0.9.1"
Const CallFunc=0 ;Soll eine funktion gerufen werden beim updaten

;TEMPLATE VARIABLEN
Type template
Field img ; das Bild
Field image[9] ; die 9 Bilder die zur Auswahl stahen
Field minspeedx#,maxspeedx# ;min und max speed der x Koordinaten
Field maxspeedy#,minspeedy# ;min und max speed der y koordinbaten
Field snow ; Schnee Effekt
Field maxangle#,minangle# ;Max und min wert des Winkels
Field minaspeed#,maxaspeed# ; Geschwindigkeit
Field maxr,maxg,maxb ;r g b Werte minimum
Field minr,ming,minb ; r g b  Werte Maximum
Field maxlive,minlive ;Min und maximale Lebensdauer
Field transparent ; Transparent
End Type
Global temp.template
;PARTIKEL VARIABLEN
Type particle
Field x#,y# ;x,y position
Field dazux#,dazuy# ;wie viel pro aufruf dazugerechnet wird
Field img ;das Bild
Field image ;das 2. Bild
Field angle# ;der Winkel
Field aspeed# ;die Winkelgeschwindigkeit
Field snow ;schnee effekt
Field maxlive ;wie lange esmaximal lebt
Field live ;wie lange es schon gelebt hat
Field bildw,bildh ;die breiteund höhe des Bildes
Field transparent ;Ob es transparent ist
Field father ;von welchem template es stammt
Field mother ; von welchem emitter es stammt
End Type
Global par.particle
Global Partikel
;EMITTER VARIABLEN
Type emitter
Field x,y
Field w,he,h;h=Haandle, w=breite, he=height
Field a;anzahl der partikel, die pro schleifenaufruf erzeugt werden
Field stopped ;ob er läuft oder nicht
End Type
Global em.emitter
Global emitter
;sonstiges
Global height=GraphicsHeight()
Global width=GraphicsWidth()
Global endheight=height
Global endwidth=width
Global startx=1,starty=1


Function count_all()
For par=Each particle
i=i+1
Next
For em=Each emitter
i=i+1
Next
For temp=Each template
i=i+1
Next
Return i
End Function

Function get_emitterreturn(h)
em.emitter=Object.emitter(h)
If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
Return em\h
End Function

Function count_particle(h=0,emit=0)
If h<>0
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
EndIf
If emit<>0
em.emitter=Object.emitter(emit)
If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
EndIf
For par=Each particle
If (par\father=h Or h=0) And (par\mother=emit Or emit=0) Then i=i+1
Next
Return i
End Function

Function init_particleengine(eheight=0,ewidth=0,startxx=0,startyy=0)
height=GraphicsHeight()
width=GraphicsWidth()
End Function

Function delete_particleengine()
Delete Each emitter
Delete Each template
Delete Each particle
height=GraphicsHeight()
width=GraphicsWidth()
endheight=height
endwidth=width
startx=1
starty=1
Partikel=0
emitter=0
End Function


Function set_viewport(x,y,w,h)
startx=x
starty=y
endheight=h
endwidth=w
End Function

Function get_version()
Return vers$
End Function

Function check_all_collision(img,x,y,temp=0,frame=0)
For par=Each particle
If par\father=temp Or temp=0
If frame=0
If ImagesOverlap(img,x,y,par\img,par\x,par\y) Then Return 1 Else Return 0
Else
If ImagesCollide(img,x,y,frame,par\img,par\x,par\y,0) Then Return 1 Else Return 0
EndIf
EndIf
Next
End Function

Function check_collision(h,img,x,y,frame=0)
par.particle=Object.particle(h)
If ImagesCollide(par\img,par\x,par\y,0,img,x,y,frame) Then Return 1 Else Return 0 ;Or ImagesCollide(par\image,par\x,par\y,0,img,x,y,frame)
End Function

Function get_template()
For temp=Each template
i=i+1
Next
Return i
End Function

Function get_emitter()
Return emitter
End Function

Function get_Particle()
Return Partikel
End Function

Function get_state(h)
em.emitter=Object.emitter(h)
If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
Return em\stopped
End Function

Function state_emitter(h)
em.emitter=Object.emitter(h)
If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
If em\stopped Then em\stopped=0 Else em\stopped=1
End Function

Function delete_each(h)
For par=Each particle
If h=par\father Then Delete par.particle:Partikel=Partikel-1
Next
End Function

Function delete_particle(h)
par.particle=Object.particle(h)
If par.particle=Null Then RuntimeError "Das angegebene Partikel existiert nicht!"
Partikel=Partikel-1
Delete par.particle
End Function

Function delete_emitter(h)
em.emitter=Object.emitter(h)
If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
emitter=emitter-1
Delete em.emitter
End Function


Function delete_template(h)
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
Delete temp.template
End Function

Function set_emitter(h,par,x,y,w,he,a)
em.emitter=Object.emitter(h)
If em.emitter=Null Then RuntimeError "Der angegebene Emitter existiert nicht!"
em\x=x
em\y=y
em\w=w
em\he=he
em\h=par
em\a=a
End Function

Function create_emitter(h,x,y,w,he,a)
em.emitter=New emitter
em\x=x
em\y=y
em\h=h
em\w=w
em\he=he
em\a=a
emitter=emitter+1
Return Handle(em)
End Function

Function update_emitter()
For em=Each emitter
If em\stopped=0
For i=0 To em\a
create_particle(em\h,Rand(em\x,em\x+em\w),Rand(em\y,em\y+em\he))
par\mother=Handle(em)
Next
EndIf
Next
End Function

Function update_Particle(emitt=1)

If emitt=1
For em=Each emitter
If em\stopped=0
For i=0 To em\a
create_particle(em\h,Rand(em\x,em\x+em\w),Rand(em\y,em\y+em\he))
par\mother=Handle(em)
Next
EndIf
Next
EndIf
For par=Each particle
If par\x>startx And par\y>starty And par\x<endwidth+startx And par\y<endheight+starty; Or startx=0 And starty=0 And endwidth=0 And endheight=0
If par\image=0
If par\transparent=0
DrawImage par\img,par\x,par\y
Else
DrawBlock par\img,par\x,par\y
EndIf
Else
If par\transparent=0
DrawImage par\image,par\x,par\y
Else
DrawBlock par\image,par\x,par\y
EndIf
EndIf
EndIf
If par\angle<>0 Or par\aspeed<>0
par\x=par\x+par\dazux+Cos(par\angle#)*par\aspeed
par\y=par\y+par\dazuy+Sin(par\angle#)*-par\aspeed
Else
par\x=par\x+par\dazux
par\y=par\y+par\dazuy
EndIf
par\live=par\live+1
If par\snow<0 Then par\x=par\x-Rand(par\snow,Abs(par\snow))
If snow>0 Then snow=-snow
If par\x<-par\bildw Or par\x>width+par\bildw Or par\y<-par\bildw Or par\y>height+par\bildh Or par\live=par\maxlive Then
Delete par.particle
Partikel=Partikel-1
EndIf
If CallFunc=1
update_func()
EndIf
Next
End Function

Function create_particle(h,x#,y#)
par.particle=New particle
par\x#=x#
par\y#=y#
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
par\dazux=Rnd(temp\minspeedx,temp\maxspeedx)
par\dazuy=Rnd(temp\minspeedy,temp\maxspeedy)
par\maxlive=Rand(temp\minlive,temp\maxlive)
par\angle#=Rnd(temp\minangle,temp\maxangle)
par\aspeed=Rnd(temp\minaspeed,temp\maxaspeed)
par\snow=temp\snow
par\father=Handle(temp)
If temp\image[0]<>0
For i=0 To 9
If temp\image[i]=0 And i>0 Then
par\image=temp\image[Rand(0,i)]
EndIf
Next
EndIf

If temp\img=0
If temp\maxr>255 Or temp\minr<0 Or temp\maxg>255 Or temp\ming<0 Or temp\minb<0 Or temp\maxb>255 Then RuntimeError "Die angegebenen rgb werte sind ungültig."
temp\img=CreateImage(1,1)
SetBuffer ImageBuffer(temp\img)
Color Rand(temp\minr,temp\maxr),Rand(temp\ming,temp\maxg),Rand(temp\minb,temp\maxb)
Plot 0,0
SetBuffer BackBuffer()
par\transparent=1
Else
par\transparent=temp\transparent
EndIf
par\img=temp\img
par\bildw=ImageWidth(par\img)
par\bildh=ImageHeight(par\img)
Partikel=Partikel+1
Return
End Function

Function create_template()
temp=New template
temp\transparent=1
Return Handle(temp)
End Function

Function set_image(h,img,image0=0,image1=0,image2=0,image3=0,image4=0,image5=0,image6=0,image7=0,image8=0,image9=0)
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
temp\img=img
temp\image[0]=image0
temp\image[1]=image1
temp\image[2]=image2
temp\image[3]=image3
temp\image[4]=image4
temp\image[5]=image5
temp\image[6]=image6
temp\image[7]=image7
temp\image[8]=image8
temp\image[9]=image9
End Function

Function set_transparent(h,transparent)
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
temp\transparent=transparent
End Function

Function set_rgb(h,minr,ming,minb,maxr,maxg,maxb)
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
temp\maxr=minr
temp\maxg=ming
temp\maxb=minb
temp\minr=maxr
temp\ming=maxg
temp\minb=maxb
End Function

Function set_live(h,minlive,maxlive)
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
temp\minlive=minlive
temp\maxlive=maxlive
End Function

Function set_angle(h,minangle,maxangle,minaspeed,maxaspeed)
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
temp\minangle=minangle
temp\maxangle=maxangle
temp\minaspeed=minaspeed
temp\maxaspeed=maxaspeed
End Function

Function set_snow(h,snow)
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
temp\snow=snow
End Function

Function set_speedxy(h,minspeedx,maxspeedx,minspeedy,maxspeedy)
temp.template=Object.template(h)
If temp.template=Null Then RuntimeError "Das angegebene Template existiert nicht!"
temp\minspeedx=minspeedx
temp\maxspeedx=maxspeedx
temp\minspeedy=minspeedy
temp\maxspeedy=maxspeedy
End Function

Function update_func()
RuntimeError "Bitte überschreiben Sie diese Funktion"
End Function


Function create_snow_template()
temp.template=New template
temp\minspeedx=0
temp\maxspeedx=0
temp\minspeedy=1
temp\maxspeedy=5
temp\snow=-1
temp\maxangle=0
temp\minangle=0
temp\minaspeed=0
temp\maxaspeed=0
temp\maxr=255
temp\maxg=0
temp\maxb=0
temp\minr=200
temp\ming=0
temp\minb=0
temp\minlive=1
temp\maxlive=180
temp\img=LoadImage("partikel/snow.png")
Return Handle(temp)
End Function

Function create_fire_template()
temp.template=New template
temp\maxangle=0
temp\minangle=0
temp\minaspeed=0
temp\maxaspeed=0
temp\minspeedx=-2
temp\maxspeedx=2
temp\minspeedy=-1
temp\maxspeedy=-4
temp\snow=0
temp\maxr=255
temp\maxg=0
temp\maxb=0
temp\minr=200
temp\ming=0
temp\minb=0
temp\minlive=1
temp\maxlive=100
temp\img=LoadImage("partikel/fire.png")
temp\transparent=1
Return Handle(temp)
End Function

Function create_glut_template()
temp.template=New template
temp\maxangle=0
temp\minangle=0
temp\minaspeed=0
temp\maxaspeed=0
temp\minspeedx=-2
temp\maxspeedx=2
temp\minspeedy=-1
temp\maxspeedy=-4
temp\snow=0
temp\maxr=255
temp\maxg=0
temp\maxb=0
temp\minr=200
temp\ming=0
temp\minb=0
temp\minlive=1
temp\maxlive=50
temp\img=LoadImage("partikel/glut.png")
temp\transparent=1
Return Handle(temp)
End Function

Function create_rain_template()
temp.template=New template
temp\minspeedx=0
temp\maxspeedx=0
temp\minspeedy=1
temp\maxspeedy=5
temp\snow=0
temp\maxangle=0
temp\minangle=0
temp\minaspeed=0
temp\maxaspeed=0
temp\maxr=255
temp\maxg=0
temp\maxb=0
temp\minr=200
temp\ming=0
temp\minb=0
temp\minlive=0
temp\maxlive=0
temp\img=LoadImage("partikel/water.png")
Return Handle(temp)
End Function

Function create_explosion_template()
temp.template=New template
temp\minspeedx=0
temp\maxspeedx=0
temp\minspeedy=0
temp\maxspeedy=0
temp\snow=0
temp\maxangle=0
temp\minangle=360
temp\minaspeed=1
temp\maxaspeed=5
temp\maxr=255
temp\maxg=0
temp\maxb=0
temp\minr=200
temp\ming=0
temp\minb=0
temp\minlive=0
temp\maxlive=100
temp\img=LoadImage("partikel/stone.png")
Return Handle(temp)
End Function


Neu sind die verbesserten Kollisions und Hilfsfunktionen, und eine Viewport Funktion
http://programming-with-design.at/ <-- Der Preis ist heiß!
That's no bug, that's my project!
"Eigenzitate sind nur was für Deppen" -Eigenzitat

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group