Skip to content

Commit

Permalink
Merge pull request #138 from UQcsse3200/Team-4---General-Mobs
Browse files Browse the repository at this point in the history
Team 4   general mobs
  • Loading branch information
meganroxburgh authored Sep 11, 2023
2 parents 65faa31 + 280bf1c commit b8d88cf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,30 @@ public void create() {
}

void animateRun() {
if (!Objects.equals(animator.getCurrentAnimation(), "xeno_shoot")) {
animator.stopAnimation();
animator.startAnimation("xeno_run");
}
animator.startAnimation("xeno_run");
}

void animateHurt() {
animator.stopAnimation();
animator.startAnimation("xeno_hurt");
}

void animateShoot() {
animator.stopAnimation();
animator.startAnimation("xeno_shoot");
}

void animateMelee1() {
animator.stopAnimation();
animator.startAnimation("xeno_melee_1");
}

void animateMelee2() {
animator.stopAnimation();
animator.startAnimation("xeno_melee_2");
}

void animateDie() {
animator.stopAnimation();
animator.startAnimation("xeno_die");
}

void stopAnimation() {
animator.stopAnimation();
animator.startAnimation("default");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MobAttackTask extends DefaultTask implements PriorityTask {
private static final String STOW = "wanderStart";
private static final String DEPLOY = "deployStart";
private static final String FIRING = "shootStart";
private static final String IDLE = "idleStart";
private static final String IDLE = "stop";

private Fixture target;

Expand Down Expand Up @@ -76,7 +76,7 @@ public void start() {
this.maxRangePosition.set(0, mobPosition.y);
//owner.getEntity().getEvents().trigger(IDLE);
endTime = timeSource.getTime() + (INTERVAL * 500);
owner.getEntity().getEvents().trigger("shootStart");
// owner.getEntity().getEvents().trigger("shootStart");
}

/**
Expand All @@ -102,7 +102,7 @@ public void updateMobState() {
case IDLE -> {
if (isTargetVisible()) {
// targets detected in idle mode - start deployment
owner.getEntity().getEvents().trigger(DEPLOY);
// owner.getEntity().getEvents().trigger(DEPLOY);
mobState = STATE.DEPLOY;
}
}
Expand All @@ -111,33 +111,34 @@ public void updateMobState() {
// currently deploying,
if (isTargetVisible() || this.meleeOrProjectile() != null) {
owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(false);
owner.getEntity().getEvents().trigger(FIRING);
this.owner.getEntity().getEvents().trigger(FIRING);
mobState = STATE.FIRING;
} else {
owner.getEntity().getEvents().trigger(STOW);
this.owner.getEntity().getEvents().trigger(STOW);
mobState = STATE.STOW;
}
}

case FIRING -> {
// targets gone or cannot be attacked - stop firing
if (!isTargetVisible() || this.meleeOrProjectile() == null) {
owner.getEntity().getEvents().trigger(STOW);
this.owner.getEntity().getEvents().trigger(STOW);
mobState = STATE.STOW;
} else {
if (this.meleeOrProjectile() instanceof Melee) {
System.out.println("Melee attack");
TouchAttackComponent attackComp = owner.getEntity().getComponent(TouchAttackComponent.class);
HitboxComponent hitboxComp = owner.getEntity().getComponent(HitboxComponent.class);
attackComp.onCollisionStart(hitboxComp.getFixture(), target);
this.owner.getEntity().getEvents().trigger("meleeStart");
} else {
Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y));
// newProjectile.setScale(-1f, 0.5f);
ServiceLocator.getEntityService().register(newProjectile);

// System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n");
owner.getEntity().getEvents().trigger(FIRING);
this.owner.getEntity().getEvents().trigger(FIRING);
mobState = STATE.STOW;
}
}
Expand All @@ -148,7 +149,7 @@ public void updateMobState() {
case STOW -> {
// currently stowing
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(DEPLOY);
// owner.getEntity().getEvents().trigger(DEPLOY);
mobState = STATE.DEPLOY;
} else {
owner.getEntity().getEvents().trigger(IDLE);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
package com.csse3200.game.components.tasks;

import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.ai.tasks.Task;
import com.csse3200.game.areas.ForestGameArea;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.DropFactory;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.components.ColliderComponent;
import com.csse3200.game.physics.components.HitboxComponent;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.utils.math.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
* Wander around by moving a random position within a range of the starting position. Wait a little
* bit between movements. Requires an entity with a PhysicsMovementComponent.
*/
public class WanderTask extends DefaultTask implements PriorityTask {
private static final Logger logger = LoggerFactory.getLogger(WanderTask.class);
public class MobWanderTask extends DefaultTask implements PriorityTask {
private static final Logger logger = LoggerFactory.getLogger(MobWanderTask.class);

private final Vector2 wanderRange;
private final float waitTime;
Expand All @@ -41,7 +33,7 @@ public class WanderTask extends DefaultTask implements PriorityTask {
* called.
* @param waitTime How long in seconds to wait between wandering.
*/
public WanderTask(Vector2 wanderRange, float waitTime) {
public MobWanderTask(Vector2 wanderRange, float waitTime) {
this.wanderRange = wanderRange;
this.waitTime = waitTime;
}
Expand All @@ -67,7 +59,7 @@ public void start() {
currentTask = movementTask;


this.owner.getEntity().getEvents().trigger("wanderStart");
// this.owner.getEntity().getEvents().trigger("wanderStart");
}

@Override
Expand All @@ -81,7 +73,7 @@ public void update() {
// This method is the idea of Ahmad who very kindly helped
// with section, massive props to him for his help!
if (!isDead && owner.getEntity().getComponent(CombatStatsComponent.class).isDead()) {
owner.getEntity().getEvents().trigger("dieStart");
this.owner.getEntity().getEvents().trigger("dieStart");
currentTask.stop();
isDead = true;
}
Expand Down Expand Up @@ -115,12 +107,14 @@ else if (!isDead) {

private void startWaiting() {
logger.debug("Starting waiting");
this.owner.getEntity().getEvents().trigger("stop");
swapTask(waitTask);
}

private void startMoving() {
logger.debug("Starting moving");
movementTask.setTarget(getDirection());
this.owner.getEntity().getEvents().trigger("wanderStart");
swapTask(movementTask);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import com.csse3200.game.components.npc.GhostAnimationController;
import com.csse3200.game.components.npc.XenoAnimationController;
import com.csse3200.game.components.tasks.MobAttackTask;
import com.csse3200.game.components.tasks.MobDeathTask;
import com.csse3200.game.components.tasks.WanderTask;
import com.csse3200.game.components.tasks.MobWanderTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.Melee;
import com.csse3200.game.entities.PredefinedWeapons;
Expand Down Expand Up @@ -139,7 +138,7 @@ public static Entity createXenoGrunt(Entity target) {
public static Entity createBaseNPC(Entity target) {
AITaskComponent aiComponent =
new AITaskComponent()
.addTask(new WanderTask(new Vector2(2f, 2f), 2f))
.addTask(new MobWanderTask(new Vector2(2f, 2f), 2f))
.addTask(new MobAttackTask(2, 40));
Entity npc =
new Entity()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.csse3200.game.entities.factories;

import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.AITaskComponent;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.player.InventoryComponent;
import com.csse3200.game.components.player.PlayerActions;
import com.csse3200.game.components.player.PlayerStatsDisplay;
import com.csse3200.game.components.tasks.MobAttackTask;
import com.csse3200.game.components.tasks.SpawnWaveTask;
import com.csse3200.game.components.tasks.WanderTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.configs.PlayerConfig;
import com.csse3200.game.files.FileLoader;
Expand Down
Loading

0 comments on commit b8d88cf

Please sign in to comment.