GLBasic forum

Codesnippets => Code Snippets => Topic started by: aroldo on 2013-Jul-26

Title: APD Particle System in GLBasic - Explosion and Implosion
Post by: aroldo on 2013-Jul-26
GLBasic Team,

It is the time to contribute and give something back to this developer community. (GLBasic Rocks!) :nw:

First of all I have to say that I am not the best programmer as many in this forum, I have been working with GLB for over 2 years and I keep learning.

A while ago I needed a particle system to simulate an explosion in my game Brick Buster for iOS and WebOS devices.
It should work well on Android but I don't have the devices to test therefore I did not launch it in the Goggle Play market.
(Any volunteers to test it are welcome  :enc:)

There are two attachments, a picture of the test program and the entire GLB Project!!!

The Test Program

When you run the test program you will see the fireworks and a menu with 5 choices.
Just hover the mouse over the option you want and click to increase or change the value of the particle system.
The test program allows you to control the particle system variables as follows:
Particles - this controls the number of particles in the system, from 64 to 1024.
Life - The duration of each particle, from 0.5 to 10.5.
Mode - Explode the particles or Implode the particles.
Dot Size - Is the size of each particle. from 1 to 5
The test program simulates fireworks on the screen and you can turn on and turn off the sound.
Sound -Turns the sound on and off
Bonus
I also included in the test program the following functions:
Mouse control
Text formatting and mouse hover, both will automatically adjust to any screen size.

Using the Particle System
In your program you first call the allocParticle() to instanciate the particle system.
Then you call drawparticles() to draw then in the particle array object.
Last you call moveparticles() from your update function.
The particle Type object has the following variables:
Code (glbasic) Select
TYPE  Tparticle
x=0   
y=0
sine=0
cosine=0
speed=0
life#=0.0
colors=0 //points to array of colors
ENDTYPE

This particle system has 2 features: Explode and Implode.

Gernot can you pin this post to the Code Snippets? :good:

Play with it and I hope you enjoy :D
Title: Re: APD Particle System in GLBasic - Explosion and Implosion
Post by: erico on 2013-Jul-26
Really nice Aroldo!

I will give a go on the test code on android later on and report back here.
Tks for sharing! :good:
Title: Re: APD Particle System in GLBasic - Explosion and Implosion
Post by: erico on 2013-Jul-26
Gave a try on the testcode on PC.

Tried long 10.5 life, biggest particle size and implode.
On some occasions(~1 out of 10), one particle stays static on screen and won´t move like the rest.

edit: I also notice this dosen´t happen on explode, only on implode.

Title: Re: APD Particle System in GLBasic - Explosion and Implosion
Post by: aroldo on 2013-Jul-26
Enrico,

I noticed that too. I will have to debug it to understand which one pixel is not moving.
Other than that it is a nice little particle system.

Regarding he android test thank you for doing that. :nw: I will send you the BrickBuster compile for android.

Can I send it to your e-mail?
What kind of Android devices you have?
BrickBuster should work on screen sizer from 320x480 to 1536x2048.
Title: Re: APD Particle System in GLBasic - Explosion and Implosion
Post by: erico on 2013-Jul-26
Enrrrricoooo Suaaaaveee!! :D :D

It sure is a nice particle system, and the code seems like it is not too complicated to use by your instructions! That is really nice.

I will give a go later today on the test for android.
I would need to finish up some ongoing things before.

You can send anything for test to my ericomont(googlething).

I have a galaxy note II. It runs 1280x720.
Cheers, thanks again for the contribution and instructions!
Title: Re: APD Particle System in GLBasic - Explosion and Implosion
Post by: bigsofty on 2013-Jul-27
Particle systems are always fun, thanks Aroldo!  :good: