Particledemo

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Particledemo

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Rings.

Code: Select all

; ParticleDemo Effect in PureBasic
; by S.Rings(-CodeGuru-) in 2002
;----------------------------------------------

#scrw = 800
#scrh = 600
#scrd = 32

Structure Particle
  X.f
  Y.f
  velocity.f
  speed.f
  xoff.f
  color.l
  heat.f
EndStructure

Num=1000;count of particles
Dim Part.Particle(Num)

Gravity.f=0.65
strength.f=5

For i = 1 To num
  Gosub ParticleInit
Next i
;-------- Init all needed Stuff --------
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageBox_ (0,"Can't open DirectX 7 or later", "-Codeguru-", #MB_ICONINFORMATION|#MB_OK)
  End
EndIf
If OpenScreen(#scrw,#scrh,#scrd,"ParticleDemo by -CodeGuru-") = 0 
  MessageBox_ (0,"Could not open  screen", "ParticleDemo by -CodeGuru-", #MB_ICONINFORMATION|#MB_OK)
  End                                                                                     
EndIf

SetFrameRate(60)     

;-------- MainLoop --------
Repeat
  ClearScreen(RGB(0,0,0))
  
  ExamineMouse()
  musx = MouseX()
  musy = MouseY()
  If StartDrawing(ScreenOutput())                   
  
    Gosub ParticleMove
    For i = 1 To num
      x = Part(i)\X
      y = Part(i)\Y
      If x >= 0 And y >= 0 And x < #scrw And y < #scrh
        Plot(x, y, Part(i)\color)
      EndIf
    Next i
    
    DrawingMode(1)
    DrawText(#scrw/2-100,#scrh/2, "ParticleDemo by -CodeGuru-", RGB(100,100,255))
    
    StopDrawing() 
  EndIf
  
  FlipBuffers()
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End

ParticleInit:
  Part(i)\Y = musy;#scrh/2
  Part(i)\X = musx;#scrw/2
  Part(i)\xoff = Random(100)/100 * -strength + Random(100)/100 * strength
  Part(i)\velocity = 0.5
  Part(i)\speed = Random(100)/100 * 15
  t=Random(55)
  Part(i)\color = RGB(200+t,200+t,200+t)
Return

ParticleMove:
  For i = 1 To num
    Part(i)\speed = (Part(i)\speed + Part(i)\velocity) - gravity
    Part(i)\Y = (Part(i)\Y - Part(i)\speed)
    Part(i)\X = Part(i)\X + Part(i)\xoff
    Part(i)\heat = Part(i)\heat + 3
    If Part(i)\Y > #scrh Or Part(i)\X > #scrw
      Gosub ParticleInit:
    EndIf
  Next i
Return
Its a long way to the top if you wanna .....CodeGuru
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Really nice effect Rings... Seems PureBasic is going more and more for game and demo coders :wink:

greetz


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Hi Rings, nice job.
On my machine at home (WinXP) it only runs as compiled exe.
Editor -> F5 results in an error at line:

musx = WindowMouseX()

"There is no current Window"

Strange isn't it?




Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Works fine here, but with DEBUGGER OFF.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

This is a Rings code error. WindowMouseX() is intended to runs when a WINDOW is used. If it runs here, it's a luck and willn't run on other OS. When you use the fullscreen mode, use InitMouse()/ExamineMouse()/MouseX()/MouseY(). This is NOT a debugger bug. Please always enable debugger when developping.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

>If it runs here, it's a luck

Well, the DirectX-"Screen" is also a Window only.
I think thats the reason why it works.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

That's true. It's not the cas on Amiga or Linux.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

The Problem only is that i have used a (Pixel)-skeleton from MrVain to test it.
I never use MessageBox_ nor WindowMouseX in my code.But please forgive me, this is a fast 15 minutes port from VB.

Its a long way to the top if you wanna .....CodeGuru
Post Reply