Plasma Fireworks

Community Forums/Graphic Chat/Plasma Fireworks

Ked(Posted 2007) [#1]
I have been particle-happy recently and made this little snippet. I must say that I'm quite happy with myself. Would do you all think?

FLARE.PNG


GLOW.PNG


If you like the code and/or images then you may have them but please credit me in any form of the releases.

CODE (BLITZ3D)
screenwidth=640
screenheight=480

Graphics3D screenwidth,screenheight,32,2
SetBuffer BackBuffer()

Global flaresprite=LoadSprite("flare.png",1):HideEntity flaresprite
Global halfwidth=screenwidth/2,halfheight=screenheight/2
Global glowsprite=LoadSprite("glow.png",1):HideEntity glowsprite

Global camera=CreateCamera()
Global light=CreateLight()

Type flare
	Field x,y
	Field angle#
	Field speed#
	Field alpha#
	Field src
End Type

Type glow
	Field x,y
	Field alpha#
	Field src
End Type

While Not KeyHit(1)
	RenderWorld:Flip:UpdateWorld
	
	If KeyHit(57)
		x=Rand(100,screenwidth-100)
		y=Rand(100,screenheight-100)
		CreateGlow(x,y)
		For i=1 To 30
			CreateExplosion(x,y)
		Next
	EndIf
	
	UpdateGlow()
	UpdateExplosion()
Wend
End

Function CreateGlow(x,y)
	g.glow=New glow
	g\x=x
	g\y=y
	g\alpha=1.0
	g\src=CopyEntity(glowsprite)
	ScaleSprite g\src,200/2,200/2
End Function

Function UpdateGlow()
	For g.glow=Each glow
		g\alpha=g\alpha-0.05
		
		If g\alpha > 0
			PositionEntity g\src,halfwidth-g\x,g\y-halfheight,halfwidth*1
			EntityAlpha g\src,g\alpha
		Else
			FreeEntity g\src
			Delete g
		EndIf
	Next
End Function

Function CreateExplosion(x,y)
	f.flare=New flare
	f\x=x
	f\y=y
	f\angle=Rand(360)
	f\speed=Rand(3,7)
	f\alpha=1.0
	f\src=CopyEntity(flaresprite)
	RotateSprite f\src,f\angle
	ScaleSprite f\src,50/2,50/2
End Function

Function UpdateExplosion()
	For f.flare=Each flare
		
		If f\alpha>0
			f\x=f\x+Sin(f\angle)*f\speed
			f\y=f\y+Cos(f\angle)*f\speed
			If f\angle > 180
				f\angle=f\angle-0.5
			ElseIf f\angle < 180
				f\angle=f\angle+0.5
			EndIf
			f\alpha=f\alpha-0.01
			PositionEntity f\src,halfwidth-f\x,f\y-halfheight,halfwidth*1
			EntityAlpha f\src,f\alpha
			RotateSprite f\src,f\angle
		Else
			FreeEntity f\src
			Delete f
		EndIf
	
	Next
End Function



Nathaniel(Posted 2007) [#2]
Looks nice!

Next time indicate that it's bb code. Code doesn't work for me--even after I editted the code to load "png" images instead of "bmp."


Ked(Posted 2007) [#3]
Sorry. ImageShack converted my images to PNG and forgot to change it in the source. I don't understand what you mean when you say indicate that it's bb code.


Nathaniel(Posted 2007) [#4]
Blitz3D (or BlitzPlus) files won't work with BlitzMax. It's good practice to warn Max users before they absent-mindedly copy and paste the code into the IDE.


Ked(Posted 2007) [#5]
I completely forgot about BlitzMax. I will put a note at the top.


Yo! Wazzup?(Posted 2007) [#6]
I'm using Blitz3d and all I see is a black screen.


Canardian(Posted 2007) [#7]
Press the space key. And again. And again! Having fun yet?


Yo! Wazzup?(Posted 2007) [#8]
With these kinds of things I always like changing KeyHit to KeyDown and holding down the key.


Ked(Posted 2007) [#9]
With these kinds of things I always like changing KeyHit to KeyDown and holding down the key.

Thats a fun way of having to reboot your computer due to a jam up. :P

[brag]
But not with my computer!!!!
[/brag]


Loktar(Posted 2007) [#10]
I did the exact same thing in a screensaver a few years back. Looks nice.

Also whos computer reboots nowadays to holding a key down?


DheDarkhCustard(Posted 2008) [#11]
make sure you use binary friendly dimensions for images such as 16 32 128 256 etc or some computers won't load the images properly.

I rand the program with blitz3d and it said that the images didn't exist. So I then changed thm to 64x64 and 256x256 in Photoshop (Used the Image Size option), and they worked.

Keep this in mind for future development.


DheDarkhCustard(Posted 2008) [#12]
Oh the fireworks were splendid too by the way.

A cool thing to think about, avoid fading off white, white is used as the brightest colour, in this case blue is the intense colour so as it lessens, it should instead go blue rather than gray. (watch the flare carefully)

you could have a white flare and a blue one and shrink the white one first then the blue can fade. This is annoying though because you'll have to load 2 separate entities which both need to be taken care of in terms of loading and freeing etc.

keep up the flare work thought you are on the right track.