Skip to content

Commit

Permalink
Merge branch 'Team-4---General-Mobs' into Team-4--General-Mobs-Max
Browse files Browse the repository at this point in the history
  • Loading branch information
max9753 committed Sep 10, 2023
2 parents c2c873c + 72c1ca4 commit 7b27e04
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 62 deletions.
File renamed without changes
File renamed without changes.
Binary file modified source/core/assets/images/terrain_use.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class ForestGameArea extends GameArea {
"images/ghostKing.atlas",
"images/towers/turret.atlas",
"images/towers/turret01.atlas",
"images/xenoGrunt.atlas",
"images/mobs/xenoGrunt.atlas",
"images/mobs/robot.atlas",
"images/mobs/rangeBossRight.atlas",
"images/towers/TNTTower.atlas",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.csse3200.game.components.npc;

import com.badlogic.gdx.graphics.g2d.Animation;
import com.csse3200.game.components.Component;
import com.csse3200.game.rendering.AnimationRenderComponent;

import java.util.Objects;

/**
* This class listens to events relevant to a ghost entity's state and plays the animation when one
* of the events is triggered.
Expand All @@ -14,34 +17,48 @@ public class XenoAnimationController extends Component {
public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener("wanderStart", this::animateWander);
entity.getEvents().addListener("chaseStart", this::animateChase);
entity.getEvents().addListener("wanderStart", this::animateRun);
entity.getEvents().addListener("runHurt", this::animateHurt);
entity.getEvents().addListener("meleeStart", this::animateMelee1);
entity.getEvents().addListener("meleeStart", this::animateMelee2);
entity.getEvents().addListener("shootStart", this::animateShoot);
entity.getEvents().addListener("dieStart", this::animateDie);
entity.getEvents().addListener("stop", this::stopAnimation);
}

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

void animateChase() {
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.csse3200.game.physics.PhysicsEngine;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.raycast.RaycastHit;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.entities.factories.ProjectileFactory;
Expand All @@ -22,9 +23,9 @@ public class MobAttackTask extends DefaultTask implements PriorityTask {
private static final short TARGET = PhysicsLayer.OBSTACLE; // mobs detecting for towers
// ^ fix this

private static final String STOW = "stowStart";
private static final String STOW = "wanderStart";
private static final String DEPLOY = "deployStart";
private static final String FIRING = "firingStart";
private static final String FIRING = "shootStart";
private static final String IDLE = "idleStart";

private final int priority;
Expand Down Expand Up @@ -67,9 +68,8 @@ public void start() {
startTime = timeSource.getTime();
this.mobPosition = owner.getEntity().getCenterPosition();
this.maxRangePosition.set(0, mobPosition.y);
owner.getEntity().getEvents().trigger(IDLE);
//owner.getEntity().getEvents().trigger(IDLE);
endTime = timeSource.getTime() + (INTERVAL * 500);
owner.getEntity().getEvents().trigger("shootStart");
}

/**
Expand Down Expand Up @@ -103,45 +103,46 @@ 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;
}
}

case DEPLOY -> {
// currently deploying,
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(FIRING);
//owner.getEntity().getEvents().trigger(FIRING);
mobState = STATE.FIRING;
} else {
owner.getEntity().getEvents().trigger(STOW);
//owner.getEntity().getEvents().trigger(STOW);
mobState = STATE.STOW;
}
}

case FIRING -> {
// targets gone - stop firing
if (!isTargetVisible()) {
owner.getEntity().getEvents().trigger(STOW);
//owner.getEntity().getEvents().trigger(STOW);
mobState = STATE.STOW;
} else {
owner.getEntity().getEvents().trigger(FIRING);
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);
mobState = STATE.STOW;
owner.getEntity().getEvents().trigger("shootStart");
}
}

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);
//owner.getEntity().getEvents().trigger(IDLE);
mobState = STATE.IDLE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void start() {
this.mobPosition = owner.getEntity().getCenterPosition();
//sets endTime
endTime = timeSource.getTime() + (INTERVAL * 500);
this.owner.getEntity().getEvents().trigger("dieStart");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.csse3200.game.components.tasks;
package com.csse3200.game.components.tasks.human;

import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.DefaultTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.ai.tasks.Task;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.tasks.EngineerCombatTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.components.ColliderComponent;
import com.csse3200.game.physics.components.HitboxComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,19 @@ public static Entity createXenoGrunt(Entity target) {

AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService().getAsset("images/xenoGrunt.atlas", TextureAtlas.class));
ServiceLocator.getResourceService().getAsset("images/mobs/xenoGrunt.atlas", TextureAtlas.class));
animator.addAnimation("xeno_run", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("xeno_shoot", 0.1f, Animation.PlayMode.NORMAL);
animator.addAnimation("xeno_melee_1", 0.1f, Animation.PlayMode.NORMAL);
animator.addAnimation("xeno_melee_2", 0.1f, Animation.PlayMode.NORMAL);
animator.addAnimation("xeno_die", 0.1f, Animation.PlayMode.NORMAL);
animator.addAnimation("xeno_hurt", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("xeno_shoot", 0.1f);
animator.addAnimation("xeno_melee_1", 0.1f);
animator.addAnimation("xeno_melee_2", 0.1f);
animator.addAnimation("xeno_die", 0.1f);
xenoGrunt
.addComponent(new CombatStatsComponent(config.fullHeath, config.baseAttack, drops, melee, projectiles))
.addComponent(animator)
.addComponent(new XenoAnimationController());

xenoGrunt.getComponent(HitboxComponent.class).setAsBoxAligned(new Vector2(.3f, .5f), PhysicsComponent.AlignX.RIGHT, PhysicsComponent.AlignY.BOTTOM);
xenoGrunt.getComponent(AnimationRenderComponent.class).scaleEntity();

return xenoGrunt;
Expand All @@ -148,11 +150,11 @@ public static Entity createBaseNPC(Entity target) {
.addComponent(new PhysicsComponent())
.addComponent(new PhysicsMovementComponent())
.addComponent(new ColliderComponent())
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.NPC))
.addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS, 1.5f))
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.XENO))
.addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS))
.addComponent(aiComponent);

PhysicsUtils.setScaledCollider(npc, 0.9f, 0.4f);
PhysicsUtils.setScaledCollider(npc, 0.3f, 0.5f);
return npc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ public boolean raycast(Vector2 from, Vector2 to, short layerMask, RaycastHit hit
return singleHitCallback.didHit;
}

public Fixture raycastGetHit(Vector2 from, Vector2 to, short layerMask, RaycastHit hit) {
singleHitCallback.didHit = false;
singleHitCallback.layerMask = layerMask;
world.rayCast(singleHitCallback, from, to);
return singleHitCallback.hit.fixture;
}

/**
* Cast a ray in a straight line from one point to another, checking for all collision against
* colliders in the specified layers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class PhysicsLayer {
public static final short PROJECTILE = (1 << 4);
public static final short TOWER = (1 << 5);

public static final short XENO = (1 << 3);
public static final short HUMANS = (1 << 1) | (1 << 5);
public static final short ALL = ~0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void setScaledCollider(Entity entity, float scaleX, float scaleY)
entity
.getComponent(ColliderComponent.class)
.setAsBoxAligned(
boundingBox, PhysicsComponent.AlignX.CENTER, PhysicsComponent.AlignY.BOTTOM);
boundingBox, PhysicsComponent.AlignX.RIGHT, PhysicsComponent.AlignY.BOTTOM);
}

private PhysicsUtils() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
* Contains additional utility constants and functions for common GridPoint2 operations.
*/
public class GridPoint2Utils {
public static final GridPoint2 ZERO = new GridPoint2(0, 4);
public static final GridPoint2 ZERO = new GridPoint2(0, 0);


private GridPoint2Utils() {
throw new IllegalStateException("Instantiating static util class");
}

public static GridPoint2Utils createInstance() {
return new GridPoint2Utils();
}
}
Loading

0 comments on commit 7b27e04

Please sign in to comment.