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);
if (ally.getHitZone() != null) {
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;
if (ally.playCollideSFX() && enemy.playCollideSFX()) {

View File

@ -28,6 +28,7 @@ public class Entity extends Actor implements Poolable {
protected boolean simple = true;
protected boolean nonStnrd = false;
protected boolean move = true;
protected boolean dead;
protected Rectangle hitbox;
protected Sprite sprite;
@ -77,23 +78,8 @@ public class Entity extends Actor implements Poolable {
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() {
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
return true;
}
return false;
return dead;
}
@Override
@ -106,7 +92,7 @@ public class Entity extends Actor implements Poolable {
if (move) {
move(delta, true);
}
if (isDead()) {
if (dead) {
ef.recycleEntity(this);
}
}
@ -114,6 +100,10 @@ public class Entity extends Actor implements Poolable {
if (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);
}
@ -172,6 +162,7 @@ public class Entity extends Actor implements Poolable {
center.set(0, 0);
angle = 0;
speed = 0;
dead = false;
}
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.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
public class Laser extends Entity {
boolean dead;
Sound sfx;
@Override
@ -60,27 +58,12 @@ public class Laser extends Entity {
@Override
public void reset() {
dead = false;
super.reset();
}
@Override
public void collided(Entity entity) {
switch (entity.getEntityType()) {
default:
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.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
public class PolyJetEntity extends Entity {
public float health;
@ -69,6 +68,10 @@ public class PolyJetEntity extends Entity {
moveBy(0, -rate*delta);
}
if (health <= 0) {
dead = true;
}
super.act(delta);
}
@ -79,25 +82,10 @@ public class PolyJetEntity extends Entity {
super.draw(batch, parentAlpha);
}
@Override
public EntityIndex getEntityType() {
return EntityIndex.POLYJET;
}
@Override
public void collided(Entity entity) {
}
@Override
public boolean isDead() {
if (health <= 0) {
return true;
} else {
return false;
}
}
public Rectangle getHitbox() {
return hitbox;
}

View File

@ -8,10 +8,9 @@ import com.badlogic.gdx.math.Rectangle;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
import zero1hd.rhythmbullet.entity.ally.PolyJetEntity;
public class Bar extends Entity {
private boolean dead;
@Override
public void preInit() {
@ -43,18 +42,13 @@ public class Bar extends Entity {
@Override
public void reset() {
dead = false;
super.reset();
}
@Override
public void collided(Entity entity) {
switch (entity.getEntityType()) {
case POLYJET:
if (entity.getClass() == PolyJetEntity.class) {
dead = true;
break;
default:
break;
}
}
@ -63,14 +57,4 @@ public class Bar extends Entity {
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.math.Rectangle;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
import zero1hd.rhythmbullet.entity.ally.Laser;
public class Flake extends Entity {
private float timer;
@ -74,8 +73,11 @@ public class Flake extends Entity {
shards[i].move(delta, true);
}
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
timer = 0;
if (timer <= 0) {
for (int i = 0; i < shards.length; i++) {
shards[i].setSpeed(45f);
}
dead = true;
}
super.act(delta);
@ -89,12 +91,8 @@ public class Flake extends Entity {
@Override
public void collided(Entity entity) {
switch (entity.getEntityType()) {
case LASER:
if (entity.getClass() == Laser.class) {
timer --;
break;
default:
break;
}
}
@ -103,23 +101,6 @@ public class Flake extends Entity {
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
public void reset() {
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.utils.Pool.Poolable;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
public class Pellet extends Entity implements Poolable {
private boolean dead;
@ -47,24 +45,10 @@ public class Pellet extends Entity implements Poolable {
@Override
public void collided(Entity entity) {
switch (entity.getEntityType()) {
default:
dead = true;
break;
}
super.collided(entity);
}
@Override
public EntityIndex getEntityType() {
return EntityIndex.PELLET;
}
@Override
public boolean isDead() {
return dead;
}
@Override
public void reset() {
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.math.Rectangle;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
import zero1hd.rhythmbullet.entity.ally.Laser;
public class Shard extends Entity {
private int hp;
@ -57,8 +56,8 @@ public class Shard extends Entity {
@Override
public void act(float delta) {
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
hp = 0;
if (hp <= 0) {
dead = true;
}
super.act(delta);
}
@ -71,12 +70,8 @@ public class Shard extends Entity {
@Override
public void collided(Entity entity) {
switch (entity.getEntityType()) {
case LASER:
hp--;
break;
default:
break;
if (entity.getClass() == Laser.class) {
hp --;
}
}
@ -85,16 +80,4 @@ public class Shard extends Entity {
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 zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityIndex;
public class VoidCircle extends Entity {
private float timer;
private float endRadius;
private float currentRadius;
private float growthRate;
private boolean done;
private boolean begin;
private float maxTime;
private Sound sound;
@ -75,7 +73,7 @@ public class VoidCircle extends Entity {
if (currentRadius > 0) {
growCurrentRadius(delta*-growthRate);
} else {
done = true;
dead = true;
}
}
}
@ -90,7 +88,6 @@ public class VoidCircle extends Entity {
timer = 0;
maxTime = 0;
endRadius = 0;
done = false;
begin = false;
setSize(0, 0);
super.reset();
@ -102,25 +99,9 @@ public class VoidCircle extends Entity {
hitbox.setSize(length, length);
}
@Override
public EntityIndex getEntityType() {
return EntityIndex.VOID_CIRCLE;
}
@Override
public void collided(Entity entity) {
switch (entity.getEntityType()) {
case LASER:
sound.play(prefs.getFloat("fx vol"));
break;
default:
break;
}
}
@Override
public boolean isDead() {
return done;
}
@Override

View File

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