News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Fireworks effects

Started by Crystal Noir, February 24, 2010, 08:46:15 AM

Previous topic - Next topic

Crystal Noir

Hi All :)

I'm trying again Playbasic with the 1.64 version for now. This is my real first try.

Here's a sample code to make some fireworks effects, may be it looks like better with the 1.7x version I don't know ^^

I've attached the entire project in this topic, so you can test it if you want.

Here's the code (download the fireworks.zip file to have the entire project directly)

Sorry for my bad english

PlayBASIC Code: [Select]
; PROJECT : Artifice
; AUTHOR : Crystal Noir
; CREATED : 23/02/2010
; EDITED : 25/02/2010
; ---------------------------------------------------------------------
SCREENVSYNC ON

//Variables

GLOBAL Speed#
GLOBAL parax#
GLOBAL paray#
GLOBAL paraz#
GLOBAL coulr#
GLOBAL coulg#
GLOBAL coulb#
GLOBAL Angle1#
GLOBAL Angle2#

GLOBAL switch = 0
GLOBAL NbFeu = 400
GLOBAL Temps = 0



//Types

TYPE FeuArtifice
image
x#
y#
z#
vy#
xd#
yd#
zd#
r#
g#
b#
Life
size#
alpha#
ENDTYPE

DIM Pouf AS FeuArtifice LIST

//Sprite
LOADFXIMAGE "feu.png",1
IMAGEMASKCOLOUR 1,RGB(0,0,0)

// Boucle principale
REPEAT
CLS RGB(0,0,0)
IF Temps = 0
parax# = RND(200) - 100
paray# = RND(200) - 100
paraz# = 200

coulr# = RND(255)
coulg# = RND(255)
coulb# = RND(255)

IF swith = 0
Temps = 100
ENDIF

FOR i = 1 TO NbFeu
NewFeu()
NEXT
ENDIF

FOR EACH Pouf()
AfficheFeu()
NEXT
DRAWALLSPRITES
Temps = Temps - 1
SYNC

UNTIL ESCKEY() = 1

//Sub & Functions
PSUB NewFeu()
Pouf = NEW FeuArtifice
Pouf.size# = rnd#(0.10)
Pouf.image = NEWSPRITE(-50,-50,1)
SPRITEDRAWMODE Pouf.image,02+16+64
//SPRITEALPHAADDCOLOUR Pouf.image,RGB(coulr#,coulg#,255)
Angle1# = RND(360)
Angle2# = RND(360)
Speed# = 0.1

Pouf.x# = parax#
Pouf.y# = paray#
Pouf.z# = paraz#
Pouf.r# = coulr#
Pouf.g# = coulg#
Pouf.b# = coulb#

Pouf.xd# = COS(Angle1#) * COS(Angle2#) * Speed#
Pouf.yd# = COS(Angle1#) * SIN(Angle2#) * Speed#
Pouf.zd# = SIN(Angle1#) * Speed#
Pouf.Life = 150
Pouf.alpha# = 1
ENDPSUB

PSUB AfficheFeu()
mapos = GETLISTPOS(Pouf())
IF Pouf.Life > 0
IF Pouf.size# > 0
Pouf.size# = Pouf.size# - 0.0010
ENDIF
Pouf.x# = Pouf.x# + Pouf.xd# * 10.0
Pouf.y# = Pouf.y# + Pouf.yd# * 10.0
Pouf.z# = Pouf.z# + Pouf.zd# * 10.0
Pouf.y# = Pouf.y# + Pouf.vy#
Pouf.vy# = Pouf.vy# + 0.02
Pouf.alpha# = Pouf.alpha# - 0.008

posx# = (800/2) + ((Pouf.x# / Pouf.z#) * 500)
posy# = (600/2) + ((Pouf.y# / Pouf.z#) * 500)

Pouf.Life = Pouf.Life - 1
SCALESPRITEXY Pouf.image,Pouf.size#,Pouf.size#
SPRITETINT Pouf.image,RGB(Pouf.r#,Pouf.g#,Pouf.b#)
spritefadelevel Pouf.image,Pouf.alpha#
POSITIONSPRITE Pouf.image,posx#,posy#
ELSE
DELETESPRITE Pouf.image
FREECELL Pouf(),mapos
ENDIF
ENDPSUB



ATLUS

Very good!!
Thanks for code!!!!

Crystal Noir

Thx :)

I've updated it. Now I use the 1.64 version and the effect is better with the combination of alpha add and fade ^^

monkeybot


OldNESJunkie

Yes, this is very nice looking. I'm surprised I overlooked this somehow before.

kevin

#5
  Fireworks Effects Tweaked

    Here's a version that's been tweaked up in order correct a few mistakes, namely with trying to use additive sprites directly to video memory (See Crash course in Image & Sprites Draw Modes).   Another issue if scaling down an over sized image.   Here I've made it a 1/4 of the original size,  MipMaps would be a better solution though.   The real time tint could be removed by creating a custom version of the particle image (pre-coloured) for each set of the particles.  Which would get rid of the  multiples per pixel.    

 
Download
 
   Download Fireworks V1.64 Fixed

 

OldNESJunkie

OK, I am going to have the read the help file in it's entirety before beginning my new project or I think I'm gonna get into trouble :^(