Skip to content

Commit

Permalink
Merge branch 'main' into Mohamad-Maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamad11Dab committed Oct 1, 2023
2 parents 8b7bb81 + d1cbb5a commit 1369a4e
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ public void update() {

/**
* Deflects projectile to the opposite direction
* @param me Self entity fixture
*
* @param me Self entity fixture
* @param other Colliding projectile fixture.
*/
private void deflectProj(Fixture me, Fixture other) {
// If self fixture does not match to the colliding target return;
if (hitboxComponent.getFixture() != me
|| !PhysicsLayer.contains(targetLayer, other.getFilterData().categoryBits))
return;

if (deflectLimitAmount-- <= 0) { // Reached deflect limit amt, return.
entity.getComponent(this.getClass()).setEnabled(false);
// reset health
Expand All @@ -86,16 +87,18 @@ private void deflectProj(Fixture me, Fixture other) {

// Disposes all tasks for the curr projectile. At this curr time, it assumes
// projectile only has one significant task, and that is the TrajectTask.
projectile.getComponent(AITaskComponent.class).dispose(); // stop task
projectile.getComponent(AITaskComponent.class).disposeAll();

// Obtain current direction of projectile
Vector2 direction = projectile.getComponent(
PhysicsMovementComponent.class).getTarget();

// Rare occurence that the direction is null if target isn't set.
if(direction == null) return;
if (direction == null)
return;

// Add new traject task with the target in the opposite x-direction.
// // Add new traject task with the target in the opposite x-direction.
projectile.getComponent(AITaskComponent.class)
.addTask(new TrajectTask(new Vector2(-direction.x, direction.y)));

Expand Down

0 comments on commit 1369a4e

Please sign in to comment.