February 27, 2021, 04:22:32 AM

Author Topic: [bb] Fireworks by Ross C [ 1+ years ago ]  (Read 417 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Fireworks by Ross C [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Fireworks
Author : Ross C
Posted : 1+ years ago

Description : This code will shoot a firework in the air then explode it. Not much, but someone might find it useful i hope :o)

Code :
Code: BlitzBasic
  1. Graphics 800,600
  2. SetBuffer BackBuffer()
  3.  
  4.  
  5. Type shot
  6.         Field x#,y#
  7.         Field speed#
  8.         Field distance
  9.         Field travelled#
  10.         Field cr,cg,cb
  11. End Type
  12.  
  13. Type particle
  14.         Field x#,y#
  15.         Field angle#
  16.         Field speed#
  17.         Field time
  18.         Field timer
  19. End Type
  20.  
  21.  
  22. While Not KeyHit(1)
  23.         Cls
  24.                                                                 ;     x             y           speed      distance
  25.         If KeyHit(2) Then fire_shot(Rnd(10,700) , Rnd(200,600) , Rnd(0.5,3) , Rnd(50,180))
  26.        
  27.        
  28.         update_shots()
  29.         update_particles()
  30.         Flip
  31. Wend
  32. End
  33.  
  34.  
  35. Function fire_shot(x#,y#,speed#,distance#)
  36.         s.shot=New shot
  37.         sx                      = x
  38.         sy                      = y
  39.         sspeed          = speed
  40.         sdistance       = sy-distance
  41.         scr             = Rand(100,255)
  42.         scg             = Rand(100,155)
  43.         scb             = Rand(10,100)
  44.  
  45. End Function
  46.  
  47. Function update_shots()
  48.         For s.shot=Each shot
  49.                 sy=sy-sspeed ; move shot
  50.                 Color scr,scg,scb ; set color
  51.                 Rect sx,sy,2,2; draw particle
  52.                
  53.                 If sy<sdistance Then
  54.                         trnd=Rand(1,6); number of Rings of particles the shot will produce (min,max)
  55.                         For mloop=1 To trnd; loop for the number of rings of particles the shot will produce (min,max)
  56.                                 speed#=Rnd(0.2,2); rnd speed for each ring of particles
  57.                                 incr#=Rnd(10,70); angle/spacing between each particle
  58.                                 For loop=0 To incr; loop thru each particle in the loop, and create
  59.                                         create_new_particle(sx,sy,Rnd(speed*0.8,speed*1.2),loop*(360/incr))
  60.                                 Next
  61.                         Next
  62.                         Delete s.shot
  63.                 End If
  64.                
  65.         Next
  66. End Function
  67.  
  68. Function create_new_particle(x#,y#,speed#,angle)
  69.         p.particle=New particle
  70.         px=x
  71.         py=y
  72.         pspeed=speed
  73.         pangle=angle
  74.         p       imer=MilliSecs()
  75.         p       ime=Rand(500,2000)
  76. End Function
  77.  
  78. Function update_particles()
  79.         For p.particle=Each particle
  80.                 px=px+Cos(pangle)*pspeed ; move particle
  81.                 py=py+Sin(pangle)*pspeed ; move particle
  82.                 temp=Rand(100,255) ; random red color
  83.                 temp1=Rand(10,temp) ; random green colour, based on the result of the random red colour
  84.                 Color temp,temp1,Rand(10,190) ; set colour
  85.                 Rect px,py,Rand(1,4),Rand(1,4) ; set colour
  86.                 If MilliSecs()>p        imer+p  ime Then
  87.                         Delete p.particle
  88.                 End If
  89.         Next
  90. End Function


Comments :


Agamer(Posted 1+ years ago)

 I love it, well you know I used it for some game I was making nothing much but interesting!


big10p(Posted 1+ years ago)

 Ooooooh! Ahhhhhhh! :)


Subirenihil(Posted 1+ years ago)

 Interesting...However, I have a program that does far better effects.  Mine is designed for use within other programs, so you have me beat there.Try Fireworks II.


DheDarkhCustard(Posted 1+ years ago)

 nifty!someone could use it in a high scores screen.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal