December 04, 2020, 11:22:41 AM

Author Topic: [bb] Simple particle engine by Andres [ 1+ years ago ]  (Read 604 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Simple particle engine by Andres [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Simple particle engine
Author : Andres
Posted : 1+ years ago

Description : image% - either singleframed or multiframed image handle
x#, y# - location of the particle
xs#, ys# - velocity of the particle
duration% - duration of the particle in millisecs
frames% - if does then how many frames particle has (default: 1 frame)
Global Inerts# - Will be multiplied with velocity in every update


Code :
Code: BlitzBasic
  1. Type particle
  2.         Field image%, x#, y#, xs#, ys#, w%, h%, time%, duration%, frames%
  3. End Type
  4.  
  5. Global Inerts# = .9
  6.  
  7. Function CreateParticle(image%, x#, y#, xs#, ys#, duration%, frames% = 1)
  8.         this.particle = New particle
  9.                 thisimage% = CopyImage(image%)
  10.                 thisx# = x#
  11.                 thisy# = y#
  12.                 thisxs# = xs#
  13.                 thisys# = ys#
  14.                 thisw% = ImageWidth(thisimage%)
  15.                 thish% = ImageHeight(thisimage%)
  16.                 this    ime% = MilliSecs()
  17.                 thisduration% = duration%
  18.                 thisframes% = frames%
  19. End Function
  20.  
  21. Function DrawParticles()
  22.         For par.particle = Each particle
  23.                 If parframes% = 1
  24.                         DrawImage parimage%, parx% - parw% / 2, pary% - parh% / 2
  25.                 Else
  26.                         frame% = (parframes% - 1) * (Float (MilliSecs() - par   ime%) / parduration%)
  27.                         If frame% > parframes% Then frame% = parframes%
  28.                         DrawImage parimage%, parx% - parw% / 2, pary% - parh% / 2, frame%
  29.                 EndIf
  30.         Next
  31. End Function
  32.  
  33. Function UpdateParticles()
  34.         For par.particle = Each particle
  35.                 If MilliSecs() - par    ime% < parduration% Then
  36.                         parx# = parx# + parxs#
  37.                         pary# = pary# + parys#
  38.                        
  39.                         parxs# = parxs# * Inerts#
  40.                         parys# = parys# * Inerts#
  41.                 Else
  42.                         FreeImage parimage%
  43.                         Delete par
  44.                 EndIf
  45.         Next
  46. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal