Skip to content

Commit

Permalink
Added WarningTask, WarningComponent and WarningFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
praneetdhoolia committed Oct 16, 2023
1 parent 3fea798 commit 54b3df8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.slf4j.LoggerFactory;
import java.util.Timer;

import static com.csse3200.game.entities.factories.WarningFactory.createWarning;
import static com.csse3200.game.screens.AssetLoader.loadAllAssets;

/** Forest area for the demo game with trees, a player, and some enemies. */
Expand Down Expand Up @@ -496,6 +497,7 @@ public void spawnMob(String entity, GridPoint2 randomPos, int health) {
} else {
mob.setScale(1.5f, 1.5f);
}
flashWarning(entity, randomPos);
spawnEntityAt(mob, randomPos, true, false);
}

Expand Down Expand Up @@ -963,5 +965,8 @@ private void spawnGapScanners() {
}
}


private void flashWarning(String mobType, GridPoint2 position) {
Entity warning = WarningFactory.createWarning(mobType, position);
spawnEntity(warning);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.csse3200.game.components.maingame;
package com.csse3200.game.components;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Interpolation;
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.services.ServiceLocator;
import com.csse3200.game.ui.ButtonFactory;
Expand All @@ -16,26 +22,22 @@ public class WarningComponent extends UIComponent {
float severity;
GridPoint2 position;
boolean toggle = false;
public WarningComponent(String mobType, GridPoint2 position) {
System.out.println("Warned");

@Override
public void create() {
super.create();
addActors();
}
public void addActors() {

}
public void config(String mobType, GridPoint2 position) {
this.position = position;
this.spawnTime = ServiceLocator.getTimeSource().getTime();
this.severity = mobType.contains("Boss") ? 5f : 1.5f;
// this.warning = new Label("!", getSkin());
this.warning = ButtonFactory.createButton("Next wave in:"
+ (ServiceLocator.getWaveService().getNextWaveTime() / 1000));
this.warning.setPosition(position.x - 10, position.y);
}
@Override
public void update() {
System.out.println("hi");
if (ServiceLocator.getTimeSource().getTime() > this.spawnTime + 333) {
this.warning.setVisible(toggle);
toggle = !toggle;
}
if (ServiceLocator.getTimeSource().getTime() > this.spawnTime + 2000) {
this.dispose();
}
}
@Override
public void dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WarningFlashTask extends DefaultTask implements PriorityTask {
private static final Logger logger = LoggerFactory.getLogger(WarningFlashTask.class);
public class WarningTask extends DefaultTask implements PriorityTask {
private static final Logger logger = LoggerFactory.getLogger(WarningTask.class);
long startTime;
@Override
public void start() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
package com.csse3200.game.entities.factories;public class WarningFactory {
package com.csse3200.game.entities.factories;

import com.badlogic.gdx.math.GridPoint2;
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) {
WarningComponent warningComponent = new WarningComponent();
warningComponent.config(mobType, position);
return new Entity()
.addComponent(new AITaskComponent().addTask(new WarningTask()))
.addComponent(warningComponent);
}
}

0 comments on commit 54b3df8

Please sign in to comment.