diff --git a/android/assets/shaders/glow.fsh b/android/assets/shaders/glow.fsh index a701908..c68efd7 100755 --- a/android/assets/shaders/glow.fsh +++ b/android/assets/shaders/glow.fsh @@ -21,11 +21,11 @@ void main() { sum += texture2D(u_texture, texcoord + vec2(j, i)*0.004) * 0.25; } } - if (texture2D(u_texture, texcoord).r < 0.3) { + if (texture2D(u_texture, texcoord).r * vColor.r < 0.3) { gl_FragColor = vec4(sum * sum * 0.012 + texture2D(u_texture, texcoord)) * vColor; } else { - if (texture2D(u_texture, texcoord).r < 0.5) { + if (texture2D(u_texture, texcoord).r * vColor.r < 0.5) { gl_FragColor = vec4( sum * sum * 0.009 + texture2D(u_texture, texcoord)) * vColor; diff --git a/core/src/zero1hd/polyjet/entity/CollisionDetector.java b/core/src/zero1hd/polyjet/entity/CollisionDetector.java index ad9c493..fcb1917 100755 --- a/core/src/zero1hd/polyjet/entity/CollisionDetector.java +++ b/core/src/zero1hd/polyjet/entity/CollisionDetector.java @@ -4,10 +4,14 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Preferences; import com.badlogic.gdx.assets.AssetManager; 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 zero1hd.polyjet.Polyjet; + public class CollisionDetector { Array firstGroup; Array secondGroup; @@ -16,6 +20,8 @@ public class CollisionDetector { Preferences prefs; //Particle pools; ParticleEffectPool explosionEffectPool; + Array effects = new Array<>(); + Sound explosionSFX; public CollisionDetector(Array firstGroup, Array secondGroup, AssetManager assetManager, Preferences prefs) { this.firstGroup = firstGroup; @@ -37,6 +43,17 @@ public class CollisionDetector { if (fe.getHitZone().overlaps(se.getHitZone())) { Gdx.app.debug("Collision Detector", "Collision between entities: " + fe.getEntityType() + " and " + se.getEntityType()); + //Play FX; + if (fe.playCollideSFX()) { + explosionSFX.play(prefs.getFloat("fx vol"), 1f, (fe.getX()/Polyjet.GAME_AREA_WIDTH)-0.55f); + } + if (fe.playCollidePFX()) { + PooledEffect currentPFX; + currentPFX = explosionEffectPool.obtain(); + currentPFX.setPosition(fe.getX() + fe.getWidth()/2f, fe.getY() + fe.getHeight()/2f); + effects.add(currentPFX); + } + fe.collided(se); se.collided(fe); break; @@ -45,4 +62,27 @@ public class CollisionDetector { } } } + + + /** + * draws the explosion particles where necessecary. + * @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(); + } + } } diff --git a/core/src/zero1hd/polyjet/entity/Entity.java b/core/src/zero1hd/polyjet/entity/Entity.java index 2cfd5ac..1b55953 100755 --- a/core/src/zero1hd/polyjet/entity/Entity.java +++ b/core/src/zero1hd/polyjet/entity/Entity.java @@ -4,6 +4,8 @@ import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.scenes.scene2d.Actor; public abstract class Entity extends Actor { + + /** * Called whenever a collision is detected * @param entity is the entity that hit this one. @@ -28,4 +30,11 @@ public abstract class Entity extends Actor { */ public abstract boolean isDead(); + public boolean playCollidePFX() { + return true; + } + + public boolean playCollideSFX() { + return true; + } } diff --git a/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java b/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java index 4800f3d..38e8cdb 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java +++ b/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java @@ -132,4 +132,14 @@ public class VoidCircle extends Entity implements Poolable { public boolean isDead() { return done; } + + @Override + public boolean playCollidePFX() { + return false; + } + + @Override + public boolean playCollideSFX() { + return false; + } } diff --git a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java index 81f90f7..1689ad9 100755 --- a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java +++ b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java @@ -77,11 +77,16 @@ public class GamePlayArea extends Stage { if (glowShader.getLog().length()!=0) { System.out.println(glowShader.getLog()); } -// blurTarget = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getHeight()/Polyjet.GAME_AREA_HEIGHT, Polyjet.GAME_AREA_WIDTH*Gdx.graphics.getHeight()/Polyjet.GAME_AREA_HEIGHT, false); -// blurTarget = new FrameBuffer(Format.RGBA8888, Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT, false); - fboSize = 4096; + + if (Gdx.graphics.getWidth() < 1024) { + fboSize = 1024; + } else if (Gdx.graphics.getWidth() < 2048) { + fboSize = 2048; + } else { + fboSize = 4096; + } + blurTarget = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false); -// blurTarget = new FrameBuffer(Format.RGBA8888, (int) getCamera().viewportWidth, (int) getCamera().viewportHeight, false); fboRegion = new TextureRegion(blurTarget.getColorBufferTexture()); fboRegion.flip(false, true); @@ -131,6 +136,7 @@ public class GamePlayArea extends Stage { getBatch().setBlendFunction(-1, -1); Gdx.gl20.glBlendFuncSeparate(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA,GL20.GL_ONE, GL20.GL_DST_ALPHA); super.draw(); + collisionDetector.renderParticles(getBatch(), Gdx.graphics.getDeltaTime(), true); blurTarget.end(getViewport().getScreenX(), getViewport().getScreenY(), getViewport().getScreenWidth(), getViewport().getScreenHeight()); getBatch().setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);