better integration with new entity system

This commit is contained in:
Harrison Deng 2017-08-02 23:30:29 -05:00
parent 928f85f709
commit 89ecbb6f4d
11 changed files with 32 additions and 185 deletions

View File

@ -43,7 +43,7 @@ public class CollisionDetector {
Entity ally = allies.get(s); Entity ally = allies.get(s);
if (ally.getHitZone() != null) { if (ally.getHitZone() != null) {
if (enemy.getHitZone().overlaps(ally.getHitZone())) { if (enemy.getHitZone().overlaps(ally.getHitZone())) {
Gdx.app.debug("Collision Detector", "Collision between entities: " + enemy.getEntityType() + " and " + ally.getEntityType()); Gdx.app.debug("Collision Detector", "Collision between entities: " + enemy.getClass().getSimpleName() + " and " + ally.getClass().getSimpleName());
//Play FX; //Play FX;
if (ally.playCollideSFX() && enemy.playCollideSFX()) { if (ally.playCollideSFX() && enemy.playCollideSFX()) {

View File

@ -28,6 +28,7 @@ public class Entity extends Actor implements Poolable {
protected boolean simple = true; protected boolean simple = true;
protected boolean nonStnrd = false; protected boolean nonStnrd = false;
protected boolean move = true; protected boolean move = true;
protected boolean dead;
protected Rectangle hitbox; protected Rectangle hitbox;
protected Sprite sprite; protected Sprite sprite;
@ -77,23 +78,8 @@ public class Entity extends Actor implements Poolable {
return hitbox; return hitbox;
} }
/**
* gets the type of entity this entity is
* @return the entity type
*/
public EntityIndex getEntityType() {
return null;
}
/**
* If this entity's life span is over, it should be considered dead. Useful for knowing what can be freed in a pool scenario.
* @return if this entity is dead or not.
*/
public boolean isDead() { public boolean isDead() {
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { return dead;
return true;
}
return false;
} }
@Override @Override
@ -106,7 +92,7 @@ public class Entity extends Actor implements Poolable {
if (move) { if (move) {
move(delta, true); move(delta, true);
} }
if (isDead()) { if (dead) {
ef.recycleEntity(this); ef.recycleEntity(this);
} }
} }
@ -114,6 +100,10 @@ public class Entity extends Actor implements Poolable {
if (angle >= 360f) { if (angle >= 360f) {
angle -= 360f; angle -= 360f;
} }
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
dead = true;
}
super.act(delta); super.act(delta);
} }
@ -172,6 +162,7 @@ public class Entity extends Actor implements Poolable {
center.set(0, 0); center.set(0, 0);
angle = 0; angle = 0;
speed = 0; speed = 0;
dead = false;
} }
public Vector2 getCenter() { public Vector2 getCenter() {

View File

@ -1,24 +0,0 @@
package zero1hd.rhythmbullet.entity;
import zero1hd.rhythmbullet.entity.ally.Laser;
import zero1hd.rhythmbullet.entity.ally.PolyJetEntity;
import zero1hd.rhythmbullet.entity.enemies.Bar;
import zero1hd.rhythmbullet.entity.enemies.Flake;
import zero1hd.rhythmbullet.entity.enemies.Pellet;
import zero1hd.rhythmbullet.entity.enemies.Shard;
import zero1hd.rhythmbullet.entity.enemies.VoidCircle;
public enum EntityIndex {
POLYJET(PolyJetEntity.class), BAR(Bar.class), VOID_CIRCLE(VoidCircle.class), SHARD(Shard.class), LASER(Laser.class), PELLET(Pellet.class), FLAKE(Flake.class);
private final Class<? extends Entity> classType;
private EntityIndex(Class<? extends Entity> classType) {
this.classType = classType;
}
public Class<? extends Entity> getClassType() {
return classType;
}
}

View File

@ -9,10 +9,8 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
public class Laser extends Entity { public class Laser extends Entity {
boolean dead;
Sound sfx; Sound sfx;
@Override @Override
@ -60,27 +58,12 @@ public class Laser extends Entity {
@Override @Override
public void reset() { public void reset() {
dead = false;
super.reset(); super.reset();
} }
@Override @Override
public void collided(Entity entity) { public void collided(Entity entity) {
switch (entity.getEntityType()) {
default:
dead = true; dead = true;
break;
}
}
@Override
public EntityIndex getEntityType() {
return EntityIndex.LASER;
}
@Override
public boolean isDead() {
return dead;
} }
} }

View File

@ -9,7 +9,6 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
public class PolyJetEntity extends Entity { public class PolyJetEntity extends Entity {
public float health; public float health;
@ -69,6 +68,10 @@ public class PolyJetEntity extends Entity {
moveBy(0, -rate*delta); moveBy(0, -rate*delta);
} }
if (health <= 0) {
dead = true;
}
super.act(delta); super.act(delta);
} }
@ -79,25 +82,10 @@ public class PolyJetEntity extends Entity {
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
} }
@Override
public EntityIndex getEntityType() {
return EntityIndex.POLYJET;
}
@Override @Override
public void collided(Entity entity) { public void collided(Entity entity) {
} }
@Override
public boolean isDead() {
if (health <= 0) {
return true;
} else {
return false;
}
}
public Rectangle getHitbox() { public Rectangle getHitbox() {
return hitbox; return hitbox;
} }

View File

@ -8,10 +8,9 @@ import com.badlogic.gdx.math.Rectangle;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex; import zero1hd.rhythmbullet.entity.ally.PolyJetEntity;
public class Bar extends Entity { public class Bar extends Entity {
private boolean dead;
@Override @Override
public void preInit() { public void preInit() {
@ -43,18 +42,13 @@ public class Bar extends Entity {
@Override @Override
public void reset() { public void reset() {
dead = false;
super.reset(); super.reset();
} }
@Override @Override
public void collided(Entity entity) { public void collided(Entity entity) {
switch (entity.getEntityType()) { if (entity.getClass() == PolyJetEntity.class) {
case POLYJET:
dead = true; dead = true;
break;
default:
break;
} }
} }
@ -63,14 +57,4 @@ public class Bar extends Entity {
return hitbox; return hitbox;
} }
@Override
public EntityIndex getEntityType() {
return EntityIndex.BAR;
}
@Override
public boolean isDead() {
return dead;
}
} }

View File

@ -7,9 +7,8 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex; import zero1hd.rhythmbullet.entity.ally.Laser;
public class Flake extends Entity { public class Flake extends Entity {
private float timer; private float timer;
@ -74,8 +73,11 @@ public class Flake extends Entity {
shards[i].move(delta, true); shards[i].move(delta, true);
} }
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { if (timer <= 0) {
timer = 0; for (int i = 0; i < shards.length; i++) {
shards[i].setSpeed(45f);
}
dead = true;
} }
super.act(delta); super.act(delta);
@ -89,12 +91,8 @@ public class Flake extends Entity {
@Override @Override
public void collided(Entity entity) { public void collided(Entity entity) {
switch (entity.getEntityType()) { if (entity.getClass() == Laser.class) {
case LASER:
timer --; timer --;
break;
default:
break;
} }
} }
@ -103,23 +101,6 @@ public class Flake extends Entity {
return hitbox; return hitbox;
} }
@Override
public EntityIndex getEntityType() {
return EntityIndex.FLAKE;
}
@Override
public boolean isDead() {
if (timer <= 0) {
for (int i = 0; i < shards.length; i++) {
shards[i].setSpeed(45f);
}
return true;
} else {
return false;
}
}
@Override @Override
public void reset() { public void reset() {
timer = 0; timer = 0;

View File

@ -6,9 +6,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.utils.Pool.Poolable; import com.badlogic.gdx.utils.Pool.Poolable;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
public class Pellet extends Entity implements Poolable { public class Pellet extends Entity implements Poolable {
private boolean dead; private boolean dead;
@ -47,24 +45,10 @@ public class Pellet extends Entity implements Poolable {
@Override @Override
public void collided(Entity entity) { public void collided(Entity entity) {
switch (entity.getEntityType()) {
default:
dead = true; dead = true;
break;
}
super.collided(entity); super.collided(entity);
} }
@Override
public EntityIndex getEntityType() {
return EntityIndex.PELLET;
}
@Override
public boolean isDead() {
return dead;
}
@Override @Override
public void reset() { public void reset() {
dead = false; dead = false;

View File

@ -7,9 +7,8 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex; import zero1hd.rhythmbullet.entity.ally.Laser;
public class Shard extends Entity { public class Shard extends Entity {
private int hp; private int hp;
@ -57,8 +56,8 @@ public class Shard extends Entity {
@Override @Override
public void act(float delta) { public void act(float delta) {
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { if (hp <= 0) {
hp = 0; dead = true;
} }
super.act(delta); super.act(delta);
} }
@ -71,12 +70,8 @@ public class Shard extends Entity {
@Override @Override
public void collided(Entity entity) { public void collided(Entity entity) {
switch (entity.getEntityType()) { if (entity.getClass() == Laser.class) {
case LASER: hp --;
hp--;
break;
default:
break;
} }
} }
@ -85,16 +80,4 @@ public class Shard extends Entity {
return hitbox; return hitbox;
} }
@Override
public EntityIndex getEntityType() {
return EntityIndex.SHARD;
}
@Override
public boolean isDead() {
if (hp <= 0) {
return true;
}
return false;
}
} }

View File

@ -7,14 +7,12 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
public class VoidCircle extends Entity { public class VoidCircle extends Entity {
private float timer; private float timer;
private float endRadius; private float endRadius;
private float currentRadius; private float currentRadius;
private float growthRate; private float growthRate;
private boolean done;
private boolean begin; private boolean begin;
private float maxTime; private float maxTime;
private Sound sound; private Sound sound;
@ -75,7 +73,7 @@ public class VoidCircle extends Entity {
if (currentRadius > 0) { if (currentRadius > 0) {
growCurrentRadius(delta*-growthRate); growCurrentRadius(delta*-growthRate);
} else { } else {
done = true; dead = true;
} }
} }
} }
@ -90,7 +88,6 @@ public class VoidCircle extends Entity {
timer = 0; timer = 0;
maxTime = 0; maxTime = 0;
endRadius = 0; endRadius = 0;
done = false;
begin = false; begin = false;
setSize(0, 0); setSize(0, 0);
super.reset(); super.reset();
@ -102,25 +99,9 @@ public class VoidCircle extends Entity {
hitbox.setSize(length, length); hitbox.setSize(length, length);
} }
@Override
public EntityIndex getEntityType() {
return EntityIndex.VOID_CIRCLE;
}
@Override @Override
public void collided(Entity entity) { public void collided(Entity entity) {
switch (entity.getEntityType()) {
case LASER:
sound.play(prefs.getFloat("fx vol")); sound.play(prefs.getFloat("fx vol"));
break;
default:
break;
}
}
@Override
public boolean isDead() {
return done;
} }
@Override @Override

View File

@ -1,7 +1,5 @@
package zero1hd.rhythmbullet.ui.windows; package zero1hd.rhythmbullet.ui.windows;
import java.util.HashMap;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
@ -29,8 +27,6 @@ import zero1hd.rhythmbullet.entity.enemies.VoidCircle;
public class SpawnerWindow extends Window { public class SpawnerWindow extends Window {
private Stage stage; private Stage stage;
private HashMap<String, Float> params = new HashMap<>();
private Array<EntityFrame<? extends Entity>> entityFrames = new Array<>(); private Array<EntityFrame<? extends Entity>> entityFrames = new Array<>();
private List<EntityFrame<? extends Entity>> listOfEntities; private List<EntityFrame<? extends Entity>> listOfEntities;
private ScrollPane entityListScroller; private ScrollPane entityListScroller;