Skip to content

Commit

Permalink
commit where slow doesn't crash the game
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchan550 committed Oct 10, 2023
1 parent 73fe55d commit 2b8b59c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void create() {
// waves.getEvents().addListener("spawnWave", this::spawnMob);
spawnGregMob(18, 2);
// spawnDemonBoss();
spawnEffectProjectile(new Vector2(5f,2f), PhysicsLayer.HUMANS, 20, new Vector2(1f,1f), ProjectileEffects.STUN, false);
spawnEffectProjectile(new Vector2(10f,2f), PhysicsLayer.NPC, 20, new Vector2(2f,2f), ProjectileEffects.SLOW, false);

spawnScrap();
spawnGapScanners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class EffectComponent extends Component {
private long burnTime;
private long slowTime;
private long stunTime;
private Vector2 initialSpeed;
private static long BURN_TICK = 1000;

public EffectComponent(boolean mob) {
Expand All @@ -56,6 +57,15 @@ public void update() {
}

// apply slow effect
if (mob) {
if (slowFlag) {
Vector2 halfSpeed = new Vector2(target.getComponent(PhysicsMovementComponent.class).getSpeed());
changeSpeed(new Vector2(halfSpeed.x / 2, halfSpeed.y / 2));
} else if (isSlowed) {
changeSpeed(initialSpeed);
isSlowed = false;
}
}
if (slowFlag && !isSlowed) {
slowEffect(2);
} else if (!slowFlag && isSlowed) {
Expand All @@ -82,6 +92,7 @@ public void applyEffect(ProjectileEffects effect, Entity host, Entity target) {
case SLOW -> {
slowFlag = true;
slowTime = gameTime.getTime() + EFFECT_DURATION;
initialSpeed = entity.getComponent(PhysicsMovementComponent.class).getSpeed();
}
case STUN -> {
stunFlag = true;
Expand Down Expand Up @@ -119,6 +130,16 @@ private void slowEffect(int amount) {
}
}

private void changeSpeed(Vector2 speed) {
PhysicsMovementComponent targetPhysics = target.getComponent(
PhysicsMovementComponent.class);
if (targetPhysics == null) {
return;
}
// Set mob speed
targetPhysics.setSpeed(speed);
}

private void stunEffect(boolean stunned) {
isStunned = true;
AITaskComponent targetAI = target.getComponent(AITaskComponent.class);
Expand Down

0 comments on commit 2b8b59c

Please sign in to comment.