Page 1 of 1

Particle effect

Posted: Wed Dec 08, 2004 3:33 pm
by Garzul
:D Hi all .

I'm french, and my english quality is too bad :)

I create a particle effect for learning beginner .

It's a tuto particle .

Code: Select all

;/*********************************************
;/*            \\ Particle effect //          *  
;/*       \\  Crée par Garzul | 2004  //      *  
;/* \\JaPBe > 2.4.7.17 || Purebasic > 3.91 // *  
;/*********************************************  


#Largeur = 1024
#Hauteur = 768

Enumeration

  #Box
  
EndEnumeration


;* Initialisation de DirectX *;

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Erreur", "Impossible d'initialiser DirectX", 0)
  End
EndIf


;* Ouverture de la l'écran *;
OpenScreen(#Largeur,#Hauteur,32,"")

SetRefreshRate(60) 

Global NbrBox , ColorRed , ColorGreen , ColorBlue
NbrBox = 2000


Structure Box

  x.l
  y.l
  Vit.l
  
EndStructure

NewList Box1.Box()


For i = 0 To NbrBox
  
  AddElement(Box1())
  
  Box1()\x   = Random(1024) 
  Box1()\y   = Random(768)
  Box1()\Vit = 2
  
Next i



CreateSprite(#Box , 5 , 5)
StartDrawing(SpriteOutput(#Box))
Box(0 , 0 , 2 , 2 , RGB(Random(255) , Random(255) , Random(255)))
StopDrawing()


;-Afficher Effet
Procedure AffichEffect()
  
  ResetList(Box1())
  
  ForEach Box1()
    
    
    DisplayTransparentSprite(#Box , Box1()\x + Cos(Random(1000)) * #pi, Box1()\y + Sin(Random(1000)) * #Pi )
    
     
  Next
  
EndProcedure


;-Option effet
Procedure Option()


  StartDrawing(ScreenOutput())
    DrawingMode(1)
    FrontColor($C0,$C0,$C0)
    DrawText("Nombre de boite = " + Str(NbrBox))
    Locate(0 , 20)
    DrawText("Couleur RGB du fond de plan ( Rouge , Vert , Bleu ) = " + Str(ColorRed) + "," + Str( ColorGreen ) + "," + Str(ColorBlue))
    Locate(0 , 740)
    DrawText("C = Ajouter , S = Diminuer , Fléches = Déplacements , Entrer = Réinitialiser Aléatoirement , R = Plus de rouge , G = Plus de vert , B = Plus de bleu , N = Noir")
  StopDrawing()
  
  
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_C)
  
     NbrBox + 50
     
     For i = 0 To 50
     
       AddElement(Box1())
       
     Next
     
    ElseIf KeyboardPushed(#PB_Key_S)
   
     NbrBox - 50
     
     For i = 0 To 50
     
       DeleteElement(Box1()) 
     
     Next
     
   EndIf
     
     
   If KeyboardPushed(#PB_Key_Right)
   
   ForEach Box1()
   
      Box1()\X + Box1()\Vit
      
   Next
   
     ElseIf KeyboardPushed(#PB_Key_Left)
     
   ForEach Box1()
   
      Box1()\X - Box1()\Vit
      
   Next
   
     ElseIf KeyboardPushed(#PB_Key_Up)
     
   ForEach Box1()
   
      Box1()\Y - Box1()\Vit
      
   Next
     
     ElseIf KeyboardPushed(#PB_Key_Down)
     
   ForEach Box1()
   
      Box1()\Y + Box1()\Vit
      
   Next
   
   EndIf
   
   
   ForEach Box1()
   
      If Box1()\Y < 0
      
           Box1()\Y = 0
         
         ElseIf Box1()\Y > 768
         
           Box1()\Y = 768
         
         ElseIf Box1()\X < 0
         
           Box1()\X = 0
         
         ElseIf Box1()\X > 1024
         
           Box1()\X = 1024
         
      EndIf
      
   ;-réinitialiser 
   If KeyboardPushed(#PB_Key_Return)
   
      Box1()\Y = Random(768)
      Box1()\X = Random(1024)
      
   EndIf
   
   
   ;-// Changement de couleur de fond de plan \\
   If KeyboardReleased(#PB_Key_R)
   
        ColorRed   + 1
       
      ElseIf KeyboardReleased(#PB_Key_G)
      
        ColorGreen + 1
        
      ElseIf KeyboardReleased(#PB_Key_B)
      
        ColorBlue  + 1
        
      ElseIf KeyboardPushed(#PB_Key_N)

        ColorBlue  = 0
        ColorGreen = 0
        ColorRed   = 0
        
      ElseIf ColorBlue > 255 Or ColorGreen > 255 Or ColorBlue > 255
      
        ColorBlue  = 0
        ColorGreen = 0
        ColorRed   = 0
        
   EndIf  
   
   Next
   
EndProcedure
  

;// Boucle \\
Repeat

  ClearScreen(ColorRed,ColorGreen,ColorBlue)
    

    Option()
    AffichEffect()
  
  FlipBuffers()
  

;// On quitte ! :) \\
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()

^^

Posted: Mon May 09, 2005 7:40 pm
by zefiro_flashparty
nice

Posted: Wed May 11, 2005 3:01 am
by Shannara
Constant #pi missing, line 72.

Posted: Wed May 11, 2005 8:03 am
by dagcrack
#pi = 3.14159

???
Isnt PI equal on any case? :P
By the way, is the idea of this "particles example" to display dots everywhere shaking like ants? Shoudlnt particles have an emmiter for example?

Posted: Sat May 14, 2005 5:09 pm
by Shannara
Nope, thats a common FUD that some 3D guru made up to try to look cool ... no seriously :)

Particles are particles :)

Posted: Mon May 16, 2005 9:05 pm
by dagcrack
nah dude just like in real life particles must come from somewhere.. like a sand grain came from a rock! or like rain comes from the clouds! particles doesnt show up at the middle of everything with out having a source :lol:

Posted: Tue May 17, 2005 12:54 am
by Shannara
Ah, I think I know what you mean. The particles showing up instantly, anywhere.. I suppose so, but think of it this way, snow and rain shows up from the top down.. all along the top. If there was an emitter, it would be a pretty long one :)


Btw: I am not a surfer :)

Posted: Tue May 31, 2005 4:48 am
by dagcrack
Yes ... emmiters can have any size.. Did you ever work with an advanced particles engine? RealFlow from NEXTlimit for example?... even simpler engines like 3dsmax's or Cinema4D's ?.. There you will find out what im talking about.