added a test for the particle engine

This commit is contained in:
Ziver Koc 2007-03-25 20:48:23 +00:00
parent e3f5017007
commit d3a6c31dd1
4 changed files with 419 additions and 18 deletions

View file

@ -7,10 +7,6 @@ package ei.engine.effects;
* Visit Our Sites At www.tiptup.com and nehe.gamedev.net
*/
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

View file

@ -30,13 +30,14 @@ import ei.engine.texture.TextureLoader;
*
*/
public class Particles extends Entity{
public int maxParticles = 1000;
public boolean regenerate = true;
public boolean enabled = true;
public boolean rainbow = true; // Rainbow Mode?
public float slowdown = 1.0f; // Slow Down Particles
public float xspeed = 00; // Base X Speed (To Allow Keyboard Direction Of Tail)
public float yspeed = 000; // Base Y Speed (To Allow Keyboard Direction Of Tail)
public float xspeed = 0.0f; // Base X Speed (To Allow Keyboard Direction Of Tail)
public float yspeed = 0.0f; // Base Y Speed (To Allow Keyboard Direction Of Tail)
public float MaxSpeedX = 500; // The Max Random Speed On X Axis
public float MaxSpeedY = 500; // The Max Random Speed On Y Axis
@ -56,7 +57,6 @@ public class Particles extends Entity{
{0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f}
};
private final int MAX_PARTICLES = 1000;
private Particle particle[];
private int col; // Current Color Selection
private int delay; // Rainbow Effect Delay
@ -74,9 +74,9 @@ public class Particles extends Entity{
*
*/
public void reset(){
particle = new Particle[MAX_PARTICLES];
particle = new Particle[maxParticles];
for(int i=0;i<MAX_PARTICLES;i++) {
for(int i=0;i<maxParticles;i++) {
particle[i] = new Particle();
particle[i].life = -1.0f;
}
@ -94,13 +94,13 @@ public class Particles extends Entity{
}
private void init() {
for (int i=0;i<MAX_PARTICLES;i++){ // Initials All The Textures
for (int i=0;i<maxParticles;i++){ // Initials All The Textures
particle[i].active = true; // Make All The Particles Active
particle[i].life = life; // Give All The Particles Full Life
particle[i].fade = ((float)(Math.random() * 100.0)) / 1000.0f + 0.003f; // Random Fade Speed
particle[i].r = colors[i * (colors.length / MAX_PARTICLES)][0]; // Select Red Rainbow Color
particle[i].g = colors[i * (colors.length / MAX_PARTICLES)][1]; // Select Red Rainbow Color
particle[i].b = colors[i * (colors.length / MAX_PARTICLES)][2]; // Select Red Rainbow Color
particle[i].r = colors[i * (colors.length / maxParticles)][0]; // Select Red Rainbow Color
particle[i].g = colors[i * (colors.length / maxParticles)][1]; // Select Red Rainbow Color
particle[i].b = colors[i * (colors.length / maxParticles)][2]; // Select Red Rainbow Color
particle[i].xi = ((float)((Math.random() * MaxSpeedX)) - (MaxSpeedX/2)) * 10.0f; // Random Speed On X Axis
particle[i].yi = ((float)((Math.random() * MaxSpeedY)) - (MaxSpeedY/2)) * 10.0f; // Random Speed On Y Axis
particle[i].zi = ((float)((Math.random() * MaxSpeedZ)) - (MaxSpeedZ/2)) * 10.0f; // Random Speed On Z Axis
@ -116,10 +116,10 @@ public class Particles extends Entity{
MaxSpeedZ = 500;
pullForceX = 0.0f;
pullForceY = -0.8f;
pullForceY = 0.0f;
pullForceZ = 0.0f;
life = 6.0f;
life = 1.0f;
size = 20.0f;
//regenerate = false;
@ -135,7 +135,7 @@ public class Particles extends Entity{
texture.bindGL();
for(int i=0;i<MAX_PARTICLES;i++) { // Loop Through All The Particles
for(int i=0;i<maxParticles;i++) { // Loop Through All The Particles
if (particle[i].active) { // If The Particle Is Active
float x = particle[i].x; // Grab Our Particle X Position
float y = particle[i].y; // Grab Our Particle Y Position
@ -179,8 +179,8 @@ public class Particles extends Entity{
particle[i].y = getLocation().getY(); // Center On Y Axis
particle[i].z = getZ(); // Center On Z Axis
particle[i].xi = ((float)((Math.random() * MaxSpeedX)) - (MaxSpeedX/2)) * 10.0f; // X Axis Speed And Direction
particle[i].yi = ((float)((Math.random() * MaxSpeedY)) - (MaxSpeedY/2)) * 10.0f; // Y Axis Speed And Direction
particle[i].xi = xspeed + ((float)((Math.random() * MaxSpeedX)) - (MaxSpeedX/2)) * 10.0f; // X Axis Speed And Direction
particle[i].yi = yspeed + ((float)((Math.random() * MaxSpeedY)) - (MaxSpeedY/2)) * 10.0f; // Y Axis Speed And Direction
particle[i].zi = ((float)((Math.random() * MaxSpeedZ)) - (MaxSpeedZ/2)) * 10.0f; // Z Axis Speed And Direction
particle[i].r = colors[col][0]; // Select Red From Color Table