Addded particle engine but it is not finnished yet its some configuration left
This commit is contained in:
parent
01af69cbc8
commit
7c8dba70d1
10 changed files with 577 additions and 33 deletions
10
log.txt
10
log.txt
|
|
@ -1,4 +1,6 @@
|
|||
2007-03-18 18:37:49:515 # Loading sound: data/sounds/test.wav
|
||||
2007-03-18 18:37:49:531 # Sound sources: quantity=0
|
||||
2007-03-18 18:37:49:531 # Stoping sound: source=0
|
||||
2007-03-18 18:37:49:531 # Playing sound: source=0 buffer=264767544
|
||||
2007-03-21 19:59:45:093 # Loading texture: data/units/tank.png
|
||||
2007-03-21 19:59:46:203 # Loading texture: data/particle.bmp
|
||||
2007-03-21 19:59:46:421 # Loading sound: data/sounds/test.wav
|
||||
2007-03-21 19:59:46:484 # Sound sources: quantity=0
|
||||
2007-03-21 19:59:46:484 # Stoping sound: source=0
|
||||
2007-03-21 19:59:46:484 # Playing sound: source=0 buffer=261490744
|
||||
|
|
|
|||
Binary file not shown.
BIN
src/data/particle.bmp
Normal file
BIN
src/data/particle.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
|
|
@ -61,18 +61,25 @@ public class LWJGLGameWindow {
|
|||
// Create the display window
|
||||
Display.create();
|
||||
|
||||
// enable textures since we're going to use these for our sprites
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
//Select The Projection Matrix
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
//Reset The Projection Matrix
|
||||
GL11.glLoadIdentity();
|
||||
|
||||
GL11.glOrtho(0.0f, width, height, 0, -1, 1);
|
||||
|
||||
// Select The Modelview Matrix (controls model orientation)
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glLoadIdentity();
|
||||
// disable the OpenGL depth test since we're rendering 2D graphics
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
//Enable Smooth Shading
|
||||
//GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
//Really Nice Perspective Calculations
|
||||
//GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glOrtho(0, width, height, 0, -1, 1);
|
||||
// enable textures since we're going to use these for our sprites
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
//Type Of Blending To Perform
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
|
||||
//Enable Blending
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
||||
// Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work)
|
||||
Display.setVSyncEnabled(true);
|
||||
|
|
|
|||
326
src/ei/engine/effects/CopyOfLesson19.java
Normal file
326
src/ei/engine/effects/CopyOfLesson19.java
Normal file
|
|
@ -0,0 +1,326 @@
|
|||
package ei.engine.effects;
|
||||
|
||||
/*
|
||||
* This Code Was Created By Jeff Molofee and GB Schmick 2000
|
||||
* A HUGE Thanks To Fredric Echols For Cleaning Up
|
||||
* And Optimizing The Base Code, Making It More Flexible!
|
||||
* If You've Found This Code Useful, Please Let Me Know.
|
||||
* Visit Our Sites At www.tiptup.com and nehe.gamedev.net
|
||||
*/
|
||||
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.glu.GLU;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import ei.engine.texture.Texture;
|
||||
import ei.engine.texture.TextureLoader;
|
||||
import ei.engine.util.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* @author Mark Bernard
|
||||
* date: 23-Jun-2004
|
||||
*
|
||||
* Port of NeHe's Lesson 19 to LWJGL
|
||||
* Title: Particle Engine Using Triangle Strips
|
||||
* Uses version 0.9alpha of LWJGL http://www.lwjgl.org/
|
||||
*
|
||||
* Be sure that the LWJGL libraries are in your classpath
|
||||
*
|
||||
* Ported directly from the C++ version
|
||||
*
|
||||
* 2004-10-08: Updated to version 0.92alpha of LWJGL.
|
||||
* 2004-12-19: Updated to version 0.94alpha of LWJGL and to use
|
||||
* DevIL for image loading.
|
||||
*/
|
||||
public class CopyOfLesson19 {
|
||||
private boolean done = false;
|
||||
private boolean fullscreen = false;
|
||||
private final String windowTitle = "NeHe's OpenGL Lesson 19 for LWJGL (Particle Engine Using Triangle Strips)";
|
||||
private boolean f1 = false;
|
||||
private DisplayMode displayMode;
|
||||
|
||||
private final int MAX_PARTICLES = 1000;
|
||||
private Particle particle[];
|
||||
boolean rainbow = true; // Rainbow Mode?
|
||||
boolean sp; // Spacebar Pressed?
|
||||
boolean rp; // Enter Key Pressed?
|
||||
|
||||
float slowdown = 2.0f; // Slow Down Particles
|
||||
float xspeed; // Base X Speed (To Allow Keyboard Direction Of Tail)
|
||||
float yspeed; // Base Y Speed (To Allow Keyboard Direction Of Tail)
|
||||
float zoom = -40.0f; // Used To Zoom Out
|
||||
|
||||
int col; // Current Color Selection
|
||||
int delay; // Rainbow Effect Delay
|
||||
int texture; // Storage For Our Particle Texture
|
||||
|
||||
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}
|
||||
};
|
||||
|
||||
public static void main(String args[]) {
|
||||
MultiPrintStream.makeInstance(new MultiPrintStream("log.txt"));
|
||||
boolean fullscreen = false;
|
||||
if(args.length>0) {
|
||||
if(args[0].equalsIgnoreCase("fullscreen")) {
|
||||
fullscreen = true;
|
||||
}
|
||||
}
|
||||
|
||||
CopyOfLesson19 l19 = new CopyOfLesson19();
|
||||
l19.run(fullscreen);
|
||||
}
|
||||
public void run(boolean fullscreen) {
|
||||
this.fullscreen = fullscreen;
|
||||
try {
|
||||
init();
|
||||
while (!done) {
|
||||
mainloop();
|
||||
render();
|
||||
Display.update();
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
private void mainloop() {
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // Exit if Escape is pressed
|
||||
done = true;
|
||||
}
|
||||
if(Display.isCloseRequested()) { // Exit if window is closed
|
||||
done = true;
|
||||
}
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_F1) && !f1) { // Is F1 Being Pressed?
|
||||
f1 = true; // Tell Program F1 Is Being Held
|
||||
switchMode(); // Toggle Fullscreen / Windowed Mode
|
||||
}
|
||||
if(!Keyboard.isKeyDown(Keyboard.KEY_F1)) { // Is F1 Being Released?
|
||||
f1 = false;
|
||||
}
|
||||
if((Keyboard.isKeyDown(Keyboard.KEY_SPACE) && !sp) || (rainbow && (delay > 25))) {
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
|
||||
rainbow = false; // If Spacebar Is Pressed Disable Rainbow Mode
|
||||
}
|
||||
sp = true; // Set Flag Telling Us Space Is Pressed
|
||||
delay = 0; // Reset The Rainbow Color Cycling Delay
|
||||
col++; // Change The Particle Color
|
||||
if(col > 11) {
|
||||
col = 0; // If Color Is Too High Reset It
|
||||
}
|
||||
}
|
||||
if(!Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
|
||||
sp = false;
|
||||
}
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_ADD) && (slowdown > 1.0f)) {
|
||||
slowdown -= 0.01f; // Speed Up Particles
|
||||
}
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_SUBTRACT) && (slowdown < 4.0f)) {
|
||||
slowdown += 0.01f; // Slow Down Particles
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_PRIOR)) {
|
||||
zoom += 0.1f; // Zoom In
|
||||
}
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_NEXT)) {
|
||||
zoom -= 0.1f; // Zoom Out
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_RETURN) && !rp) { // Return Key Pressed
|
||||
rp = true; // Set Flag Telling Us It's Pressed
|
||||
rainbow = !rainbow; // Toggle Rainbow Mode On / Off
|
||||
}
|
||||
if(!Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
|
||||
rp = false; // If Return Is Released Clear Flag
|
||||
}
|
||||
|
||||
delay++; // Increase Rainbow Mode Color Cycling Delay Counter
|
||||
}
|
||||
|
||||
private void switchMode() {
|
||||
fullscreen = !fullscreen;
|
||||
try {
|
||||
Display.setFullscreen(fullscreen);
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void createWindow() throws Exception {
|
||||
Display.setFullscreen(fullscreen);
|
||||
DisplayMode d[] = Display.getAvailableDisplayModes();
|
||||
for (int i = 0; i < d.length; i++) {
|
||||
if (d[i].getWidth() == 640
|
||||
&& d[i].getHeight() == 480
|
||||
&& d[i].getBitsPerPixel() == 32) {
|
||||
displayMode = d[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
Display.setDisplayMode(displayMode);
|
||||
Display.setTitle(windowTitle);
|
||||
Display.create();
|
||||
}
|
||||
private void init() throws Exception {
|
||||
particle = new Particle[MAX_PARTICLES];
|
||||
|
||||
for(int i=0;i<MAX_PARTICLES;i++) {
|
||||
particle[i] = new Particle();
|
||||
}
|
||||
|
||||
createWindow();
|
||||
|
||||
loadTextures();
|
||||
initGL();
|
||||
|
||||
}
|
||||
private void loadTextures() { // Load Bitmaps And Convert To Textures
|
||||
texture = loadTexture("data/particle.bmp");
|
||||
}
|
||||
private void initGL() { // All Setup For OpenGL Goes Here
|
||||
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
|
||||
GL11.glLoadIdentity(); // Reset The Projection Matrix
|
||||
|
||||
// Calculate The Aspect Ratio Of The Window
|
||||
GLU.gluPerspective(45.0f,
|
||||
(float) displayMode.getWidth() / (float) displayMode.getHeight(),
|
||||
0.1f,100.0f);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
|
||||
|
||||
//GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); // Type Of Blending To Perform
|
||||
GL11.glEnable(GL11.GL_BLEND); // Enable Blending
|
||||
|
||||
|
||||
|
||||
for (int i=0;i<MAX_PARTICLES;i++) // Initials All The Textures
|
||||
{
|
||||
particle[i].active = true; // Make All The Particles Active
|
||||
particle[i].life = 1.0f; // 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 * (12 / MAX_PARTICLES)][0]; // Select Red Rainbow Color
|
||||
particle[i].g = colors[i * (12 / MAX_PARTICLES)][1]; // Select Red Rainbow Color
|
||||
particle[i].b = colors[i * (12 / MAX_PARTICLES)][2]; // Select Red Rainbow Color
|
||||
particle[i].xi = ((float)((Math.random() * 50.0)) - 26.0f) * 10.0f; // Random Speed On X Axis
|
||||
particle[i].yi = ((float)((Math.random() * 50.0)) - 25.0f) * 10.0f; // Random Speed On Y Axis
|
||||
particle[i].zi = ((float)((Math.random() * 50.0)) - 25.0f) * 10.0f; // Random Speed On Z Axis
|
||||
particle[i].xg = 0.0f; // Set Horizontal Pull To Zero
|
||||
particle[i].yg = -0.8f; // Set Vertical Pull Downward
|
||||
particle[i].zg = 0.0f; // Set Pull On Z Axis To Zero
|
||||
}
|
||||
}
|
||||
|
||||
private void render() {
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
|
||||
GL11.glLoadIdentity(); // Reset The ModelView Matrix
|
||||
|
||||
for(int i=0;i<MAX_PARTICLES;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
|
||||
float z = particle[i].z + zoom; // Particle Z Pos + Zoom
|
||||
|
||||
// Draw The Particle Using Our RGB Values, Fade The Particle Based On It's Life
|
||||
GL11.glColor4f(particle[i].r, particle[i].g, particle[i].b, particle[i].life);
|
||||
|
||||
GL11.glBegin(GL11.GL_TRIANGLE_STRIP); // Build Quad From A Triangle Strip
|
||||
GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3f(x + 0.5f, y + 0.5f, z); // Top Right
|
||||
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(x - 0.5f, y + 0.5f, z); // Top Left
|
||||
GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3f(x + 0.5f, y - 0.5f, z); // Bottom Right
|
||||
GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3f(x - 0.5f, y - 0.5f, z); // Bottom Left
|
||||
GL11.glEnd(); // Done Building Triangle Strip
|
||||
|
||||
particle[i].x += particle[i].xi / (slowdown * 1000);// Move On The X Axis By X Speed
|
||||
particle[i].y += particle[i].yi / (slowdown * 1000);// Move On The Y Axis By Y Speed
|
||||
particle[i].z += particle[i].zi / (slowdown * 1000);// Move On The Z Axis By Z Speed
|
||||
|
||||
particle[i].xi += particle[i].xg; // Take Pull On X Axis Into Account
|
||||
particle[i].yi += particle[i].yg; // Take Pull On Y Axis Into Account
|
||||
particle[i].zi += particle[i].zg; // Take Pull On Z Axis Into Account
|
||||
particle[i].life -= particle[i].fade; // Reduce Particles Life By 'Fade'
|
||||
|
||||
if (particle[i].life < 0.0f) { // If Particle Is Burned Out
|
||||
particle[i].life = 1.0f; // Give It New Life
|
||||
particle[i].fade = ((float)(Math.random() * 100.0)) / 1000.0f + 0.003f; // Random Fade Value
|
||||
particle[i].x = 0.0f; // Center On X Axis
|
||||
particle[i].y = 0.0f; // Center On Y Axis
|
||||
particle[i].z = 0.0f; // Center On Z Axis
|
||||
particle[i].xi = xspeed + ((float)(Math.random() * 60.0)) - 32.0f; // X Axis Speed And Direction
|
||||
particle[i].yi = yspeed + ((float)(Math.random() * 60.0)) - 30.0f; // Y Axis Speed And Direction
|
||||
particle[i].zi = ((float)(Math.random() * 60.0)) - 30.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
|
||||
}
|
||||
|
||||
// If Number Pad 8 And Y Gravity Is Less Than 1.5 Increase Pull Upwards
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_NUMPAD8) && (particle[i].yg<1.5f)) {
|
||||
particle[i].yg += 0.01f;
|
||||
}
|
||||
|
||||
// If Number Pad 2 And Y Gravity Is Greater Than -1.5 Increase Pull Downwards
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_NUMPAD2) && (particle[i].yg>-1.5f)) {
|
||||
particle[i].yg -= 0.01f;
|
||||
}
|
||||
|
||||
// If Number Pad 6 And X Gravity Is Less Than 1.5 Increase Pull Right
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_NUMPAD6) && (particle[i].xg<1.5f)) {
|
||||
particle[i].xg += 0.01f;
|
||||
}
|
||||
|
||||
// If Number Pad 4 And X Gravity Is Greater Than -1.5 Increase Pull Left
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_NUMPAD4) && (particle[i].xg>-1.5f)) {
|
||||
particle[i].xg -= 0.01f;
|
||||
}
|
||||
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_TAB)) { // Tab Key Causes A Burst
|
||||
particle[i].x = 0.0f; // Center On X Axis
|
||||
particle[i].y = 0.0f; // Center On Y Axis
|
||||
particle[i].z = 0.0f; // Center On Z Axis
|
||||
particle[i].xi = ((float)(Math.random() * 50.0) - 26.0f) * 10.0f; // Random Speed On X Axis
|
||||
particle[i].yi = ((float)(Math.random() * 50.0) - 25.0f) * 10.0f; // Random Speed On Y Axis
|
||||
particle[i].zi = ((float)(Math.random() * 50.0) - 25.0f) * 10.0f; // Random Speed On Z Axis
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
Display.destroy();
|
||||
}
|
||||
|
||||
private int loadTexture(String path) {
|
||||
Texture tex;
|
||||
tex = TextureLoader.getTextureLoaderInstance().getTexture(path);
|
||||
return tex.getGLTarget(); // Return Image Address In Memory
|
||||
}
|
||||
}
|
||||
/*
|
||||
class Particle { // Particles Structure
|
||||
public boolean active; // Active (Yes/No)
|
||||
public float life; // Particle Life
|
||||
public float fade; // Fade Speed
|
||||
public float r; // Red Value
|
||||
public float g; // Green Value
|
||||
public float b; // Blue Value
|
||||
public float x; // X Position
|
||||
public float y; // Y Position
|
||||
public float z; // Z Position
|
||||
public float xi; // X Direction
|
||||
public float yi; // Y Direction
|
||||
public float zi; // Z Direction
|
||||
public float xg; // X Gravity
|
||||
public float yg; // Y Gravity
|
||||
public float zg; // Z Gravity
|
||||
}
|
||||
*/
|
||||
194
src/ei/engine/effects/Particles.java
Normal file
194
src/ei/engine/effects/Particles.java
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
package ei.engine.effects;
|
||||
|
||||
/*
|
||||
* This Code Was Created By Jeff Molofee and GB Schmick 2000
|
||||
* A HUGE Thanks To Fredric Echols For Cleaning Up
|
||||
* And Optimizing The Base Code, Making It More Flexible!
|
||||
* If You've Found This Code Useful, Please Let Me Know.
|
||||
* Visit Our Sites At www.tiptup.com and nehe.gamedev.net
|
||||
*/
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import ei.engine.scene.Entity;
|
||||
import ei.engine.texture.Texture;
|
||||
import ei.engine.texture.TextureLoader;
|
||||
|
||||
/**
|
||||
* @author Mark Bernard
|
||||
* date: 23-Jun-2004
|
||||
* @author Ziver Koc
|
||||
* date: 19-Mar-2007
|
||||
*
|
||||
* Port of NeHe's Lesson 19 to LWJGL
|
||||
* Title: Particle Engine Using Triangle Strips
|
||||
* Uses version 0.9alpha of LWJGL http://www.lwjgl.org/
|
||||
*
|
||||
* Be sure that the LWJGL libraries are in your classpath
|
||||
*
|
||||
* Ported directly from the C++ version
|
||||
*
|
||||
*/
|
||||
public class Particles extends Entity{
|
||||
private final int MAX_PARTICLES = 1000;
|
||||
private Particle particle[];
|
||||
boolean rainbow = true; // Rainbow Mode?
|
||||
|
||||
float slowdown = 1.0f; // Slow Down Particles
|
||||
float xspeed = 00; // Base X Speed (To Allow Keyboard Direction Of Tail)
|
||||
float yspeed = 000; // Base Y Speed (To Allow Keyboard Direction Of Tail)
|
||||
float zoom = 0.0f; // Used To Zoom Out
|
||||
|
||||
int col; // Current Color Selection
|
||||
int delay; // Rainbow Effect Delay
|
||||
Texture texture; // Storage For Our Particle Texture
|
||||
|
||||
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}
|
||||
};
|
||||
|
||||
public Particles(String name){
|
||||
super(name);
|
||||
this.texture = TextureLoader.getTextureLoaderInstance().getTexture("data/particle.bmp");
|
||||
reset();
|
||||
setExplotion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all the paricals
|
||||
*
|
||||
*/
|
||||
public void reset(){
|
||||
particle = new Particle[MAX_PARTICLES];
|
||||
|
||||
for(int i=0;i<MAX_PARTICLES;i++) {
|
||||
particle[i] = new Particle();
|
||||
particle[i].life = -1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(rainbow && (delay > 25)) {
|
||||
delay = 0; // Reset The Rainbow Color Cycling Delay
|
||||
col++; // Change The Particle Color
|
||||
if(col > 11) {
|
||||
col = 0; // If Color Is Too High Reset It
|
||||
}
|
||||
}
|
||||
delay++; // Increase Rainbow Mode Color Cycling Delay Counter
|
||||
}
|
||||
|
||||
|
||||
private void setExplotion() {
|
||||
for (int i=0;i<MAX_PARTICLES;i++){ // Initials All The Textures
|
||||
particle[i].active = true; // Make All The Particles Active
|
||||
particle[i].regenerate = false; // set if the partical whill regenerate
|
||||
particle[i].size = 20.0f; // Set Vertical size
|
||||
particle[i].life = 1.0f; // 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 * (12 / MAX_PARTICLES)][0]; // Select Red Rainbow Color
|
||||
particle[i].g = colors[i * (12 / MAX_PARTICLES)][1]; // Select Red Rainbow Color
|
||||
particle[i].b = colors[i * (12 / MAX_PARTICLES)][2]; // Select Red Rainbow Color
|
||||
particle[i].xi = ((float)((Math.random() * 500.0)) - 260.0f) * 10.0f; // Random Speed On X Axis
|
||||
particle[i].yi = ((float)((Math.random() * 500.0)) - 250.0f) * 10.0f; // Random Speed On Y Axis
|
||||
particle[i].zi = ((float)((Math.random() * 500.0)) - 250.0f) * 10.0f; // Random Speed On Z Axis
|
||||
particle[i].xg = 0.0f; // Set Horizontal Pull To Zero
|
||||
particle[i].yg = -0.8f; // Set Vertical Pull Downward
|
||||
particle[i].zg = 0.0f; // Set Pull On Z Axis To Zero
|
||||
}
|
||||
}
|
||||
|
||||
public void render() {
|
||||
// store the current model matrix
|
||||
GL11.glPushMatrix();
|
||||
//Reset The Current Modelview Matrix
|
||||
GL11.glLoadIdentity();
|
||||
|
||||
//Sets the location
|
||||
super.setTranslationGL();
|
||||
|
||||
texture.bindGL();
|
||||
for(int i=0;i<MAX_PARTICLES;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
|
||||
float z = particle[i].z + zoom; // Particle Z Pos + Zoom
|
||||
float size = particle[i].size;
|
||||
|
||||
// Draw The Particle Using Our RGB Values, Fade The Particle Based On It's Life
|
||||
GL11.glColor4f(particle[i].r, particle[i].g, particle[i].b, particle[i].life);
|
||||
//Build Quad From A Triangle Strip
|
||||
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);{
|
||||
//Top Right
|
||||
GL11.glTexCoord2f(1.0f, 1.0f);
|
||||
GL11.glVertex3f(x + size, y + size, z);
|
||||
//Top Left
|
||||
GL11.glTexCoord2f(0.0f, 1.0f);
|
||||
GL11.glVertex3f(x - size, y + size, z);
|
||||
//Bottom Right
|
||||
GL11.glTexCoord2f(1.0f, 0.0f);
|
||||
GL11.glVertex3f(x + size, y - size, z);
|
||||
//Bottom Left
|
||||
GL11.glTexCoord2f(0.0f, 0.0f);
|
||||
GL11.glVertex3f(x - size, y - size, z);
|
||||
//Done Building Triangle Strip
|
||||
}GL11.glEnd();
|
||||
|
||||
particle[i].x += particle[i].xi / (slowdown * 1000);// Move On The X Axis By X Speed
|
||||
particle[i].y += particle[i].yi / (slowdown * 1000);// Move On The Y Axis By Y Speed
|
||||
particle[i].z += particle[i].zi / (slowdown * 1000);// Move On The Z Axis By Z Speed
|
||||
|
||||
particle[i].xi += particle[i].xg; // Take Pull On X Axis Into Account
|
||||
particle[i].yi += particle[i].yg; // Take Pull On Y Axis Into Account
|
||||
particle[i].zi += particle[i].zg; // Take Pull On Z Axis Into Account
|
||||
particle[i].life -= particle[i].fade; // Reduce Particles Life By 'Fade'
|
||||
|
||||
if (particle[i].life < 0.0f) { // If Particle Is Burned Out
|
||||
particle[i].life = 1.0f; // Give It New Life
|
||||
particle[i].size = 15.0f; // Particle size
|
||||
particle[i].fade = ((float)(Math.random() * 1000.0)) / 1000.0f + 0.003f; // Random Fade Value
|
||||
particle[i].x = 0.0f; // Center On X Axis
|
||||
particle[i].y = 0.0f; // Center On Y Axis
|
||||
particle[i].z = 0.0f; // Center On Z Axis
|
||||
particle[i].xi = ((float)((Math.random() * 500.0)) - 250.0f) * 10.0f; // X Axis Speed And Direction
|
||||
particle[i].yi = ((float)((Math.random() * 500.0)) - 250.0f) * 10.0f; // Y Axis Speed And Direction
|
||||
particle[i].zi = ((float)((Math.random() * 500.0)) - 250.0f) * 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
|
||||
if(!particle[i].regenerate){
|
||||
particle[i].active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Reset The Current Modelview Matrix
|
||||
GL11.glLoadIdentity();
|
||||
// restore the model view matrix to prevent contamination
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
class Particle { // Particles Structure
|
||||
public boolean active; // Active (Yes/No)
|
||||
public boolean regenerate; // Regenerate (Yes/No)
|
||||
public float size; // Particle Size
|
||||
public float life; // Particle Life
|
||||
public float fade; // Fade Speed
|
||||
public float r; // Red Value
|
||||
public float g; // Green Value
|
||||
public float b; // Blue Value
|
||||
public float x; // X Position
|
||||
public float y; // Y Position
|
||||
public float z; // Z Position
|
||||
public float xi; // X Direction
|
||||
public float yi; // Y Direction
|
||||
public float zi; // Z Direction
|
||||
public float xg; // X Gravity
|
||||
public float yg; // Y Gravity
|
||||
public float zg; // Z Gravity
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
package ei.engine.scene;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import ei.engine.texture.Texture;
|
||||
|
|
@ -49,15 +47,7 @@ public class Sprite extends Entity {
|
|||
*/
|
||||
public Sprite(String name, String ref) {
|
||||
super(name);
|
||||
try {
|
||||
this.texture = TextureLoader.getTextureLoaderInstance().getTexture(ref);
|
||||
|
||||
} catch (IOException e) {
|
||||
// a tad abrupt, but our purposes if you can't find a
|
||||
// sprite's image you might as well give up.
|
||||
System.err.println("Unable to load texture: "+ref);
|
||||
System.exit(0);
|
||||
}
|
||||
this.texture = TextureLoader.getTextureLoaderInstance().getTexture(ref);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -73,6 +73,15 @@ public class Texture {
|
|||
setWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target of the buffer
|
||||
*
|
||||
* @return The target of the buffer
|
||||
*/
|
||||
public int getGLTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the original image
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import javax.imageio.ImageIO;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import ei.engine.util.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* A utility class to load textures for lwjgl. This source is based
|
||||
* on a texture that can be found in the Java Gaming (www.javagaming.org)
|
||||
|
|
@ -88,18 +90,25 @@ public class TextureLoader {
|
|||
* @return The loaded texture
|
||||
* @throws IOException Indicates a failure to access the resource
|
||||
*/
|
||||
public Texture getTexture(String resourceName) throws IOException {
|
||||
public Texture getTexture(String resourceName){
|
||||
MultiPrintStream.out.println("Loading texture: "+resourceName);
|
||||
Texture tex = (Texture) table.get(resourceName);
|
||||
|
||||
if (tex != null) {
|
||||
return tex;
|
||||
}
|
||||
|
||||
tex = getTexture(resourceName,
|
||||
GL11.GL_TEXTURE_2D, // target
|
||||
GL11.GL_RGBA, // dst pixel format
|
||||
GL11.GL_LINEAR, // min filter (unused)
|
||||
GL11.GL_LINEAR);
|
||||
try {
|
||||
tex = getTexture(resourceName,
|
||||
GL11.GL_TEXTURE_2D, // target
|
||||
GL11.GL_RGBA, // dst pixel format
|
||||
GL11.GL_LINEAR, // min filter (unused)
|
||||
GL11.GL_LINEAR);
|
||||
} catch (IOException e) {
|
||||
MultiPrintStream.out.println("Unable to load texture: "+resourceName);
|
||||
MultiPrintStream.out.println(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
table.put(resourceName,tex);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package ei.game.gamestate;
|
||||
|
||||
import ei.engine.effects.Particles;
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
|
|
@ -11,17 +12,23 @@ public class InGameState extends GameState{
|
|||
private Node rootNode;
|
||||
private Sprite sprite1;
|
||||
private Sound sound1;
|
||||
private Particles p;
|
||||
|
||||
public InGameState(String name){
|
||||
super(name);
|
||||
rootNode = new Node("InGameNode");
|
||||
|
||||
sprite1 = new Sprite("tank","data/units/tank.png");
|
||||
sprite1.setScale(new Vector2f(0.5f,0.5f));
|
||||
//sprite1.setScale(new Vector2f(0.5f,0.5f));
|
||||
sprite1.setLocation(new Vector2f(300,300));
|
||||
rootNode.add(sprite1);
|
||||
|
||||
p = new Particles("particle");
|
||||
p.setLocation(sprite1.getLocation());
|
||||
rootNode.add(p);
|
||||
|
||||
sound1 = new Sound("sound","data/sounds/test.wav");
|
||||
sound1.loop();
|
||||
sound1.play();
|
||||
rootNode.add(sound1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue