Particle effect

Advanced game related topics
Garzul
New User
New User
Posts: 4
Joined: Mon Aug 23, 2004 1:14 pm
Location: France
Contact:

Particle effect

Post 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()
Hi and good bye :d
zefiro_flashparty
User
User
Posts: 74
Joined: Fri Mar 04, 2005 7:46 pm
Location: argentina

^^

Post by zefiro_flashparty »

nice
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Constant #pi missing, line 72.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Nope, thats a common FUD that some 3D guru made up to try to look cool ... no seriously :)

Particles are particles :)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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:
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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 :)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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.
Post Reply