Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: CopyableCougar4 (posted 2014-06-21 02:13:32, viewed 89 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84  
package me.CopyableCougar4.opengl;

public class Vector {
   
   /** X coordinate */
   private float x;
   /** Y coordinate */
   private float y;
   
   /**
    * Construct a vector.
    */
   public Vector(float x, float y){
      
      this.x = x;
      this.y = y;
      
   }
   
   /**
    * Get the x
    */
   public float getX(){
      
      return x;
      
   }
   
   /**
    * Get the y
    */
   public float getY(){
      
      return y;
      
   }
   
   /**
    * Set the x
    */
   public void setX(float x){
      
      this.x = x;
      
   }
   
   /**
    * Set the y
    */
   public void setY(float y){
      
      this.y = y;
      
   }
   
   /**
    * Clone the object
    */
   public Vector clone(){
      
      return new Vector(x, y);
      
   }
   
   /**
    * Add to the vector
    */
   public void add(float _x, float _y){
      
      setX(x + _x);
      setY(y + _y);
      
   }
   
   /**
    * Get a string representation
    */
   public String toString(){
      
      return "Vector -> [" + x + ", " + y + "]";
      
   }

}


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122  
package me.CopyableCougar4.opengl;

import java.awt.Color;

import static org.lwjgl.opengl.GL11.*;

public class Particle {
   
   /** Particle center. */
   private Vector center;
   /** Particle color */
   private Color color;
   /** Size of the particle */
   private int size;
   /** Whether the particle is disposed */
   private boolean disposed;
   /** Cycles of rendering */
   private int cycles;
   /** Angle of movement */
   private float angle;
   /** Speed of particle */
   private float speed;
   
   /**
    * Construct a particle
    */
   public Particle(Color color, Vector center, int size, float angle, float speed){
      
      this.color = color;
      this.center = center;
      this.size = size;
      disposed = false;
      cycles = 0;
      this.angle = angle;
      this.speed = speed;
      
   }
   
   /**
    * Construct a particle
    */
   public Particle(Color color, float x, float y, int size, float angle, float speed){
      
      this(color, new Vector(x, y), size, angle, speed);
      
   }
   
   /**
    * Dispose of a particle
    */
   public void dispose(){
      
      disposed = true;
      
   }
   
   /**
    * Check if a particle is disposed
    */
   public boolean isDisposed(){
      
      return disposed;
      
   }
   
   /**
    * Convert it's angle/speed into movement
    */
   public void travel(){
      
      float x = (float) (Math.cos(Math.toRadians(-angle)) * speed);
      float y = (float) (Math.sin(Math.toRadians(-angle)) * speed);
      float dx = center.getX() + x;
      float dy = center.getY() + y;
      center.setX(dx);
      center.setY(dy);
      
   }
   
   /**
    * Render the particle
    */
   public void render(){
      
      if(cycles % 1000 == 0){
         shrink(); // shrink test
      }
      if(isDisposed())
         return; // dispose test
      cycles++; // frame count
      travel(); // make the particle travel
      // render it
      float x1 = center.getX() - (size / 2);
      float y1 = center.getY() - (size / 2);
      glPushMatrix();
         glColor3f(color.getRed() / 255.0f, color.getGreen() / 255.0f, color.getBlue() / 255.0f);
            glTranslatef(x1, y1, 0.0f);
            glBegin(GL_QUADS);
               glVertex2f(0.0f, 0.0f);
               glVertex2f(size, 0.0f);
               glVertex2f(size, size);
               glVertex2f(0.0f, size);
            glEnd();
         glColor3f(1.0f, 1.0f, 1.0f);
      glPopMatrix();
      
   }
   
   /**
    * Shrink the particle
    */
   public void shrink(){
      
      if(size >= 2){
         size /= 2; // cut in half
      } else {
         dispose(); // destroy it, it's too small
      }
      
   }

}


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50  
package me.CopyableCougar4.opengl;

import java.awt.Color;
import java.util.ArrayList;

import org.lwjgl.opengl.GL11;

public class Emitter {

   /** Arraylist for Particles */
   private ArrayList<Particle> particles;

   /**
    * Construct the emitter instance
    */
   public Emitter(int quantity, Color particleColor, Vector center, float speed){
      
      particles = new ArrayList<Particle>();
      float delta = 360.0f / quantity;
      float angle = 0.0f;
      //add particles in all directions
      while(angle < 360.0f){
         angle += delta;
         particles.add(new Particle(particleColor, center, 32, angle, speed));
      }
      
   }
   
   /**
    * Construct the emitter instance
    */
   public Emitter(int quantity, Vector center, float speed){
      
      this(quantity, Color.RED, center, speed);
      
   }
   
   /**
    * Render all the particles in this emitter
    */
   public void render(){

      GL11.glDisable(GL11.GL_TEXTURE_2D);
      for(Particle particle : particles){
         particle.render(); // render the particle if it isn't disposed
      }
      
   }
   
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (9 views)
2014-10-02 14:36:20

Pippogeek (41 views)
2014-09-24 16:13:29

Pippogeek (32 views)
2014-09-24 16:12:22

Pippogeek (22 views)
2014-09-24 16:12:06

Grunnt (48 views)
2014-09-23 14:38:19

radar3301 (30 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!