more effects, pretty logic, optimization

This commit is contained in:
Daniel
2024-10-20 03:48:44 +03:00
parent 967db15be3
commit 44b9cf0263
16 changed files with 701 additions and 22 deletions

159
assets/particles/hit.p Normal file
View File

@@ -0,0 +1,159 @@
Glitch
- Delay -
active: false
- Duration -
lowMin: 2.0
lowMax: 2.0
- Count -
min: 0
max: 200
- Emission -
lowMin: 0.0
lowMax: 0.0
highMin: 14.0
highMax: 14.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Life -
lowMin: 0.0
lowMax: 0.0
highMin: 500.0
highMax: 500.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
independent: false
- Life Offset -
active: false
independent: false
- X Offset -
active: true
lowMin: -3.0
lowMax: 3.0
highMin: 0.0
highMax: 0.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Y Offset -
active: true
lowMin: -3.0
lowMax: 3.0
highMin: 0.0
highMax: 0.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Spawn Shape -
shape: point
- Spawn Width -
lowMin: 0.0
lowMax: 0.0
highMin: 0.0
highMax: 0.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Spawn Height -
lowMin: 0.0
lowMax: 0.0
highMin: 0.0
highMax: 0.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- X Scale -
lowMin: 0.0
lowMax: 0.0
highMin: 200.0
highMax: 200.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Y Scale -
active: false
- Velocity -
active: false
- Angle -
active: false
- Rotation -
active: false
- Wind -
active: false
- Gravity -
active: false
- Tint -
colorsCount: 27
colors0: 1.0
colors1: 0.047058824
colors2: 0.047058824
colors3: 1.0
colors4: 0.69411767
colors5: 0.047058824
colors6: 0.95686275
colors7: 1.0
colors8: 0.047058824
colors9: 0.047058824
colors10: 1.0
colors11: 0.09019608
colors12: 0.047058824
colors13: 0.9254902
colors14: 1.0
colors15: 0.047058824
colors16: 0.11764706
colors17: 1.0
colors18: 0.4509804
colors19: 0.047058824
colors20: 1.0
colors21: 1.0
colors22: 0.047058824
colors23: 0.972549
colors24: 1.0
colors25: 0.047058824
colors26: 0.047058824
timelineCount: 9
timeline0: 0.0
timeline1: 0.16351119
timeline2: 0.2616179
timeline3: 0.38554215
timeline4: 0.51979345
timeline5: 0.6506024
timeline6: 0.7555938
timeline7: 0.8915663
timeline8: 1.0
- Transparency -
lowMin: 0.0
lowMax: 0.0
highMin: 1.0
highMax: 1.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Options -
attached: true
continuous: false
aligned: false
additive: true
behind: false
premultipliedAlpha: false
spriteMode: single
- Image Paths -
hit.png

BIN
assets/particles/hit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

159
assets/particles/logo.p Normal file
View File

@@ -0,0 +1,159 @@
Glitch
- Delay -
active: false
- Duration -
lowMin: 50.0
lowMax: 50.0
- Count -
min: 0
max: 200
- Emission -
lowMin: 20.0
lowMax: 20.0
highMin: 50.0
highMax: 50.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Life -
lowMin: 50.0
lowMax: 50.0
highMin: 500.0
highMax: 500.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
independent: false
- Life Offset -
active: false
independent: false
- X Offset -
active: true
lowMin: -3.0
lowMax: 3.0
highMin: 0.0
highMax: 0.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Y Offset -
active: true
lowMin: -3.0
lowMax: 3.0
highMin: 0.0
highMax: 0.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Spawn Shape -
shape: point
- Spawn Width -
lowMin: 0.0
lowMax: 0.0
highMin: 0.0
highMax: 0.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Spawn Height -
lowMin: 0.0
lowMax: 0.0
highMin: 0.0
highMax: 0.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- X Scale -
lowMin: 0.0
lowMax: 0.0
highMin: 200.0
highMax: 200.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Y Scale -
active: false
- Velocity -
active: false
- Angle -
active: false
- Rotation -
active: false
- Wind -
active: false
- Gravity -
active: false
- Tint -
colorsCount: 27
colors0: 1.0
colors1: 0.047058824
colors2: 0.047058824
colors3: 1.0
colors4: 0.69411767
colors5: 0.047058824
colors6: 0.95686275
colors7: 1.0
colors8: 0.047058824
colors9: 0.047058824
colors10: 1.0
colors11: 0.09019608
colors12: 0.047058824
colors13: 0.9254902
colors14: 1.0
colors15: 0.047058824
colors16: 0.11764706
colors17: 1.0
colors18: 0.4509804
colors19: 0.047058824
colors20: 1.0
colors21: 1.0
colors22: 0.047058824
colors23: 0.972549
colors24: 1.0
colors25: 0.047058824
colors26: 0.047058824
timelineCount: 9
timeline0: 0.0
timeline1: 0.16351119
timeline2: 0.2616179
timeline3: 0.38554215
timeline4: 0.51979345
timeline5: 0.6506024
timeline6: 0.7555938
timeline7: 0.8915663
timeline8: 1.0
- Transparency -
lowMin: 0.0
lowMax: 0.0
highMin: 1.0
highMax: 1.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Options -
attached: true
continuous: false
aligned: false
additive: true
behind: false
premultipliedAlpha: false
spriteMode: single
- Image Paths -
logo.png

BIN
assets/particles/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -3,19 +3,25 @@ package org.lumijiez.bugger;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import org.lumijiez.bugger.entities.Player; import org.lumijiez.bugger.entities.Player;
import org.lumijiez.bugger.handlers.*; import org.lumijiez.bugger.handlers.*;
public class Bugger { public class Bugger {
public static float deltaTime = 0f;
private static Bugger instance; private static Bugger instance;
private final World world = new World(new Vector2(0, 0), true); private final World world = new World(new Vector2(0, 0), true);
private final Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer(); private final Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();
public static ShapeRenderer shapeRenderer = new ShapeRenderer();
public static SpriteBatch spriteBatch = new SpriteBatch(); public static SpriteBatch spriteBatch = new SpriteBatch();
public static SpriteBatch uiBatch = new SpriteBatch(); public static SpriteBatch uiBatch = new SpriteBatch();
public static int kills = 0; public static int kills = 0;
private boolean logoPlayed = false;
private Bugger() { private Bugger() {
Player.getInstance().setPlayer(world, 100, 100); Player.getInstance().setPlayer(world, 100, 100);
@@ -30,12 +36,14 @@ public class Bugger {
} }
public void cycle(float delta) { public void cycle(float delta) {
deltaTime = delta;
renderClear(); renderClear();
SpaceVFXHandler.getInstance().render(); SpaceVFXHandler.getInstance().render();
step(); step();
ProjectileHandler.getInstance().cycle(delta); ProjectileHandler.getInstance().cycle(delta);
EnemyProjectileHandler.getInstance().cycle(delta);
EnemyHandler.getInstance().cycle(); EnemyHandler.getInstance().cycle();
ParticleHandler.getInstance().cycle(delta); ParticleHandler.getInstance().cycle(delta);

View File

@@ -2,6 +2,7 @@ package org.lumijiez.bugger.entities;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.box2d.*; import com.badlogic.gdx.physics.box2d.*;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
@@ -9,9 +10,13 @@ import org.lumijiez.bugger.Bugger;
import org.lumijiez.bugger.entities.weapons.Ray; import org.lumijiez.bugger.entities.weapons.Ray;
import org.lumijiez.bugger.handlers.CameraHandler; import org.lumijiez.bugger.handlers.CameraHandler;
import static org.lumijiez.bugger.Bugger.shapeRenderer;
public class Player extends Entity { public class Player extends Entity {
private static Player instance; private static Player instance;
private int health = 1000;
private Player() { private Player() {
super(null, "images/wasp.png", 10f); super(null, "images/wasp.png", 10f);
} }
@@ -49,6 +54,7 @@ public class Player extends Entity {
public void setPlayer(World world, float x, float y) { public void setPlayer(World world, float x, float y) {
this.world = world; this.world = world;
this.body = createBody(x, y); this.body = createBody(x, y);
this.body.setUserData(this);
} }
public void move(float deltaX, float deltaY) { public void move(float deltaX, float deltaY) {
@@ -61,6 +67,7 @@ public class Player extends Entity {
handleInput(); handleInput();
updateSpriteRotation(); updateSpriteRotation();
super.render(); super.render();
renderHealthBar();
} }
public void handleInput() { public void handleInput() {
@@ -87,4 +94,29 @@ public class Player extends Entity {
body.setTransform(body.getPosition(), angle * (float) Math.PI / 180f); body.setTransform(body.getPosition(), angle * (float) Math.PI / 180f);
sprite.setRotation(body.getAngle() * (180f / (float) Math.PI)); sprite.setRotation(body.getAngle() * (180f / (float) Math.PI));
} }
public void damage(int damage) {
health -= damage;
}
public int getHealth() {
return health;
}
private void renderHealthBar() {
float maxHealth = 1000f;
float healthPercentage = Math.max(health / maxHealth, 0);
float healthBarWidth = 8f;
float healthBarHeight = 1f;
float healthBarX = body.getPosition().x - healthBarWidth / 2;
float healthBarY = body.getPosition().y + size - 17;
shapeRenderer.setProjectionMatrix(CameraHandler.getInstance().getCamera().combined);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(1, 0, 0, 1);
shapeRenderer.rect(healthBarX, healthBarY, healthBarWidth * healthPercentage, healthBarHeight);
shapeRenderer.end();
}
} }

View File

@@ -5,8 +5,12 @@ import com.badlogic.gdx.physics.box2d.World;
import org.lumijiez.bugger.Bugger; import org.lumijiez.bugger.Bugger;
import org.lumijiez.bugger.entities.Entity; import org.lumijiez.bugger.entities.Entity;
import org.lumijiez.bugger.entities.Player; import org.lumijiez.bugger.entities.Player;
import org.lumijiez.bugger.handlers.EnemyProjectileHandler;
import org.lumijiez.bugger.handlers.ProjectileHandler;
public class EnemyEntity extends Entity { public class EnemyEntity extends Entity {
private float shootTimer = 0.0f;
public EnemyEntity(World world, String texturePath, float size) { public EnemyEntity(World world, String texturePath, float size) {
super(world, texturePath, size); super(world, texturePath, size);
} }
@@ -27,6 +31,14 @@ public class EnemyEntity extends Entity {
float angle = direction.angleDeg() + 270f; float angle = direction.angleDeg() + 270f;
body.setTransform(body.getPosition(), angle * (float) Math.PI / 180f); body.setTransform(body.getPosition(), angle * (float) Math.PI / 180f);
shootTimer += Bugger.deltaTime;
float shootCooldown = 2.0f;
if (shootTimer >= shootCooldown) {
EnemyProjectileHandler.getInstance().shootEnemyProjectile(this.body.getPosition(), playerPos, 50f);
shootTimer = 0.0f;
}
} }
public void cycle(Vector2 target) { public void cycle(Vector2 target) {

View File

@@ -0,0 +1,75 @@
package org.lumijiez.bugger.entities.weapons;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import org.lumijiez.bugger.entities.Entity;
public abstract class EnemyProjectile extends Entity {
protected float timeAlive = 0f;
protected boolean isEnemy = false;
public EnemyProjectile(World world, String texturePath, float size, boolean isEnemy) {
super(world, texturePath, size);
this.isEnemy = isEnemy;
this.body = createBody(0, 0);
}
public EnemyProjectile(World world, Vector2 position, Vector2 direction, String texturePath, float size) {
super(world, texturePath, size);
Vector2 offsetPosition = position.cpy().add(direction.nor().scl(size + 1f));
this.body = createBody(offsetPosition.x, offsetPosition.y);
this.body.setTransform(offsetPosition, (float) (direction.angleRad() + Math.toRadians(270f)));
this.body.setLinearVelocity(direction.nor().scl(5000f));
}
public EnemyProjectile(World world, Vector2 position, Vector2 direction, String texturePath, float size, float speed) {
super(world, texturePath, size);
Vector2 offsetPosition = position.cpy().add(direction.nor().scl(size + 1f));
this.body = createBody(offsetPosition.x, offsetPosition.y);
this.body.setTransform(offsetPosition, (float) (direction.angleRad() + Math.toRadians(270f)));
this.body.setLinearVelocity(direction.nor().scl(speed));
}
@Override
protected Body createBody(float x, float y) {
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(x, y);
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.gravityScale = 0;
Body body = world.createBody(bodyDef);
PolygonShape shape = new PolygonShape();
shape.setAsBox(size / 3, size + 2);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.isSensor = true;
body.createFixture(fixtureDef);
shape.dispose();
return body;
}
public void update(float delta) {
timeAlive += delta;
float lifetime = 3f;
if (timeAlive >= lifetime) {
markedToDestroy = true;
}
}
public boolean isEnemy() {
return isEnemy;
}
public void render() {
super.render();
}
@Override
public void destroy() {
markedToDestroy = true;
}
}

View File

@@ -0,0 +1,50 @@
package org.lumijiez.bugger.entities.weapons;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import org.lumijiez.bugger.Bugger;
public class EnemyRay extends EnemyProjectile {
float speed = 5000f;
public EnemyRay(World world, boolean isEnemy) {
super(world,"images/enemyblaze.png", 5f, isEnemy);
}
public EnemyRay(World world, Vector2 position, Vector2 direction) {
super(world, position, direction, "images/enemyblaze.png", 5f);
this.body.setUserData(this);
}
public EnemyRay(World world, Vector2 position, Vector2 direction, float speed) {
super(world, position, direction, "images/enemyblaze.png", 5f, speed);
this.speed = speed;
this.body.setUserData(this);
}
public void init(Vector2 position, Vector2 direction, boolean isEnemy) {
this.isEnemy = isEnemy;
this.body.setTransform(position, (float) (direction.angleRad() + Math.toRadians(270f)));
this.body.setLinearVelocity(direction.nor().scl(speed));
this.body.setUserData(this);
}
public void reset() {
timeAlive = 0f;
markedToDestroy = false;
this.isEnemy = false;
this.body.setLinearVelocity(Vector2.Zero);
this.body.setTransform(Vector2.Zero, 0f);
}
@Override
public void render() {
sprite.setOrigin(size / 2, size / 2);
sprite.setSize(size, size + 5);
sprite.setPosition(body.getPosition().x - size / 2, body.getPosition().y - size / 2);
sprite.setRotation(body.getAngle() * (180f / (float) Math.PI));
Bugger.spriteBatch.begin();
sprite.draw(Bugger.spriteBatch);
Bugger.spriteBatch.end();
}
}

View File

@@ -7,9 +7,11 @@ import org.lumijiez.bugger.entities.Entity;
public abstract class Projectile extends Entity { public abstract class Projectile extends Entity {
protected float timeAlive = 0f; protected float timeAlive = 0f;
protected boolean isEnemy = false;
public Projectile(World world, String texturePath, float size) { public Projectile(World world, String texturePath, float size, boolean isEnemy) {
super(world, texturePath, size); super(world, texturePath, size);
this.isEnemy = isEnemy;
this.body = createBody(0, 0); this.body = createBody(0, 0);
} }
@@ -58,6 +60,10 @@ public abstract class Projectile extends Entity {
} }
} }
public boolean isEnemy() {
return isEnemy;
}
public void render() { public void render() {
super.render(); super.render();
} }

View File

@@ -7,9 +7,8 @@ import org.lumijiez.bugger.Bugger;
public class Ray extends Projectile { public class Ray extends Projectile {
float speed = 5000f; float speed = 5000f;
public Ray(World world) { public Ray(World world, boolean isEnemy) {
super(world,"images/blaze.png", 5f); super(world,"images/blaze.png", 5f, isEnemy);
this.body.setUserData(this);
} }
public Ray(World world, Vector2 position, Vector2 direction) { public Ray(World world, Vector2 position, Vector2 direction) {
@@ -23,14 +22,17 @@ public class Ray extends Projectile {
this.body.setUserData(this); this.body.setUserData(this);
} }
public void init(Vector2 position, Vector2 direction) { public void init(Vector2 position, Vector2 direction, boolean isEnemy) {
this.isEnemy = isEnemy;
this.body.setTransform(position, (float) (direction.angleRad() + Math.toRadians(270f))); this.body.setTransform(position, (float) (direction.angleRad() + Math.toRadians(270f)));
this.body.setLinearVelocity(direction.nor().scl(speed)); this.body.setLinearVelocity(direction.nor().scl(speed));
this.body.setUserData(this);
} }
public void reset() { public void reset() {
timeAlive = 0f; timeAlive = 0f;
markedToDestroy = false; markedToDestroy = false;
this.isEnemy = false;
this.body.setLinearVelocity(Vector2.Zero); this.body.setLinearVelocity(Vector2.Zero);
this.body.setTransform(Vector2.Zero, 0f); this.body.setTransform(Vector2.Zero, 0f);
} }

View File

@@ -5,7 +5,6 @@ import com.badlogic.gdx.utils.Array;
import org.lumijiez.bugger.Bugger; import org.lumijiez.bugger.Bugger;
import org.lumijiez.bugger.entities.Entity; import org.lumijiez.bugger.entities.Entity;
import org.lumijiez.bugger.entities.enemies.EnemyEntity; import org.lumijiez.bugger.entities.enemies.EnemyEntity;
import org.lumijiez.bugger.entities.weapons.Projectile;
import java.util.List; import java.util.List;
@@ -37,7 +36,7 @@ public class CleanupHandler {
// } // }
if (entity instanceof EnemyEntity) { if (entity instanceof EnemyEntity) {
ParticleHandler.getInstance().playEffect(entity.getBody().getPosition().x, entity.getBody().getPosition().y); ParticleHandler.getInstance().playBigBoom(entity.getBody().getPosition().x, entity.getBody().getPosition().y);
enemies.remove(entity); enemies.remove(entity);
} }

View File

@@ -1,8 +1,12 @@
package org.lumijiez.bugger.handlers; package org.lumijiez.bugger.handlers;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.physics.box2d.*; import com.badlogic.gdx.physics.box2d.*;
import org.lumijiez.bugger.Bugger; import org.lumijiez.bugger.Bugger;
import org.lumijiez.bugger.entities.Player;
import org.lumijiez.bugger.entities.enemies.EnemyEntity; import org.lumijiez.bugger.entities.enemies.EnemyEntity;
import org.lumijiez.bugger.entities.weapons.EnemyProjectile;
import org.lumijiez.bugger.entities.weapons.EnemyRay;
import org.lumijiez.bugger.entities.weapons.Ray; import org.lumijiez.bugger.entities.weapons.Ray;
public class CollisionHandler implements ContactListener { public class CollisionHandler implements ContactListener {
@@ -11,14 +15,35 @@ public class CollisionHandler implements ContactListener {
Fixture fixtureA = contact.getFixtureA(); Fixture fixtureA = contact.getFixtureA();
Fixture fixtureB = contact.getFixtureB(); Fixture fixtureB = contact.getFixtureB();
if (isArrow(fixtureA) && isArrow(fixtureB)) { Object userDataA = fixtureA.getBody().getUserData();
return; Object userDataB = fixtureB.getBody().getUserData();
if (isEnemy(fixtureA) && isPlayer(fixtureB)) {
EnemyRay ray = (EnemyRay) userDataA;
if (ray.isEnemy()) {
ray.destroy();
Player.getInstance().damage(50);
ParticleHandler.getInstance().playSmallBoom(Player.getInstance().getPosition().x, Player.getInstance().getPosition().y);
ParticleHandler.getInstance().playHit(Gdx.graphics.getWidth() - 100, Gdx.graphics.getHeight() - 60);
} }
}
if (isEnemy(fixtureB) && isPlayer(fixtureA)) {
EnemyRay ray = (EnemyRay) userDataB;
if (ray.isEnemy()) {
ray.destroy();
Player.getInstance().damage(50);
ParticleHandler.getInstance().playSmallBoom(Player.getInstance().getPosition().x, Player.getInstance().getPosition().y);
ParticleHandler.getInstance().playHit(Gdx.graphics.getWidth() - 100, Gdx.graphics.getHeight() - 60);
}
}
if (isArrow(fixtureA) && isEntity(fixtureB)) { if (isArrow(fixtureA) && isEntity(fixtureB)) {
Ray ray = (Ray) fixtureA.getBody().getUserData(); Ray ray = (Ray) fixtureA.getBody().getUserData();
EnemyEntity enemy = (EnemyEntity) fixtureB.getBody().getUserData(); EnemyEntity enemy = (EnemyEntity) fixtureB.getBody().getUserData();
if (ray != null) { if (ray != null && !ray.isEnemy()) {
Bugger.kills++; Bugger.kills++;
ray.destroy(); ray.destroy();
enemy.destroy(); enemy.destroy();
@@ -28,7 +53,7 @@ public class CollisionHandler implements ContactListener {
if (isArrow(fixtureB) && isEntity(fixtureA)) { if (isArrow(fixtureB) && isEntity(fixtureA)) {
Ray ray = (Ray) fixtureB.getBody().getUserData(); Ray ray = (Ray) fixtureB.getBody().getUserData();
EnemyEntity enemy = (EnemyEntity) fixtureA.getBody().getUserData(); EnemyEntity enemy = (EnemyEntity) fixtureA.getBody().getUserData();
if (ray != null) { if (ray != null && !ray.isEnemy()) {
Bugger.kills++; Bugger.kills++;
ray.destroy(); ray.destroy();
enemy.destroy(); enemy.destroy();
@@ -53,6 +78,14 @@ public class CollisionHandler implements ContactListener {
return fixture.getBody().getUserData() instanceof Ray; return fixture.getBody().getUserData() instanceof Ray;
} }
private boolean isEnemy(Fixture fixture) {
return fixture.getBody().getUserData() instanceof EnemyProjectile;
}
private boolean isPlayer(Fixture fixture) {
return fixture.getBody().getUserData() instanceof Player;
}
private boolean isEntity(Fixture fixture) { private boolean isEntity(Fixture fixture) {
return fixture.getBody().getUserData() instanceof EnemyEntity; return fixture.getBody().getUserData() instanceof EnemyEntity;
} }

View File

@@ -0,0 +1,63 @@
package org.lumijiez.bugger.handlers;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import org.lumijiez.bugger.Bugger;
import org.lumijiez.bugger.entities.Player;
import org.lumijiez.bugger.entities.weapons.EnemyRay;
public class EnemyProjectileHandler {
private final Array<EnemyRay> deployedEnemyProjectiles = new Array<>();
private final Array<EnemyRay> freeEnemyProjectiles = new Array<>();
private static EnemyProjectileHandler instance;
private static final int INITIAL_PROJECTILES = 50;
private EnemyProjectileHandler() {
for (int i = 0; i < INITIAL_PROJECTILES; i++) {
freeEnemyProjectiles.add(new EnemyRay(Bugger.getInstance().getWorld(), true));
}
}
public static EnemyProjectileHandler getInstance() {
if (instance == null) {
instance = new EnemyProjectileHandler();
}
return instance;
}
public void cycle(float delta) {
for (int i = 0; i < deployedEnemyProjectiles.size; i++) {
EnemyRay ray = deployedEnemyProjectiles.get(i);
if (!ray.isMarkedToDestroy()) {
ray.update(delta);
ray.render();
} else {
ray.reset();
freeEnemyProjectiles.add(ray);
deployedEnemyProjectiles.removeIndex(i);
i--;
}
}
}
public void shootEnemyProjectile(Vector2 position, Vector2 direction, float speed) {
EnemyRay projectile;
Vector2 playerPos = Player.getInstance().getPosition();
Vector2 shootDirection = playerPos.cpy().sub(position).nor();
if (freeEnemyProjectiles.size > 0) {
projectile = freeEnemyProjectiles.pop();
} else if (deployedEnemyProjectiles.size > 0) {
projectile = deployedEnemyProjectiles.first();
deployedEnemyProjectiles.removeIndex(0);
} else {
return;
}
projectile.init(position, shootDirection.scl(speed), true);
deployedEnemyProjectiles.add(projectile);
}
}

View File

@@ -5,19 +5,45 @@ import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool; import com.badlogic.gdx.graphics.g2d.ParticleEffectPool;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import org.lumijiez.bugger.Bugger; import org.lumijiez.bugger.Bugger;
import org.lumijiez.bugger.entities.Player;
public class ParticleHandler { public class ParticleHandler {
private static ParticleHandler instance; private static ParticleHandler instance;
private final ParticleEffectPool particleEffectPool; private final ParticleEffectPool bigBoomPool;
private final ParticleEffectPool smallBoomPool;
private final ParticleEffectPool logoPool;
private final ParticleEffectPool hitPool;
private final Array<ParticleEffectPool.PooledEffect> activeEffects; private final Array<ParticleEffectPool.PooledEffect> activeEffects;
private final Array<ParticleEffectPool.PooledEffect> uiEffects;
private final ObjectMap<ParticleEffectPool.PooledEffect, String> effectTypes;
private ParticleHandler() { private ParticleHandler() {
ParticleEffect effect = new ParticleEffect(); ParticleEffect bigBoomEffect = new ParticleEffect();
effect.load(Gdx.files.internal("particles/boom.p"), Gdx.files.internal("particles")); bigBoomEffect.load(Gdx.files.internal("particles/boom.p"), Gdx.files.internal("particles"));
effect.scaleEffect(0.3f); bigBoomEffect.scaleEffect(0.3f);
particleEffectPool = new ParticleEffectPool(effect, 1, 20);
ParticleEffect smallBoomEffect = new ParticleEffect();
smallBoomEffect.load(Gdx.files.internal("particles/boom.p"), Gdx.files.internal("particles"));
smallBoomEffect.scaleEffect(0.1f);
ParticleEffect logoEffect = new ParticleEffect();
logoEffect.load(Gdx.files.internal("particles/logo.p"), Gdx.files.internal("particles"));
logoEffect.scaleEffect(3f);
ParticleEffect hitEffect = new ParticleEffect();
hitEffect.load(Gdx.files.internal("particles/hit.p"), Gdx.files.internal("particles"));
hitEffect.scaleEffect(1.5f);
hitEffect.setDuration(1000);
bigBoomPool = new ParticleEffectPool(bigBoomEffect, 1, 20);
smallBoomPool = new ParticleEffectPool(smallBoomEffect, 1, 20);
logoPool = new ParticleEffectPool(logoEffect, 1, 5);
hitPool = new ParticleEffectPool(hitEffect, 1, 1);
activeEffects = new Array<>(); activeEffects = new Array<>();
uiEffects = new Array<>();
effectTypes = new ObjectMap<>();
} }
public static ParticleHandler getInstance() { public static ParticleHandler getInstance() {
@@ -27,22 +53,66 @@ public class ParticleHandler {
return instance; return instance;
} }
public void playEffect(float x, float y) { public void playBigBoom(float x, float y) {
ParticleEffectPool.PooledEffect newEffect = particleEffectPool.obtain(); ParticleEffectPool.PooledEffect newEffect = bigBoomPool.obtain();
newEffect.setPosition(x, y); newEffect.setPosition(x, y);
newEffect.start(); newEffect.start();
activeEffects.add(newEffect); activeEffects.add(newEffect);
effectTypes.put(newEffect, "bigBoom");
}
public void playSmallBoom(float x, float y) {
ParticleEffectPool.PooledEffect newEffect = smallBoomPool.obtain();
newEffect.setPosition(x, y);
newEffect.start();
activeEffects.add(newEffect);
effectTypes.put(newEffect, "smallBoom");
}
public void playLogo(float x, float y) {
ParticleEffectPool.PooledEffect newEffect = logoPool.obtain();
newEffect.setPosition(x, y);
newEffect.start();
uiEffects.add(newEffect);
effectTypes.put(newEffect, "logoEffect");
}
public void playHit(float x, float y) {
ParticleEffectPool.PooledEffect newEffect = hitPool.obtain();
newEffect.setPosition(x, y);
newEffect.start();
uiEffects.add(newEffect);
effectTypes.put(newEffect, "hitEffect");
} }
public void update(float delta) { public void update(float delta) {
for (int i = activeEffects.size - 1; i >= 0; i--) { for (int i = activeEffects.size - 1; i >= 0; i--) {
ParticleEffectPool.PooledEffect effect = activeEffects.get(i); ParticleEffectPool.PooledEffect effect = activeEffects.get(i);
effect.update(delta); effect.update(delta);
String effectType = effectTypes.get(effect);
if ("bigBoom".equals(effectType)) {
// ToDo
} else if ("smallBoom".equals(effectType)) {
effect.setPosition(Player.getInstance().getPosition().x,
Player.getInstance().getPosition().y);
}
if (effect.isComplete()) { if (effect.isComplete()) {
effect.free(); effect.free();
activeEffects.removeIndex(i); activeEffects.removeIndex(i);
} }
} }
for (int i = uiEffects.size - 1; i >= 0; i--) {
ParticleEffectPool.PooledEffect effect = uiEffects.get(i);
effect.update(delta);
if (effect.isComplete()) {
effect.free();
uiEffects.removeIndex(i);
}
}
} }
public void render(SpriteBatch spriteBatch) { public void render(SpriteBatch spriteBatch) {
@@ -51,11 +121,18 @@ public class ParticleHandler {
effect.draw(spriteBatch); effect.draw(spriteBatch);
Bugger.spriteBatch.end(); Bugger.spriteBatch.end();
} }
for (ParticleEffectPool.PooledEffect effect : uiEffects) {
Bugger.uiBatch.begin();
effect.draw(Bugger.uiBatch);
Bugger.uiBatch.end();
}
} }
public void dispose() { public void dispose() {
for (ParticleEffectPool.PooledEffect effect : activeEffects) { for (ParticleEffectPool.PooledEffect effect : activeEffects) {
effect.free(); effect.free();
effectTypes.remove(effect);
} }
activeEffects.clear(); activeEffects.clear();
} }

View File

@@ -11,13 +11,14 @@ import org.lumijiez.bugger.entities.weapons.Ray;
public class ProjectileHandler { public class ProjectileHandler {
private final Array<Ray> deployedProjectiles = new Array<>(); private final Array<Ray> deployedProjectiles = new Array<>();
private final Array<Ray> freeProjectiles = new Array<>(); private final Array<Ray> freeProjectiles = new Array<>();
private final Array<Ray> deployedEnemyProjectiles = new Array<>();
private final Array<Ray> freeEnemyProjectiles = new Array<>();
private static ProjectileHandler instance; private static ProjectileHandler instance;
private static final int INITIAL_PROJECTILES = 50; private static final int INITIAL_PROJECTILES = 50;
private ProjectileHandler() { private ProjectileHandler() {
for (int i = 0; i < INITIAL_PROJECTILES; i++) { for (int i = 0; i < INITIAL_PROJECTILES; i++) {
freeProjectiles.add(new Ray(Bugger.getInstance().getWorld())); freeProjectiles.add(new Ray(Bugger.getInstance().getWorld(), false));
} }
} }
@@ -50,7 +51,6 @@ public class ProjectileHandler {
float mouseY = Gdx.input.getY(); float mouseY = Gdx.input.getY();
Vector3 mousePosition = CameraHandler.getInstance().getCamera().unproject(new Vector3(mouseX, mouseY, 0)); Vector3 mousePosition = CameraHandler.getInstance().getCamera().unproject(new Vector3(mouseX, mouseY, 0));
Vector2 playerPos = Player.getInstance().getPosition(); Vector2 playerPos = Player.getInstance().getPosition();
direction.set(mousePosition.x, mousePosition.y).sub(playerPos).nor(); direction.set(mousePosition.x, mousePosition.y).sub(playerPos).nor();
@@ -69,11 +69,15 @@ public class ProjectileHandler {
return; return;
} }
projectile.init(position, direction.nor().scl(speed)); projectile.init(position, direction.nor().scl(speed), false);
deployedProjectiles.add(projectile); deployedProjectiles.add(projectile);
} }
public Array<Ray> getDeployedProjectiles() { public Array<Ray> getDeployedProjectiles() {
return deployedProjectiles; return deployedProjectiles;
} }
public Array<Ray> getDeployedEnemyProjectiles() {
return deployedEnemyProjectiles;
}
} }