From be41a1d3aa069ce7ae58a560a47818ede3716a82 Mon Sep 17 00:00:00 2001 From: praneetdhoolia Date: Tue, 17 Oct 2023 09:14:03 +1000 Subject: [PATCH] Warning signal effects. --- .../csse3200/game/areas/ForestGameArea.java | 2 +- .../game/components/WarningComponent.java | 20 +++++++++++++++---- .../game/components/tasks/WarningTask.java | 6 +++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 789102b3..81faa459 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -967,6 +967,6 @@ private void spawnGapScanners() { private void flashWarning(String mobType, GridPoint2 position) { Entity warning = WarningFactory.createWarning(mobType, position); - spawnEntity(warning); + spawnEntityAt(warning, position, true, true); } } diff --git a/source/core/src/main/com/csse3200/game/components/WarningComponent.java b/source/core/src/main/com/csse3200/game/components/WarningComponent.java index e4c29fbb..518a2574 100644 --- a/source/core/src/main/com/csse3200/game/components/WarningComponent.java +++ b/source/core/src/main/com/csse3200/game/components/WarningComponent.java @@ -1,6 +1,8 @@ package com.csse3200.game.components; +import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.Interpolation; @@ -9,6 +11,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.csse3200.game.ai.tasks.AITaskComponent; +import com.csse3200.game.services.GameTime; +import com.csse3200.game.services.ResourceService; import com.csse3200.game.services.ServiceLocator; import com.csse3200.game.ui.ButtonFactory; import com.csse3200.game.ui.UIComponent; @@ -16,6 +21,7 @@ import org.slf4j.LoggerFactory; public class WarningComponent extends UIComponent { + long startTime = ServiceLocator.getTimeSource().getTime(); private static final Logger logger = LoggerFactory.getLogger(WarningComponent.class); TextButton warning; long spawnTime; @@ -29,17 +35,23 @@ public void create() { addActors(); } public void addActors() { + warning = new TextButton("ENEMY", getSkin()); + warning.pad(20f); + warning.addAction(new SequenceAction( + Actions.color(new Color(Color.RED)), + Actions.parallel(Actions.fadeOut(2f), Actions.sizeBy(1000, 0, 2f)), + Actions.removeActor())); + warning.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2); + logger.info(String.format("%d, %d", position.x, position.y)); + stage.addActor(warning); } + public void config(String mobType, GridPoint2 position) { this.position = position; - this.spawnTime = ServiceLocator.getTimeSource().getTime(); this.severity = mobType.contains("Boss") ? 5f : 1.5f; } @Override - public void update() { - } - @Override public void dispose() { this.warning.clear(); super.dispose(); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/WarningTask.java b/source/core/src/main/com/csse3200/game/components/tasks/WarningTask.java index dc4ce990..c195f226 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/WarningTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/WarningTask.java @@ -13,15 +13,15 @@ public class WarningTask extends DefaultTask implements PriorityTask { @Override public void start() { super.start(); - logger.info("WarningFlashTask started."); + logger.info("WarningTask started."); startTime = ServiceLocator.getTimeSource().getTime(); } @Override public void update() { owner.getEntity().getComponent(WarningComponent.class).update(); - if (ServiceLocator.getTimeSource().getTime() > startTime + 2000) { - stop(); + if (ServiceLocator.getTimeSource().getTime() > startTime + 5000) { + owner.getEntity().dispose(); } }