-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
217 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ | |
"health": 100, | ||
"baseAttack": 25, | ||
"spookyFactor": 7 | ||
}, | ||
"projectile": { | ||
"health": 100, | ||
"baseAttack": 10 | ||
} | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.csse3200.game.components.tasks; | ||
|
||
import com.badlogic.gdx.math.Vector2; | ||
import com.csse3200.game.ai.tasks.DefaultTask; | ||
import com.csse3200.game.ai.tasks.PriorityTask; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.physics.PhysicsEngine; | ||
import com.csse3200.game.physics.PhysicsLayer; | ||
import com.csse3200.game.physics.raycast.RaycastHit; | ||
import com.csse3200.game.rendering.DebugRenderer; | ||
import com.csse3200.game.services.ServiceLocator; | ||
|
||
/** Chases a target entity until they get too far away or line of sight is lost */ | ||
public class TrajectTask extends DefaultTask implements PriorityTask { | ||
private final Entity target; | ||
private final int priority; | ||
private final float viewDistance; | ||
private final PhysicsEngine physics; | ||
private final DebugRenderer debugRenderer; | ||
private final RaycastHit hit = new RaycastHit(); | ||
private MovementTask movementTask; | ||
private Vector2 destination; | ||
|
||
/** | ||
* @param target The entity to chase. | ||
* @param priority Task priority when chasing (0 when not chasing). | ||
* @param viewDistance Maximum distance from the entity at which chasing can start. | ||
* @param maxChaseDistance Maximum distance from the entity while chasing before giving up. | ||
*/ | ||
public TrajectTask(Entity shooter, Entity target, int priority, float viewDistance, Vector2 destination) { | ||
this.target = target; | ||
this.priority = priority; | ||
this.viewDistance = viewDistance; | ||
this.destination = destination; | ||
physics = ServiceLocator.getPhysicsService().getPhysics(); | ||
debugRenderer = ServiceLocator.getRenderService().getDebug(); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
super.start(); | ||
movementTask = new MovementTask(destination); | ||
movementTask.create(owner); | ||
movementTask.start(); | ||
|
||
this.owner.getEntity().getEvents().trigger("trajectStart"); | ||
} | ||
|
||
@Override | ||
public void update() { | ||
movementTask.setTarget(destination); | ||
movementTask.update(); | ||
if (movementTask.getStatus() != Status.ACTIVE) { | ||
movementTask.start(); | ||
} | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
super.stop(); | ||
movementTask.stop(); | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
if (status == Status.ACTIVE) { | ||
return getActivePriority(); | ||
} | ||
|
||
return getInactivePriority(); | ||
} | ||
|
||
private float getDistanceToTarget() { | ||
return owner.getEntity().getPosition().dst(destination); | ||
} | ||
|
||
private int getActivePriority() { | ||
return priority; | ||
} | ||
|
||
private int getInactivePriority() { | ||
float dst = getDistanceToTarget(); | ||
if (dst < viewDistance && isTargetVisible()) { | ||
return priority; | ||
} | ||
return -1; | ||
} | ||
|
||
private boolean isTargetVisible() { | ||
Vector2 from = owner.getEntity().getCenterPosition(); | ||
Vector2 to = target.getCenterPosition(); | ||
|
||
// If there is an obstacle in the path to the player, not visible. | ||
// if (physics.raycast(from, to, PhysicsLayer.OBSTACLE, hit)) { | ||
// debugRenderer.drawLine(from, hit.point); | ||
// return false; | ||
// } | ||
debugRenderer.drawLine(from, to); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
source/core/src/main/com/csse3200/game/entities/configs/ProjectileConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.csse3200.game.entities.configs; | ||
|
||
public class ProjectileConfig extends BaseEntityConfig { | ||
public int health = 1; | ||
public int baseAttack = 0; | ||
} |
58 changes: 58 additions & 0 deletions
58
source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.csse3200.game.entities.factories; | ||
|
||
import com.csse3200.game.components.TouchAttackComponent; | ||
import com.csse3200.game.components.tasks.TrajectTask; | ||
import com.csse3200.game.ai.tasks.AITaskComponent; | ||
import com.csse3200.game.components.CombatStatsComponent; | ||
import com.csse3200.game.entities.configs.BaseEntityConfig; | ||
import com.csse3200.game.entities.configs.NPCConfigs; | ||
import com.csse3200.game.files.FileLoader; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.rendering.TextureRenderComponent; | ||
import com.csse3200.game.physics.PhysicsLayer; | ||
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.badlogic.gdx.math.Vector2; | ||
|
||
/** | ||
* Responsible for creating projectiles within the game | ||
*/ | ||
public class ProjectileFactory { | ||
|
||
private static final NPCConfigs configs = FileLoader.readClass(NPCConfigs.class, "configs/NPCS.json"); | ||
|
||
public static Entity createProjectile(Entity shooter, Entity target, Vector2 destination, Vector2 speed) { | ||
BaseEntityConfig config = configs.projectile; | ||
|
||
AITaskComponent aiComponent = | ||
new AITaskComponent() | ||
.addTask(new TrajectTask(shooter, target, 10, 100f, destination)); | ||
|
||
Entity projectile = new Entity() | ||
.addComponent(new TextureRenderComponent("images/projectile.png")) | ||
.addComponent(new PhysicsComponent()) | ||
.addComponent(new PhysicsMovementComponent()) | ||
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.PROJECTILE)) | ||
.addComponent(new ColliderComponent()) | ||
.addComponent(new TouchAttackComponent(PhysicsLayer.PLAYER, 1.5f)) | ||
.addComponent(new CombatStatsComponent(config.health, config.baseAttack)) | ||
.addComponent(aiComponent); | ||
|
||
projectile.getComponent(TextureRenderComponent.class).scaleEntity(); | ||
projectile.getComponent(PhysicsMovementComponent.class).setSpeed(speed); | ||
|
||
|
||
// Able to alter the collider component's size in proportion to the Entity's size. | ||
// PhysicsUtils.setScaledCollider(projectile, 0.9f, 0.4f); | ||
return projectile; | ||
} | ||
|
||
/** | ||
* Prevents the creation of a Projectile Factory entity being created | ||
*/ | ||
private ProjectileFactory() { | ||
throw new IllegalStateException("Instantiating static util class"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters