Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

A Fountain of Lines

The LineParticles class implements a particle system made up of yellow and red lines, which shoot out from the origin with parabolic trajectories. The effect, as seen in Figure 21-2, is something like a firework. The thickness of the lines is increased slightly, and anti-aliasing is switched on. When a line has completely dropped below the y-axis, it's reinitialized, which means the firework never runs out.

The main difference from PointParticles is the extra code required to initialize the lines and update them inside the float arrays. Six values in a float array are necessary to represent a single line, three values for each of the two end points.

The LineParticles constructor creates a LineArray object using BY_REFERENCE geometry for its coordinates and color:

    lineParts = new LineArray(numPoints,  LineArray.COORDINATES |
                          LineArray.COLOR_3 | LineArray.BY_REFERENCE );
   
    lineParts.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
    lineParts.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);

Initializing the Particles

The changes start with the initialization of the float arrays inside createGeometry():

    // step in 6's == two (x,y,z) coords == one line
    for(int i=0; i < numPoints*3; i=i+6)
      initTwoParticles(i);

initTwoParticles() initializes the two points. It assigns the same position and velocity to both points and then calls updateParticle() to update one of the point's position and velocity. This specifies a line with a point which is one update ahead of the other point. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page