Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team-2--Engineers-Praneet #148

Merged
merged 15 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ public void create() {
loadAssets();
displayUI();
spawnTerrain();
// spawnBuilding1();
// spawnBuilding2();
// spawnMountains();

// Set up infrastructure for end game tracking

playMusic();

// Spawn Entities
player = spawnPlayer();
player.getEvents().addListener("spawnWave", this::spawnXenoGrunts);

Expand Down Expand Up @@ -337,14 +336,34 @@ private Entity spawnPlayer(GridPoint2 position) {
// spawnEntityAt(ghostKing, randomPos, true, true);
// return ghostKing;
// }

private Entity spawnBossKing1() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);
GridPoint2 randomPos
= new GridPoint2(0, 0);
Entity ghostKing = NPCFactory.createGhostKing(player);
spawnEntityAt(ghostKing, randomPos, true, true);
return ghostKing;
}

/**
* Spawns a projectile that only heads towards the enemies in its lane.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
=======
/**
* Spawns a projectile that only heads towards the enemies in its lane.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
>>>>>>> 92874c64074b73bbc0cd494b332a657dee66f150
*/
private void spawnProjectile(Vector2 position, short targetLayer, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y), speed);
Expand All @@ -355,10 +374,18 @@ private void spawnProjectile(Vector2 position, short targetLayer, int direction,
/**
* Spawns a projectile specifically for general mobs/xenohunters
*
<<<<<<< HEAD
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
=======
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
>>>>>>> 92874c64074b73bbc0cd494b332a657dee66f150
*/
private void spawnProjectileTest(Vector2 position, short targetLayer, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createEngineerBullet(targetLayer, new Vector2(direction, position.y), speed);
Expand All @@ -367,13 +394,24 @@ private void spawnProjectileTest(Vector2 position, short targetLayer, int direct
}

/**
<<<<<<< HEAD
* Spawns a projectile to be used for multiple projectile function.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param space The space between the projectiles' destination.
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
=======
* Spawns a projectile to be used for multiple projectile function.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param space The space between the projectiles' destination.
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
>>>>>>> 92874c64074b73bbc0cd494b332a657dee66f150
*/
private void spawnProjectile(Vector2 position, short targetLayer, int space, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y + space), speed);
Expand Down Expand Up @@ -460,7 +498,11 @@ private Entity spawnBossKing2() {
* Creates multiple projectiles that travel simultaneous. They all have same
* the starting point but different destinations.
*
<<<<<<< HEAD
* @param position The position of the Entity that's shooting the projectile.
=======
* @param position The position of the Entity that's shooting the projectile.
>>>>>>> 92874c64074b73bbc0cd494b332a657dee66f150
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param space The space between the projectiles' destination.
Expand All @@ -478,7 +520,11 @@ private void spawnMultiProjectile(Vector2 position, short targetLayer, int direc
/**
* Returns projectile that can do an area of effect damage
*
<<<<<<< HEAD
* @param position The position of the Entity that's shooting the projectile.
=======
* @param position The position of the Entity that's shooting the projectile.
>>>>>>> 92874c64074b73bbc0cd494b332a657dee66f150
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ public class EngineerCombatTask extends DefaultTask implements PriorityTask {
private static final short TARGET = PhysicsLayer.NPC; // The type of targets that the Engineer will detect.

// Animation event names for the Engineer's state machine.
private static final String STOW = "";
private static final String DEPLOY = "";
private static final String FIRING = "firingSingleStart";
private static final String IDLE_LEFT = "idleLeft";
private static final String IDLE_RIGHT = "idleRight";
private static final String DYING = "deathStart";
private static final String ENGINEER_PROJECTILE_FIRED = "engineerProjectileFired";

// The Engineer's attributes.
private final float maxRange; // The maximum range of the Engineer's weapon.
Expand All @@ -52,7 +49,7 @@ public class EngineerCombatTask extends DefaultTask implements PriorityTask {

/** The Engineer's states. */
private enum STATE {
IDLE_LEFT, IDLE_RIGHT, DEPLOY, FIRING, STOW
IDLE_RIGHT, FIRING
}
private STATE engineerState = STATE.IDLE_RIGHT;

Expand Down Expand Up @@ -96,48 +93,32 @@ public void update() {
* Engineer state machine
*/
public void updateEngineerState() {
// configure tower state depending on target visibility
// configure engineer state depending on target visibility
switch (engineerState) {
case IDLE_LEFT -> {
// targets detected in idle mode - start deployment
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(FIRING);
engineerState = STATE.FIRING;
} else {

}
}
case IDLE_RIGHT -> {
// targets detected in idle mode - start deployment
if (isTargetVisible()) {
combatState();
}
}
case DEPLOY -> {
// currently deploying,
if (isTargetVisible()) {
combatState();
} else {
owner.getEntity().getEvents().trigger(STOW);
engineerState = STATE.STOW;
}
}
case FIRING -> {
// targets gone - stop firing
if (!isTargetVisible()) {
owner.getEntity().getEvents().trigger(IDLE_RIGHT);
engineerState = STATE.IDLE_RIGHT;
} else {
if (shotsFired <= 10) {
if (shotsFired <= weaponCapacity) {
owner.getEntity().getEvents().trigger(FIRING);
owner.getEntity().getEvents().trigger(ENGINEER_PROJECTILE_FIRED);
// this might be changed to an event which gets triggered everytime the tower enters the firing state
Entity newProjectile = ProjectileFactory.createEngineerBullet(PhysicsLayer.NPC,
new Vector2(100, owner.getEntity().getPosition().y),
new Vector2(4f, 4f));
newProjectile.setScale(0.8f, 0.8f);
newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.3), (float) (owner.getEntity().getPosition().y + 0.15));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.3),
(float) (owner.getEntity().getPosition().y + 0.15));
ServiceLocator.getEntityService().register(newProjectile);
shotsFired += 1;
shotsFired ++;
reloadTime = timeSource.getTime();
} else {
// engineer needs to reload
Expand Down Expand Up @@ -185,7 +166,7 @@ public int getPriority() {
public boolean isTargetVisible() {
// If there is an obstacle in the path to the max range point, mobs visible.
Vector2 position = owner.getEntity().getCenterPosition();

hits.clear();
for (int i = 5; i > -5; i--) {
if (physics.raycast(position, new Vector2(position.x + maxRange, position.y + i), TARGET, hit)) {
hits.add(hit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public class EngineerFactory {
private static final int COMBAT_TASK_PRIORITY = 2;
private static final int ENGINEER_RANGE = 10;
private static final EngineerConfigs configs =
FileLoader.readClass(EngineerConfigs.class, "configs/Engineers.json");

FileLoader.readClass(EngineerConfigs.class, "configs/Engineers.json");
private static final float HUMAN_SCALE_X = 1f;
private static final float HUMAN_SCALE_Y = 0.8f;

/**
* Creates an Engineer entity, based on a base Human entity, with the appropriate components and animations
*
Expand All @@ -49,7 +49,7 @@ public class EngineerFactory {
public static Entity createEngineer() {
Entity engineer = createBaseHumanNPC();
BaseEntityConfig config = configs.engineer;

AnimationRenderComponent animator = new AnimationRenderComponent(
new TextureAtlas("images/engineers/engineer.atlas"));
animator.addAnimation("walk_left", 0.2f, Animation.PlayMode.LOOP);
Expand All @@ -61,43 +61,43 @@ public static Entity createEngineer() {
animator.addAnimation("prep", 0.05f, Animation.PlayMode.NORMAL);
animator.addAnimation("hit", 0.01f, Animation.PlayMode.NORMAL);
animator.addAnimation("death", 0.1f, Animation.PlayMode.NORMAL);

AITaskComponent aiComponent = new AITaskComponent();

engineer
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent(animator)
.addComponent(new HumanAnimationController())
.addComponent(aiComponent);

engineer.getComponent(AITaskComponent.class).addTask(new HumanWanderTask(COMBAT_TASK_PRIORITY, ENGINEER_RANGE));
engineer.getComponent(AnimationRenderComponent.class).scaleEntity();
engineer.setScale(HUMAN_SCALE_X, HUMAN_SCALE_Y);
return engineer;
}

/**
* Creates a generic human npc to be used as a base entity by more specific NPC creation methods.
*
* @return entity
*/
public static Entity createBaseHumanNPC() {


Entity human =
new Entity()
.addComponent(new PhysicsComponent())
.addComponent(new PhysicsMovementComponent())
.addComponent(new ColliderComponent())
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.ENGINEER))
.addComponent(new TouchAttackComponent(PhysicsLayer.NPC, 1.5f));


new Entity()
.addComponent(new PhysicsComponent())
.addComponent(new PhysicsMovementComponent())
.addComponent(new ColliderComponent())
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.ENGINEER))
.addComponent(new TouchAttackComponent(PhysicsLayer.NPC, 1.5f));
PhysicsUtils.setScaledCollider(human, 0.9f, 0.4f);
return human;
}

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