Skip to content

Commit

Permalink
Modified warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
praneetdhoolia committed Oct 17, 2023
1 parent 2e63eca commit 59f5f15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +30,7 @@ public class WarningComponent extends UIComponent {
TextButton warning;
long spawnTime;
float severity;
GridPoint2 position;
Vector2 position;
boolean toggle = false;

@Override
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 59f5f15

Please sign in to comment.