Skip to content

Commit

Permalink
Fixing Junit testing within split mobs and wavefactory
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniSoda17 committed Oct 11, 2023
1 parent ba147fa commit 286a953
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public void spawnAdditionalMob(float positionX, float positionY,
Entity waterSlime = NPCFactory.createNightBorne(60);
waterSlime.setPosition(positionX, positionY);

// waterSlime.setScale(initialScaleX * scaleX, initialScaleY * scaleY);
waterSlime.setScale(initialScaleX, initialScaleY);
waterSlime.setScale(initialScaleX * scaleX, initialScaleY * scaleY);
// waterSlime.setScale(initialScaleX, initialScaleY);

ServiceLocator.getEntityService().register(waterSlime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class DemonBossTask extends DefaultTask implements PriorityTask {
private static int xLeftBoundary = 12;
private ProjectileEffects effect = ProjectileEffects.BURN;
private boolean aoe = true;
private Array<Entity> nearbyEntities;

// Flags
private boolean startFlag = false;
Expand Down Expand Up @@ -98,6 +99,7 @@ public void start() {
animation = demon.getComponent(AnimationRenderComponent.class); // get animation
currentPos = demon.getPosition(); // get current position
demon.getComponent(PhysicsMovementComponent.class).setSpeed(DEMON_SPEED); // set speed
demon.getComponent(PhysicsMovementComponent.class).setNormalSpeed(DEMON_SPEED);

Timer.schedule(new Timer.Task() {
@Override
Expand Down Expand Up @@ -166,11 +168,10 @@ public void update() {
case IDLE -> jump(getJumpPos());
case SMASH -> {
if (jumpComplete()) {
if (getNearbyHumans(SMASH_RADIUS).isEmpty()) {
fireBreath();
}
else {
if (nearbyEntities != null && !nearbyEntities.isEmpty()) {
cleave();
} else {
fireBreath();
}
}
}
Expand Down Expand Up @@ -246,34 +247,34 @@ public int getPriority() {
return PRIORITY;
}

/**
* Returns a list of nearby entities with PhysicsLayer.HUMAN.
*
* @return nearby entities with the PhysicsLayer of HUMAN
*/
private Array<Entity> getNearbyHumans(int radius) {
Array<Entity> nearbyEntities = ServiceLocator.getEntityService().
getNearbyEntities(demon, radius);
Array<Entity> nearbyHumans = new Array<>();

// iterate through nearby entities checking if they have desired properties
for (int i = 0; i < nearbyEntities.size; i++) {
Entity targetEntity = nearbyEntities.get(i);
HitboxComponent targetHitbox = targetEntity.getComponent(HitboxComponent.class);
if (targetHitbox == null) {
break;
}

// check target layer
if (!PhysicsLayer.contains(PhysicsLayer.HUMANS, targetHitbox.
getLayer())) {
break;
}

nearbyHumans.add(targetEntity);
}
return nearbyHumans;
}
// /**
// * Returns a list of nearby entities with PhysicsLayer.HUMAN.
// *
// * @return nearby entities with the PhysicsLayer of HUMAN
// */
// private Array<Entity> getNearbyHumans(int radius) {
// Array<Entity> nearbyEntities = ServiceLocator.getEntityService().
// getNearbyEntities(demon, radius);
// Array<Entity> nearbyHumans = new Array<>();
//
// // iterate through nearby entities checking if they have desired properties
// for (int i = 0; i < nearbyEntities.size; i++) {
// Entity targetEntity = nearbyEntities.get(i);
// HitboxComponent targetHitbox = targetEntity.getComponent(HitboxComponent.class);
// if (targetHitbox == null) {
// break;
// }
//
// // check target layer
// if (!PhysicsLayer.contains(PhysicsLayer.HUMANS, targetHitbox.
// getLayer())) {
// break;
// }
//
// nearbyHumans.add(targetEntity);
// }
// return nearbyHumans;
// }

/**
* Changes state of demon and moves it to the desired position.
Expand Down Expand Up @@ -344,12 +345,20 @@ private Vector2 getJumpPos() {
* @return if demon has completed jump or not
*/
private boolean jumpComplete() {
if (currentPos.dst(jumpPos) <= STOP_DISTANCE && isJumping) {
applyAoeDamage(getNearbyHumans(SMASH_RADIUS), SMASH_DAMAGE); // do damage upon landing
if (animation.isFinished() && isJumping) {
nearbyEntities = ServiceLocator.getEntityService().getEntitiesInLayer(
demon, SMASH_RADIUS, PhysicsLayer.HUMANS);
applyAoeDamage(nearbyEntities, SMASH_DAMAGE); // do damage upon landing
isJumping = false;
jumpTask.stop();
return true;
}
// if (currentPos.dst(jumpPos) <= STOP_DISTANCE && isJumping) {
// applyAoeDamage(getNearbyHumans(SMASH_RADIUS), SMASH_DAMAGE); // do damage upon landing
// isJumping = false;
// jumpTask.stop();
// return true;
// }
return false;
}

Expand Down Expand Up @@ -500,5 +509,4 @@ public void run() {
}, (float) (i + 1) * 2);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static LevelWaves createLevel(int maxDiff, int maxWaves, int chosenLevel)
// TODO hash out level1 test in NPCFactory when doing this.
// ArrayList<String> level1Mobs = new ArrayList<>(Arrays.asList("Xeno", "PatrickBoss", "WaterQueen"));
// ArrayList<String> level1Mobs = new ArrayList<>(Arrays.asList("Xeno", "IceBoss", "WaterQueen"));
ArrayList<String> level2Mobs = new ArrayList<>(Arrays.asList("ArcaneArcher","SplittingNightBorne"));
ArrayList<String> level2Mobs = new ArrayList<>(Arrays.asList("ArcaneArcher","SplittingNightBorne", "Skeleton", "DeflectWizard"));
ArrayList<String> level3Mobs = new ArrayList<>(Arrays.asList("Xeno", "DodgingDragon", "FireWorm"));

// The mob bosses assigned to the associated levels (planets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class PhysicsMovementComponent extends Component implements MovementController {
private static final Logger logger = LoggerFactory.getLogger(PhysicsMovementComponent.class);
private Vector2 maxSpeed = Vector2Utils.ONE;
private Vector2 normalSpeed;
private float skipMovementTime = 0f; // in seconds, for knockback

private PhysicsComponent physicsComponent;
Expand Down Expand Up @@ -104,4 +105,13 @@ public void setSpeed(Vector2 speed) {
public Vector2 getSpeed() {
return this.maxSpeed;
}
}
public void setNormalSpeed(Vector2 normalSpeed) {
this.normalSpeed = normalSpeed;
}
public Vector2 getNormalSpeed() {
if (normalSpeed == null) {
return maxSpeed;
}
return normalSpeed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class SplitMoblingsTest {
private static final int BASE_AMOUNT = 5;
private final String[] atlas = {
"images/mobs/water_slime.atlas",
"images/mobs/night_borne.atlas"
};

Entity baseMob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WaveFactoryTest {
private final int LVL2_DIFF = 3;
private final int LVL2_WAVES = 10;
private final int LVL2_CHOSEN_LVL = 0;
private final ArrayList<String> LVL2_MOBS = new ArrayList<>(Arrays.asList("Skeleton", "DeflectWizard"));
private final ArrayList<String> LVL2_MOBS = new ArrayList<>(Arrays.asList("ArcaneArcher", "SplittingNightBorne", "Skeleton", "DeflectWizard"));
private final String LVL2_BOSS = "PatrickBoss";

// level stats for level 3 - fire planet
Expand Down

0 comments on commit 286a953

Please sign in to comment.