added comments; removed collision detector vfx and sfx
This commit is contained in:
parent
439307d619
commit
8f0eedd1c5
@ -4,14 +4,8 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.Preferences;
|
import com.badlogic.gdx.Preferences;
|
||||||
import com.badlogic.gdx.assets.AssetManager;
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
import com.badlogic.gdx.audio.Sound;
|
import com.badlogic.gdx.audio.Sound;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool.PooledEffect;
|
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
import zero1hd.rhythmbullet.RhythmBullet;
|
|
||||||
|
|
||||||
public class CollisionDetector {
|
public class CollisionDetector {
|
||||||
Array<Entity> enemies;
|
Array<Entity> enemies;
|
||||||
Array<Entity> allies;
|
Array<Entity> allies;
|
||||||
@ -19,10 +13,6 @@ public class CollisionDetector {
|
|||||||
AssetManager assets;
|
AssetManager assets;
|
||||||
Preferences prefs;
|
Preferences prefs;
|
||||||
|
|
||||||
//Particle pools;
|
|
||||||
ParticleEffectPool explosionEffectPool;
|
|
||||||
Array<PooledEffect> effects = new Array<>();
|
|
||||||
|
|
||||||
private int amassedPoints;
|
private int amassedPoints;
|
||||||
Sound explosionSFX;
|
Sound explosionSFX;
|
||||||
public CollisionDetector(Array<Entity> enemies, Array<Entity> allies, AssetManager assetManager, Preferences prefs) {
|
public CollisionDetector(Array<Entity> enemies, Array<Entity> allies, AssetManager assetManager, Preferences prefs) {
|
||||||
@ -31,8 +21,6 @@ public class CollisionDetector {
|
|||||||
assets = assetManager;
|
assets = assetManager;
|
||||||
this.prefs = prefs;
|
this.prefs = prefs;
|
||||||
|
|
||||||
explosionEffectPool = new ParticleEffectPool(assets.get("explosion-s.p", ParticleEffect.class), 1, 64);
|
|
||||||
explosionSFX = assets.get("explosion.ogg", Sound.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collisionCheck() {
|
public void collisionCheck() {
|
||||||
@ -46,17 +34,6 @@ public class CollisionDetector {
|
|||||||
if (enemy.getHitZone().overlaps(ally.getHitZone())) {
|
if (enemy.getHitZone().overlaps(ally.getHitZone())) {
|
||||||
Gdx.app.debug("Collision Detector", "Collision between entities: " + enemy.getClass().getSimpleName() + " and " + ally.getClass().getSimpleName());
|
Gdx.app.debug("Collision Detector", "Collision between entities: " + enemy.getClass().getSimpleName() + " and " + ally.getClass().getSimpleName());
|
||||||
|
|
||||||
//Play FX;
|
|
||||||
if (ally.playCollideSFX() && enemy.playCollideSFX()) {
|
|
||||||
explosionSFX.play(prefs.getFloat("fx vol")/100f, 1f, (enemy.getX()/RhythmBullet.GAME_AREA_WIDTH));
|
|
||||||
}
|
|
||||||
if (ally.playCollidePFX() && enemy.playCollidePFX()) {
|
|
||||||
PooledEffect currentPFX;
|
|
||||||
currentPFX = explosionEffectPool.obtain();
|
|
||||||
currentPFX.setPosition(ally.getX() + ally.getWidth()/2f, ally.getY() + ally.getHeight()/2f);
|
|
||||||
effects.add(currentPFX);
|
|
||||||
}
|
|
||||||
|
|
||||||
enemy.collided(ally);
|
enemy.collided(ally);
|
||||||
ally.collided(enemy);
|
ally.collided(enemy);
|
||||||
|
|
||||||
@ -71,28 +48,6 @@ public class CollisionDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* draws the explosion particles where necessary.
|
|
||||||
* @param batch the batch used to draw the said particles
|
|
||||||
* @param cleanBatch whether this method should call begin and end on the batch.
|
|
||||||
*/
|
|
||||||
public void renderParticles(Batch batch, float delta, boolean cleanBatch) {
|
|
||||||
if (cleanBatch) {
|
|
||||||
batch.begin();
|
|
||||||
}
|
|
||||||
for (int i = 0; i < effects.size; i++) {
|
|
||||||
effects.get(i).draw(batch, delta);
|
|
||||||
if (effects.get(i).isComplete()) {
|
|
||||||
effects.get(i).free();
|
|
||||||
effects.removeIndex(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cleanBatch) {
|
|
||||||
batch.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAmassedPoints() {
|
public int getAmassedPoints() {
|
||||||
int amassedPoints = this.amassedPoints;
|
int amassedPoints = this.amassedPoints;
|
||||||
this.amassedPoints = 0;
|
this.amassedPoints = 0;
|
||||||
|
@ -125,14 +125,6 @@ public class Entity extends Actor implements Poolable {
|
|||||||
super.draw(batch, parentAlpha);
|
super.draw(batch, parentAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean playCollidePFX() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean playCollideSFX() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void move(float delta, boolean update) {
|
public void move(float delta, boolean update) {
|
||||||
rotRatios.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
|
rotRatios.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
|
||||||
moveBy(rotRatios.x*speed*delta, rotRatios.y*speed*delta);
|
moveBy(rotRatios.x*speed*delta, rotRatios.y*speed*delta);
|
||||||
|
@ -5,6 +5,11 @@ import com.badlogic.gdx.utils.Pool.Poolable;
|
|||||||
import zero1hd.rhythmbullet.entity.Entity;
|
import zero1hd.rhythmbullet.entity.Entity;
|
||||||
import zero1hd.rhythmbullet.entity.EntityManager;
|
import zero1hd.rhythmbullet.entity.EntityManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coordinator coordinates movement of an entity. Movement can range from basic pre-determined to more advanced (with condition based behavior).
|
||||||
|
* @author Yunyang
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Coordinator implements Poolable {
|
public class Coordinator implements Poolable {
|
||||||
private CoordinatorFrame<? extends Coordinator> cf;
|
private CoordinatorFrame<? extends Coordinator> cf;
|
||||||
protected EntityManager em;
|
protected EntityManager em;
|
||||||
|
@ -9,6 +9,12 @@ public class CoordinatorFrame<T extends Coordinator> {
|
|||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
CoordinatorFrame<T> cf;
|
CoordinatorFrame<T> cf;
|
||||||
Class<T> coordinatorType;
|
Class<T> coordinatorType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to an entityFrame, however this time, for a coordinator.
|
||||||
|
* @param entityManager
|
||||||
|
* @param classtype
|
||||||
|
*/
|
||||||
public CoordinatorFrame(EntityManager entityManager, Class<T> classtype) {
|
public CoordinatorFrame(EntityManager entityManager, Class<T> classtype) {
|
||||||
this.em = entityManager;
|
this.em = entityManager;
|
||||||
coordinatorType = classtype;
|
coordinatorType = classtype;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user