Skip to content

Commit

Permalink
Merge pull request #157 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 12, 2023
2 parents d3a362c + 97b7b59 commit b0bd5ed
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.csse3200.game.components.npc;


import com.badlogic.gdx.audio.Sound;

import com.csse3200.game.components.Component;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;

import java.util.Objects;
import java.util.Random;

/**
* This class listens to events relevant to a ghost entity's state and plays the animation when one
Expand All @@ -19,15 +17,15 @@ public class XenoAnimationController extends Component {
// Sound onCollisionSound = ServiceLocator.getResourceService().getAsset(
// COLLISION_SFX, Sound.class);
AnimationRenderComponent animator;
Random rand = new Random();

@Override
public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
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("meleeStart", this::animateMelee);
entity.getEvents().addListener("shootStart", this::animateShoot);
entity.getEvents().addListener("dieStart", this::animateDie);
entity.getEvents().addListener("stop", this::stopAnimation);
Expand All @@ -45,12 +43,13 @@ void animateShoot() {
animator.startAnimation("xeno_shoot");
}

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

void animateMelee2() {
animator.startAnimation("xeno_melee_2");
void animateMelee() {
int randAnim = rand.nextInt(2);
if (randAnim == 1) {
animator.startAnimation("xeno_melee_1");
} else {
animator.startAnimation("xeno_melee_2");
}
}

void animateDie() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.csse3200.game.components.xenos;


import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.NPCFactory;
import com.csse3200.game.extensions.GameExtension;
import com.csse3200.game.physics.PhysicsService;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.rendering.DebugRenderer;
import com.csse3200.game.rendering.RenderService;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Objects;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;


@ExtendWith(GameExtension.class)
public class XenoAnimationControllerTest {

private Entity xenoGrunt;
private Entity target;
private final String[] atlas = {"images/mobs/xenoGrunt.atlas"};

@BeforeEach
public void setUp() {
ServiceLocator.registerPhysicsService(new PhysicsService());
RenderService render = new RenderService();
render.setDebug(mock(DebugRenderer.class));
ServiceLocator.registerRenderService(render);
ResourceService resourceService = new ResourceService();
ServiceLocator.registerResourceService(resourceService);
resourceService.loadTextureAtlases(atlas);
resourceService.loadAll();

xenoGrunt = NPCFactory.createXenoGrunt(target); // Replace with actual Droid Tower creation logic
xenoGrunt.create();
}

@Test
public void testAnimateWander() {
xenoGrunt.getEvents().trigger("wanderStart");
assertEquals("xeno_run", xenoGrunt.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateHurt() {
xenoGrunt.getEvents().trigger("runHurt");
assertEquals("xeno_hurt", xenoGrunt.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateMelee1() {
xenoGrunt.getEvents().trigger("meleeStart");
assert(Objects.equals(xenoGrunt.getComponent(AnimationRenderComponent.class).getCurrentAnimation(), "xeno_melee_1")
|| Objects.equals(xenoGrunt.getComponent(AnimationRenderComponent.class).getCurrentAnimation(), "xeno_melee_2"));
}

@Test
public void testAnimateDie() {
xenoGrunt.getEvents().trigger("dieStart");
assertEquals("xeno_die", xenoGrunt.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.csse3200.game.physics.components.ColliderComponent;
import com.csse3200.game.physics.components.HitboxComponent;
import com.csse3200.game.physics.components.PhysicsComponent;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.rendering.DebugRenderer;
import com.csse3200.game.rendering.RenderService;
Expand All @@ -30,12 +31,12 @@ public class NPCFactoryTest {
private Entity engineerTarget;
private Entity playerTarget;

private String[] texture = {
private final String[] texture = {
"images/towers/turret_deployed.png",
"images/towers/turret01.png",
"images/towers/wallTower.png"
};
private String[] atlas = {"images/towers/turret01.atlas",
private final String[] atlas = {"images/towers/turret01.atlas",
"images/mobs/xenoGrunt.atlas"};
private static final String[] sounds = {
"sounds/towers/gun_shot_trimmed.mp3",
Expand All @@ -62,7 +63,7 @@ public void setUp() {
ServiceLocator.getResourceService()
.getAsset("images/mobs/xenoGrunt.atlas", TextureAtlas.class);
//playerTarget = PlayerFactory.createPlayer();
towerTarget = TowerFactory.createBaseTower();
//towerTarget = TowerFactory.createBaseTower();
//engineerTarget = EngineerFactory.createEngineer();
xenoGrunt = NPCFactory.createXenoGrunt(playerTarget);
}
Expand Down Expand Up @@ -100,7 +101,14 @@ public void testXenoGruntCombatStatsComponent() {

@Test
public void xenoGruntHasAnimationComponent() {
assertNotNull(xenoGrunt.getComponent(AnimationRenderComponent.class));
assertNotNull(xenoGrunt.getComponent(AnimationRenderComponent.class),
"Xeno Grunt should have AnimationRenderComponent");
}

@Test
public void testCreateXenoGruntHasPhysicsMovementComponent() {
assertNotNull(xenoGrunt.getComponent(PhysicsMovementComponent.class),
"Xeno Grunt should have PhysicsMovementComponent");
}

}

0 comments on commit b0bd5ed

Please sign in to comment.