Skip to content

Commit

Permalink
Restructuring code mostly, explained in description
Browse files Browse the repository at this point in the history
Removed a few features
-Level start / end
-working timer
As I am reworking the Level data and have begun working on loading it from a file.

Also tuned A lot of values regarding gameplay.

NOTE: Linux driver, gamepad inputs are different depending on if the controller is connected via USB vs BLUETOOTH 
thread for bug: 
paroj/xpad#53
  • Loading branch information
goldDaniel committed Sep 14, 2018
1 parent d06d937 commit 1c938a2
Show file tree
Hide file tree
Showing 15 changed files with 436 additions and 138 deletions.
93 changes: 65 additions & 28 deletions core/src/com/golddaniel/entities/Boid.java
Expand Up @@ -35,7 +35,7 @@
*/
public class Boid extends Entity
{
static float SPEED_MAX = 300f;
static float SPEED_MAX = 250f;

static ShapeRenderer debug = new ShapeRenderer();

Expand All @@ -61,7 +61,7 @@ public Boid(Vector2 position)

float angle = MathUtils.random(MathUtils.PI*2);
acceleration = new Vector2();
velocity = new Vector2(MathUtils.cos(angle), MathUtils.sin(angle));
velocity = new Vector2(MathUtils.cos(angle), MathUtils.sin(angle)).scl(SPEED_MAX);

activeTimer = new Timer();

Expand All @@ -77,18 +77,26 @@ public Boid(Vector2 position)
boids.add(this);
}

/**
* Returns direction vector based on position of all boids in range
*
* @return
*/
private Vector2 cohesion()
{
Vector2 result = new Vector2();
int count = 0;
float range =72;
float range = 64;

Vector2 sum = new Vector2();
for(Boid b : boids)
{
float dist = position.dst(b.position);

if(dist > 0 && dist < range)
/**
* commented out as we currently want average of all boids
*
*///if(dist > 0 && dist < range)
{
sum.add(b.position);
count++;
Expand All @@ -103,6 +111,11 @@ private Vector2 cohesion()
return result;
}

/**
* Returns direction vector based on velocity of all boids in range
*
* @return
*/
private Vector2 allignment()
{
Vector2 result = new Vector2();
Expand Down Expand Up @@ -132,6 +145,14 @@ private Vector2 allignment()
return result;
}

/**
* Returns direction vector based on separation of all boids in range.
*
* if a boid is in range, add a vector to the sum and give the opposite direction
*
*
* @return
*/
private Vector2 separation()
{
Vector2 result = new Vector2();
Expand Down Expand Up @@ -205,6 +226,11 @@ public void run()

if(active)
{
float[] hsv = new float[3];
color.toHsv(hsv);
hsv[0] += 60f*delta;
color.fromHsv(hsv);

borderCheck(model);

Vector2 separation = separation();
Expand All @@ -214,7 +240,7 @@ public void run()
Vector2 seek = new Vector2();

float dist = Float.MAX_VALUE;
float range = 512;
float range = 256;
if(model.getEntityType(Player.class).size > 0)
{
Vector2 target = model.getEntityType(Player.class).first().position;
Expand All @@ -232,23 +258,16 @@ public void run()
acceleration.add(boundary);
acceleration.add(seek);

//turn faster toward the target when near
if(dist < range)
{
acceleration.limit(SPEED_MAX/4f*delta);
}
else
{
acceleration.limit(SPEED_MAX/16f*delta);
}

acceleration.limit(SPEED_MAX/64f*delta);


velocity.add(acceleration);
velocity.limit(SPEED_MAX*delta);

position.add(velocity);

acceleration.set(0, 0);



model.applyRadialForce(position, 800f, 128);
}
Expand Down Expand Up @@ -306,7 +325,7 @@ public void kill(WorldModel model)
//immune until active
if(active)
{
int particles = 32;
int particles = 64;
for (int i = 0; i < particles; i++)
{
float angle = (float)i/(float)particles*360f;
Expand All @@ -315,26 +334,44 @@ public void kill(WorldModel model)

if(i % 2 == 0)
{

float[] hsv = new float[3];

Color.MAGENTA.toHsv(hsv);

hsv[1] /= 4;

Color c = new Color().fromHsv(hsv);

model.createParticle(
new Vector2(
position.x + width/2,
position.y + height/2),
angle,
MathUtils.random(0.5f, 0.9f),
-Globals.WIDTH/2f,
Color.CYAN.cpy(),
Color.MAGENTA.cpy(),
MathUtils.random(0.5f, 0.7f),
-Globals.WIDTH/4,
Color.MAGENTA,
Color.WHITE,
Particle.TYPE.SPIN);

model.createParticle(
new Vector2(
position.x + width/2,
position.y + height/2),
angle,
MathUtils.random(0.7f, 1.2f),
-Globals.WIDTH/2f,
Color.WHITE,
Color.FIREBRICK,
Particle.TYPE.NORMAL);
}
}

for(int i = 0; i < 5; i++)
{
model.applyRadialForce(
getMid(),
2000,
256);
}
model.applyRadialForce(
getMid(),
10000,
256);

Messenger.notify(Messenger.EVENT.BOUNCER_DEAD);
isAlive = false;
}
Expand Down
2 changes: 0 additions & 2 deletions core/src/com/golddaniel/entities/Bullet.java
Expand Up @@ -32,8 +32,6 @@
*/
public class Bullet extends Entity
{



public static enum TYPE
{
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/golddaniel/entities/Particle.java
Expand Up @@ -125,7 +125,7 @@ public void update(WorldModel world, float delta)

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

lerpColor();
Expand Down
39 changes: 17 additions & 22 deletions core/src/com/golddaniel/entities/Player.java
Expand Up @@ -130,6 +130,8 @@ public void update(WorldModel model, float delta)
rightStick.y = -ControllerManager.controller.
getAxis(XboxMapping.R_STICK_VERTICAL_AXIS);



if(SharedLibraryLoader.isWindows)
{
rightStick.y = -rightStick.y;
Expand All @@ -146,12 +148,6 @@ public void update(WorldModel model, float delta)

}
//-----------------------------------------------------------

if(ControllerManager.controller.getButton(XboxMapping.A))
{

}

}
else
{
Expand Down Expand Up @@ -253,7 +249,7 @@ private void fireBullets(WorldModel model, Vector2 rightStick, float radius)
Vector2 bulletPos = new Vector2();

bulletPos.x = position.x + width/2f;
bulletPos.y = position.y + height/2f;
bulletPos.y = position. y+ height/2f;



Expand All @@ -262,23 +258,22 @@ private void fireBullets(WorldModel model, Vector2 rightStick, float radius)


Messenger.notify(Messenger.EVENT.PLAYER_FIRE);

Vector3 pos = new Vector3(position, 1);
pos.x += width/2;
pos.y += height/2;

float dif = 3f;


float dif = 2f;
model.createBullet(bulletPos,
rightStick.angle(),
Bullet.TYPE.LASER_1);
model.createBullet(bulletPos,
rightStick.angle() + dif,
int extraBullets = 2;
for (int i = 0; i < extraBullets; i++)
{
model.createBullet(bulletPos,
rightStick.angle() + dif*(i+1),
Bullet.TYPE.LASER_1);
model.createBullet(bulletPos,
rightStick.angle() - dif,
model.createBullet(bulletPos,
rightStick.angle() - dif*(i+1),
Bullet.TYPE.LASER_1);

}

cooldown = COOLDOWN_MAX;
}

Expand Down Expand Up @@ -326,7 +321,7 @@ public void kill(WorldModel model)
position.x + width/2,
position.y + height/2),
pAngle,
MathUtils.random(0.5f, 1f)*3f,
MathUtils.random(0.5f, 1.5f),
MathUtils.random(0.6f, 0.8f) * Globals.WIDTH/2,
new Color(MathUtils.random(),
MathUtils.random(),
Expand Down Expand Up @@ -354,7 +349,7 @@ public void kill(WorldModel model)
model.createParticle(
pos,
pAngle,
MathUtils.random(0.6f, 1.5f)*3f,
MathUtils.random(0.6f, 2f),
MathUtils.random(0.6f, 0.8f) * Globals.WIDTH,
new Color(MathUtils.random(),
MathUtils.random(),
Expand All @@ -368,6 +363,6 @@ public void kill(WorldModel model)
}

}
model.applyRadialForce(getMid(), -64000, model.WORLD_WIDTH);
model.applyRadialForce(getMid(), 64000, model.WORLD_WIDTH);
}
}
4 changes: 2 additions & 2 deletions core/src/com/golddaniel/main/AudioSystem.java
Expand Up @@ -19,7 +19,7 @@
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.utils.ArrayMap;
import gold.daniel.level.Level;
import gold.daniel.level.LevelModel;

/**
*
Expand All @@ -31,7 +31,7 @@ public class AudioSystem implements MessageListener
private static float MUSIC_VOLUME = 0.3f;
private static float SFX_VOLUME = 1f;

public void update(Level level)
public void update(LevelModel level)
{
}

Expand Down
6 changes: 2 additions & 4 deletions core/src/com/golddaniel/main/CollisionSystem.java
Expand Up @@ -21,18 +21,16 @@
import com.golddaniel.entities.Bullet;
import com.golddaniel.entities.Player;
import com.golddaniel.entities.Boid;
import gold.daniel.level.Level;

/**
*
* @author wrksttn
*/
public class CollisionSystem
{
public void update(Level level)
public void update(WorldModel model)
{
WorldModel model = level.getModel();

if(model == null) return;
Array<Bullet> bullets = model.getEntityType(Bullet.class);
Array<Bouncer> bouncers = model.getEntityType(Bouncer.class);
Array<Boid> boids = model.getEntityType(Boid.class);
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/golddaniel/main/ControllerManager.java
Expand Up @@ -65,7 +65,7 @@ public void disconnected(Controller cntrlr)
@Override
public boolean buttonDown(Controller cntrlr, int i)
{

System.out.println(i);
return true;
}

Expand Down

0 comments on commit 1c938a2

Please sign in to comment.