From 59f5f1589e02ac8a7530e60c92e6f8339796ce58 Mon Sep 17 00:00:00 2001 From: praneetdhoolia <praneet.dhoolia@gmail.com> Date: Wed, 18 Oct 2023 00:15:00 +1000 Subject: [PATCH] Modified warnings. --- .../csse3200/game/areas/ForestGameArea.java | 8 +++--- .../game/components/WarningComponent.java | 26 ++++++++++++------- .../entities/factories/WarningFactory.java | 5 ++-- 3 files changed, 24 insertions(+), 15 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 81faa459..ca533e94 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -497,8 +497,8 @@ public void spawnMob(String entity, GridPoint2 randomPos, int health) { } else { mob.setScale(1.5f, 1.5f); } - flashWarning(entity, randomPos); spawnEntityAt(mob, randomPos, true, false); + flashWarning(mob); } // * TEMPORARY FOR TESTING @@ -965,8 +965,8 @@ private void spawnGapScanners() { } } - private void flashWarning(String mobType, GridPoint2 position) { - Entity warning = WarningFactory.createWarning(mobType, position); - spawnEntityAt(warning, position, true, true); + private void flashWarning(Entity mob) { + Entity warning = WarningFactory.createWarning(mob); + spawnEntityAt(warning, new GridPoint2(), false, false); } } 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 518a2574..e04fca4d 100644 --- a/source/core/src/main/com/csse3200/game/components/WarningComponent.java +++ b/source/core/src/main/com/csse3200/game/components/WarningComponent.java @@ -6,12 +6,16 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction; 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.areas.terrain.TerrainComponent; +import com.csse3200.game.entities.Entity; import com.csse3200.game.services.GameTime; import com.csse3200.game.services.ResourceService; import com.csse3200.game.services.ServiceLocator; @@ -26,7 +30,7 @@ public class WarningComponent extends UIComponent { TextButton warning; long spawnTime; float severity; - GridPoint2 position; + Vector2 position; boolean toggle = false; @Override @@ -36,26 +40,30 @@ public void create() { } public void addActors() { warning = new TextButton("ENEMY", getSkin()); - warning.pad(20f); + warning.setDisabled(true); warning.addAction(new SequenceAction( Actions.color(new Color(Color.RED)), - Actions.parallel(Actions.fadeOut(2f), Actions.sizeBy(1000, 0, 2f)), + 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)); - + warning.setPosition(Gdx.graphics.getWidth(), position.y); stage.addActor(warning); } - public void config(String mobType, GridPoint2 position) { - this.position = position; - this.severity = mobType.contains("Boss") ? 5f : 1.5f; + public void config(Entity mob) { + this.position = mob.getPosition(); } @Override public void dispose() { this.warning.clear(); super.dispose(); } + private Vector2 convert_coordinates(float x, float y) { + Vector3 entityCoordinates = new Vector3(x, y, 0); + Vector3 entityScreenCoordinate = this.camera.project(entityCoordinates); + Vector2 stageCoordinates = stage.screenToStageCoordinates( + new Vector2(entityScreenCoordinate.x, entityScreenCoordinate.y)); + stage.getViewport().unproject(stageCoordinates); + } @Override protected void draw(SpriteBatch batch) { diff --git a/source/core/src/main/com/csse3200/game/entities/factories/WarningFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/WarningFactory.java index d2d806c9..faee9d41 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/WarningFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/WarningFactory.java @@ -1,15 +1,16 @@ package com.csse3200.game.entities.factories; import com.badlogic.gdx.math.GridPoint2; +import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.AITaskComponent; import com.csse3200.game.components.WarningComponent; import com.csse3200.game.components.tasks.WarningTask; import com.csse3200.game.entities.Entity; public abstract class WarningFactory { - public static Entity createWarning(String mobType, GridPoint2 position) { + public static Entity createWarning(Entity mob) { WarningComponent warningComponent = new WarningComponent(); - warningComponent.config(mobType, position); + warningComponent.config(mob); return new Entity() .addComponent(new AITaskComponent().addTask(new WarningTask())) .addComponent(warningComponent);