Skip to content

Commit

Permalink
Merge branch 'Team-1--Projectiles' into Team-1--Mobs-Enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniSoda17 committed Sep 16, 2023
2 parents b4b8922 + 9086112 commit 34553f0
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 7 deletions.
Binary file added source/core/assets/images/projectiles/projectile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void updateMobState() {
} else {
Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y));
// newProjectile.setScale(-1f, 0.5f);
// newProjectile.setScale(-1f, 1f);
ServiceLocator.getEntityService().register(newProjectile);

// System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n");
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.csse3200.game.components.*;
import com.csse3200.game.components.MobProjectileAnimationController;
import com.csse3200.game.components.projectile.*;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.extensions.GameExtension;
Expand Down Expand Up @@ -160,12 +161,12 @@ public void testMobBallProjectileAnimationRenderComponent() {
"Mob Ball Projectile does not have an AnimationRenderComponent");
}

@Test
public void testMobBallProjectileAnimationController() {
Entity mobBallProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0.1f, 0.1f), new Vector2(1f, 1f));
assertNotNull(mobBallProjectile.getComponent(MobProjectileAnimationController.class),
"Mob Ball Projectile does not have an AnimationController");
}
// @Test
// public void testMobBallProjectileAnimationController() {
// Entity mobBallProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0.1f, 0.1f), new Vector2(1f, 1f));
// assertNotNull(mobBallProjectile.getComponent(MobProjectileAnimationController.class),
// "Mob Ball Projectile does not have an AnimationController");
// }

@Test
public void testMobKingBallCreation() {
Expand Down

0 comments on commit 34553f0

Please sign in to comment.