Skip to content

Commit

Permalink
Particle type system changed
Browse files Browse the repository at this point in the history
  • Loading branch information
goldDaniel committed Sep 4, 2018
1 parent ca52495 commit d06d937
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 93 deletions.
24 changes: 9 additions & 15 deletions core/src/com/golddaniel/entities/Boid.java
Expand Up @@ -306,31 +306,25 @@ public void kill(WorldModel model)
//immune until active
if(active)
{
int particles = 64;
int particles = 32;
for (int i = 0; i < particles; i++)
{
float angle = (float)i/(float)particles*360f;

angle += MathUtils.random(-2.5f, 2.5f);

if(i % 2 == 0)
{
ParticleSpin p = new ParticleSpin(
new Vector2(
position.x + width/2,
position.y + height/2),
angle, MathUtils.random(0.2f, .6f),
Color.ORANGE.cpy(), Color.WHITE.cpy(), Globals.WIDTH/2f);
model.addEntity(p);
}
else
{
model.createParticle(
new Vector2(
new Vector2(
position.x + width/2,
position.y + height/2),
angle, MathUtils.random(0.1f, 0.4f), Globals.WIDTH/1.2f,
Color.WHITE.cpy(), Color.LIME.cpy());
position.y + height/2),
angle,
MathUtils.random(0.5f, 0.9f),
-Globals.WIDTH/2f,
Color.CYAN.cpy(),
Color.MAGENTA.cpy(),
Particle.TYPE.SPIN);
}
}

Expand Down
21 changes: 14 additions & 7 deletions core/src/com/golddaniel/entities/Bouncer.java
Expand Up @@ -210,30 +210,37 @@ public void kill(WorldModel model)

if(i % 2 == 0)
{
ParticleSpin p = new ParticleSpin(
model.createParticle(
new Vector2(
position.x + width/2,
position.y + height/2),
angle, MathUtils.random(0.4f, 1.2f),
Color.WHITE.cpy(), Color.GREEN.cpy(), Globals.WIDTH/2f);
model.addEntity(p);
angle,
MathUtils.random(0.3f, 0.4f),
Globals.WIDTH/4f,
Color.WHITE.cpy(),
Color.GREEN.cpy(),
Particle.TYPE.SPIN);
}
else
{
model.createParticle(
new Vector2(
position.x + width/2,
position.y + height/2),
angle, MathUtils.random(0.2f, .8f), Globals.WIDTH,
Color.WHITE.cpy(), Color.YELLOW.cpy());
angle,
MathUtils.random(0.2f, .8f),
Globals.WIDTH,
Color.WHITE.cpy(),
Color.YELLOW.cpy(),
Particle.TYPE.NORMAL);
}
}

for (int i = 0; i < 5; i++)
{
model.applyRadialForce(
getMid(),
4000,
16000,
512);
}
Messenger.notify(Messenger.EVENT.BOUNCER_DEAD);
Expand Down
83 changes: 59 additions & 24 deletions core/src/com/golddaniel/entities/Particle.java
Expand Up @@ -20,22 +20,31 @@
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.golddaniel.main.Messenger;
import com.badlogic.gdx.utils.Pool;
import com.golddaniel.main.WorldModel;

/**
*
* @author wrksttn
* @param <T>
*
*/
public class Particle extends Entity
public class Particle<T> implements Pool.Poolable
{
public static enum TYPE
{
NORMAL,
SPIN,
}

Vector2 pos;
float angle;

float lifespan;
final float START_LIFESPAN;

//would make final, but cannot due to poolable
float START_LIFESPAN;

Color startColor;
Color endColor;
Expand All @@ -46,14 +55,29 @@ public class Particle extends Entity
float height;

float speed;
final float START_SPEED;

//would make final, but cannot due to poolable
float START_SPEED;

TYPE type;

private static TextureRegion tex = new TextureRegion(new Texture("texture.png"));

boolean isAlive;

public Particle(
Vector2 pos, float dir,
float lifespan, Color startColor, Color endColor,
float speed)
float speed, TYPE type)
{
init(pos, dir, lifespan, startColor, endColor, speed,type);
}

public void init(
Vector2 pos, float dir,
float lifespan, Color startColor, Color endColor,
float speed,
TYPE type)
{
this.pos = pos;
this.angle = dir;
Expand All @@ -68,18 +92,19 @@ public Particle(

this.START_SPEED = speed;

this.type = type;


width = 64;
height = 4;

if(type == TYPE.SPIN)
{
width = 128;
}

isAlive = true;
}

@Override
public void onNotify(Messenger.EVENT event)
{
}

private void lerpColor()
{
color.r = MathUtils.lerp(endColor.r, startColor.r, lifespan/START_LIFESPAN);
Expand All @@ -88,7 +113,6 @@ private void lerpColor()
color.a = MathUtils.lerp(0.4f, 1f, lifespan/START_LIFESPAN);
}

@Override
public void update(WorldModel world, float delta)
{
pos.x += MathUtils.cosDeg(angle)*speed*delta;
Expand All @@ -99,13 +123,17 @@ public void update(WorldModel world, float delta)

speed = START_SPEED * lifespan/START_LIFESPAN;

if(type == TYPE.SPIN)
{
angle += MathUtils.random(90f, 360f) * delta * lifespan/START_LIFESPAN;
}

lerpColor();

lifespan -= delta;
if(lifespan <= 0) isAlive = false;
}

@Override

public void draw(SpriteBatch s)
{
s.enableBlending();
Expand All @@ -119,20 +147,27 @@ public void draw(SpriteBatch s)
s.setColor(Color.WHITE);
}

@Override
public void dispose()
public boolean isAlive()
{
return isAlive;
}

@Override
public Rectangle getBoundingBox()

public void dispose()
{
return new Rectangle(pos.x, pos.y, width, height);

}

@Override
public void kill(WorldModel model)
public void reset()
{
//isAlive = false;
pos = new Vector2(-100, -100);
angle = 0;
lifespan = -1;
START_LIFESPAN = -1;

startColor = endColor = color = null;

width = height = 0;
speed = START_SPEED = 0;
}
}
37 changes: 33 additions & 4 deletions core/src/com/golddaniel/entities/Player.java
Expand Up @@ -316,7 +316,7 @@ public void kill(WorldModel model)
{
isAlive = false;
System.out.println("KILL PLAYER");
int particles = 2048;
int particles = 1024;
for (int i = 0; i < particles; i++)
{
//particle angle
Expand All @@ -327,17 +327,46 @@ public void kill(WorldModel model)
position.y + height/2),
pAngle,
MathUtils.random(0.5f, 1f)*3f,
MathUtils.random(0.6f, 0.8f) * model.WORLD_WIDTH*2,
MathUtils.random(0.6f, 0.8f) * Globals.WIDTH/2,
new Color(MathUtils.random(),
MathUtils.random(),
MathUtils.random(),
1f),
new Color(MathUtils.random(),
MathUtils.random(),
MathUtils.random(),
1f));
1f),
Particle.TYPE.NORMAL);
}
model.killAllEntities();
int points = 64;
particles = 64;
for (int i = 0; i < points; i++)
{
for (int j = 0; j < particles; j++)
{
float pAngle = (float)i/(float)particles*360f;

Vector2 pos = new Vector2();
pos.x = MathUtils.random(model.WORLD_WIDTH);
pos.y = MathUtils.random(model.WORLD_HEIGHT);

model.createParticle(
pos,
pAngle,
MathUtils.random(0.6f, 1.5f)*3f,
MathUtils.random(0.6f, 0.8f) * Globals.WIDTH,
new Color(MathUtils.random(),
MathUtils.random(),
MathUtils.random(),
1f),
new Color(MathUtils.random(),
MathUtils.random(),
MathUtils.random(),
1f),
Particle.TYPE.SPIN);
}

model.killAllEntities();
}
model.applyRadialForce(getMid(), -64000, model.WORLD_WIDTH);
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/com/golddaniel/main/PhysicsGrid.java
Expand Up @@ -33,8 +33,8 @@
public class PhysicsGrid extends Entity
{

private final float STIFFNESS = 8.5f;
private final float DAMPING = 4f;
private final float STIFFNESS = 12.5f;
private final float DAMPING = 10f;
private final float INVERSE_MASS = 1f/0.2f;

private class Spring
Expand Down Expand Up @@ -227,7 +227,7 @@ public void update(float delta)
@Override
public void update(WorldModel model, float delta)
{
if(delta < 0.25f)
if(delta < 0.025f)
update(delta);
}

Expand Down

0 comments on commit d06d937

Please sign in to comment.