Skip to content

Commit

Permalink
Adjusted position of mob balls and flipped the animation correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniSoda17 committed Sep 11, 2023
1 parent a63f74d commit 394ff12
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 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 @@ -133,8 +133,8 @@ public void updateMobState() {
this.owner.getEntity().getEvents().trigger("meleeStart");
} 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.setPosition((float) (owner.getEntity().getPosition().x + 0.7f), (float) (owner.getEntity().getPosition().y - 0.18f));
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;
}
}

0 comments on commit 394ff12

Please sign in to comment.