-
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.
Adjusted position of mob balls and flipped the animation correctly
- Loading branch information
1 parent
a63f74d
commit 394ff12
Showing
4 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
source/core/src/main/com/csse3200/game/components/MobProjectileAnimationController.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,23 @@ | ||
package com.csse3200.game.components; | ||
|
||
import com.csse3200.game.rendering.AnimationRenderComponent; | ||
|
||
|
||
public class MobProjectileAnimationController extends Component { | ||
AnimationRenderComponent animator; | ||
|
||
/** | ||
* Creation call for a TowerAnimationController, fetches the animationRenderComponent that this controller will | ||
* be attached to and registers all the event listeners required to trigger the animations and sounds. | ||
*/ | ||
@Override | ||
public void create() { | ||
super.create(); | ||
animator = this.entity.getComponent(AnimationRenderComponent.class); | ||
entity.getEvents().addListener("rotate", this::animateStartRotate); | ||
} | ||
|
||
void animateStartRotate() { | ||
animator.startAnimation("rotate"); | ||
} | ||
} |
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
91 changes: 91 additions & 0 deletions
91
source/core/src/main/com/csse3200/game/components/tasks/ShootTask.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,91 @@ | ||
package com.csse3200.game.components.tasks; | ||
|
||
import com.csse3200.game.ai.tasks.DefaultTask; | ||
import com.csse3200.game.ai.tasks.PriorityTask; | ||
import com.csse3200.game.entities.Entity; | ||
import com.badlogic.gdx.math.Vector2; | ||
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; | ||
|
||
|
||
/** | ||
* Task that prints a message to the terminal whenever it is called. | ||
*/ | ||
public class ShootTask extends DefaultTask implements PriorityTask { | ||
private String message; | ||
private final Entity target; | ||
private final int priority; | ||
private final float viewDistance; | ||
private final float maxChaseDistance; | ||
private final PhysicsEngine physics; | ||
private final DebugRenderer debugRenderer; | ||
private final RaycastHit hit = new RaycastHit(); | ||
|
||
/** | ||
* @param target The entity to shoot at. | ||
* @param priority Task priority when shooting (0 when not chasing). | ||
* @param viewDistance Maximum distance from the entity at which shooting can start. | ||
* @param maxChaseDistance Maximum distance from the entity while shooting before giving up. | ||
*/ | ||
public ShootTask(Entity target, int priority, float viewDistance, float maxChaseDistance) { | ||
this.target = target; | ||
this.priority = priority; | ||
this.viewDistance = viewDistance; | ||
this.maxChaseDistance = maxChaseDistance; | ||
this.message = "Shoot Task Activated " + target; | ||
physics = ServiceLocator.getPhysicsService().getPhysics(); | ||
debugRenderer = ServiceLocator.getRenderService().getDebug(); | ||
|
||
} | ||
|
||
@Override | ||
public void start() { | ||
super.start(); | ||
System.out.println(this.message); | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
if (status == Status.ACTIVE) { | ||
return getActivePriority(); | ||
} | ||
|
||
return getInactivePriority(); | ||
} | ||
|
||
private float getDistanceToTarget() { | ||
return owner.getEntity().getPosition().dst(target.getPosition()); | ||
} | ||
|
||
private int getActivePriority() { | ||
float dst = getDistanceToTarget(); | ||
if (dst > maxChaseDistance || !isTargetVisible()) { | ||
return -1; // Too far, stop chasing | ||
} | ||
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; | ||
} | ||
} |