diff --git a/src/ei/engine/effects/Particles.java b/src/ei/engine/effects/Particles.java index 10d41ea..e91e050 100644 --- a/src/ei/engine/effects/Particles.java +++ b/src/ei/engine/effects/Particles.java @@ -38,11 +38,10 @@ public class Particles extends Entity{ public float life = 1.0f; public float size = 20.0f; - private static float colors[][]= // Rainbow Of Colors + private static float colors[][][]= // Rainbow Of Colors { - {1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f},{0.75f,1.0f,0.5f}, - {0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f},{0.5f,0.75f,1.0f}, - {0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f} + {{1.0f,0.5f,0.5f},{1.0f,1.0f,0.5f}}, + {{1.0f,1.0f,0.5f},{1.0f,0.5f,0.5f}} }; private int maxParticles = 1000; @@ -60,8 +59,8 @@ public class Particles extends Entity{ public Particles(String name){ super(name); this.texture = TextureLoader.getTextureLoaderInstance().getTexture("data/particle.bmp"); - reset(); setDefault(); + reset(); } private void setDefault() { @@ -76,27 +75,8 @@ public class Particles extends Entity{ life = 1.0f; size = 20.0f; regenerate = true; - - init(); } - private void init() { - for (int i=0;i colors[particle[i].colorId][1][0]) + particle[i].r -= 0.2f; + if(particle[i].g > colors[particle[i].colorId][1][1]) + particle[i].g -= 0.2f; + if(particle[i].b > colors[particle[i].colorId][1][2]) + particle[i].b -= 0.2f; + + if (particle[i].life < 0.0f) { // If Particle Is Burned Out particle[i].active = true; // Make All The Particles Active particle[i].life = life; // Give It New Life @@ -195,10 +213,11 @@ public class Particles extends Entity{ 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 - particle[i].g = colors[col][1]; // Select Green From Color Table - particle[i].b = colors[col][2]; // Select Blue From Color Table - + particle[i].r = colors[col][0][0]; // Select Red From Color Table + particle[i].g = colors[col][0][1]; // Select Green From Color Table + particle[i].b = colors[col][0][2]; // Select Blue From Color Table + particle[i].colorId = col; + particle[i].xg = pullForceX; // Set Horizontal Pull To Zero particle[i].yg = pullForceY; // Set Vertical Pull Downward particle[i].zg = pullForceZ; // Set Pull On Z Axis To Zero @@ -258,6 +277,7 @@ class Particle { // Particles Structure public boolean active; // Active (Yes/No) public float life; // Particle Life public float fade; // Fade Speed + public int colorId; public float r; // Red Value public float g; // Green Value diff --git a/src/ei/engine/test/ParticlesTest.java b/src/ei/engine/test/ParticlesTest.java index 4d9eb1f..966d4d2 100644 --- a/src/ei/engine/test/ParticlesTest.java +++ b/src/ei/engine/test/ParticlesTest.java @@ -32,6 +32,10 @@ public class ParticlesTest extends LWJGLGameWindow{ protected void update() { super.update(); + if(ptf.respawn){ + p.reset(); + ptf.respawn = false; + } p.life = ptf.life.getValue(); p.MaxSpeedX = ptf.maxSpeedX.getValue(); p.MaxSpeedY = ptf.maxSpeedY.getValue(); diff --git a/src/ei/engine/test/ParticlesTestFrame.java b/src/ei/engine/test/ParticlesTestFrame.java index cd9315c..ea3ab42 100644 --- a/src/ei/engine/test/ParticlesTestFrame.java +++ b/src/ei/engine/test/ParticlesTestFrame.java @@ -7,6 +7,7 @@ import javax.swing.JCheckBox; import java.awt.FlowLayout; import javax.swing.JSlider; import javax.swing.JLabel; +import javax.swing.JButton; public class ParticlesTestFrame{ @@ -33,6 +34,8 @@ public class ParticlesTestFrame{ private JLabel jLabel4 = null; private JLabel jLabel5 = null; public JSlider size = null; + public boolean respawn = false; + private JButton jButtonRespawn = null; /** * This method initializes jFrame * @@ -41,7 +44,7 @@ public class ParticlesTestFrame{ public JFrame getJFrame() { if (jFrame == null) { jFrame = new JFrame(); - jFrame.setSize(new Dimension(281, 627)); + jFrame.setSize(new Dimension(281, 662)); jFrame.setTitle("ParticleTest"); jFrame.setContentPane(getJContentPane()); } @@ -90,6 +93,7 @@ public class ParticlesTestFrame{ jContentPane.add(getLife(), null); jContentPane.add(jLabel5, null); jContentPane.add(getSize(), null); + jContentPane.add(getJButtonRespawn(), null); } return jContentPane; } @@ -358,4 +362,22 @@ public class ParticlesTestFrame{ return size; } + /** + * This method initializes jButtonRespawn + * + * @return javax.swing.JButton + */ + private JButton getJButtonRespawn() { + if (jButtonRespawn == null) { + jButtonRespawn = new JButton(); + jButtonRespawn.setText("Force Respawn"); + jButtonRespawn.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + respawn = true; + } + }); + } + return jButtonRespawn; + } + }