-
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.
Merge branch 'Team-1--Projectiles' into Projectile-Animation
- Loading branch information
Showing
13 changed files
with
299 additions
and
61 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
34 changes: 34 additions & 0 deletions
34
source/core/src/main/com/csse3200/game/components/DeleteOnMapEdgeComponent.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,34 @@ | ||
package com.csse3200.game.components; | ||
|
||
import com.badlogic.gdx.math.Vector2; | ||
import com.badlogic.gdx.physics.box2d.Fixture; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.physics.BodyUserData; | ||
import com.csse3200.game.physics.PhysicsLayer; | ||
|
||
/** | ||
* Entities with this component will self destruct after hitting the grid edge | ||
* upon collision. | ||
*/ | ||
public class DeleteOnMapEdgeComponent extends Component { | ||
|
||
@Override | ||
public void create() { | ||
entity.getEvents().addListener("collisionEnd", this::onCollisionEnd); | ||
} | ||
|
||
private void onCollisionEnd(Fixture me, Fixture other) { | ||
Entity selfEntity = ((BodyUserData) me.getBody().getUserData()).entity; | ||
|
||
// * Should change the PhysicLayer to WALL / BOUNDARIES when established | ||
if (!PhysicsLayer.contains(PhysicsLayer.WALL, other.getFilterData().categoryBits)) | ||
return; | ||
|
||
Vector2 position = selfEntity.getPosition(); | ||
|
||
if (position.x <= 1 || position.x >= 18 || position.y < 0 || position.y >= 6.5) { | ||
System.out.println("DELETION POSITION: " + position); | ||
selfEntity.setFlagForDelete(true); | ||
} | ||
} | ||
} |
65 changes: 45 additions & 20 deletions
65
source/core/src/main/com/csse3200/game/components/RicochetComponent.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
71 changes: 71 additions & 0 deletions
71
source/core/src/main/com/csse3200/game/components/SplitFireworksComponent.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,71 @@ | ||
package com.csse3200.game.components; | ||
|
||
import com.badlogic.gdx.math.Vector2; | ||
import com.badlogic.gdx.physics.box2d.Fixture; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.entities.factories.ProjectileFactory; | ||
import com.csse3200.game.physics.BodyUserData; | ||
import com.csse3200.game.physics.PhysicsLayer; | ||
import com.csse3200.game.physics.components.HitboxComponent; | ||
import com.csse3200.game.services.ServiceLocator; | ||
|
||
/** | ||
* A component that splits the projectile into multiple mini projectiles. | ||
* Assumes projectile has a disposesOnHit functionality. | ||
*/ | ||
public class SplitFireworksComponent extends Component { | ||
private short targetLayer; | ||
private HitboxComponent hitboxComponent; | ||
private int amount; | ||
private static int TOTAL_RANGE = 450; | ||
|
||
/** | ||
* Initialises a component that splits the projectile into multiple fireballs | ||
* upon collision on a specified target layer. | ||
* The spawned projectiles will be spawned just before original projectile | ||
* and spread out in multiple direction set by a certain range. | ||
* Assumes amount of split projectiles is greater or equal than 2. | ||
* | ||
* @param targetLayer Target layer upon collision. | ||
* @param amount Amount of projectiles that is split after collision event. | ||
*/ | ||
public SplitFireworksComponent(short targetLayer, int amount) { | ||
this.targetLayer = targetLayer; | ||
this.amount = amount; | ||
} | ||
|
||
@Override | ||
public void create() { | ||
entity.getEvents().addListener("collisionEnd", this::onCollisionEnd); | ||
hitboxComponent = entity.getComponent(HitboxComponent.class); | ||
} | ||
|
||
private void onCollisionEnd(Fixture me, Fixture other) { | ||
if (hitboxComponent.getFixture() != me | ||
|| !PhysicsLayer.contains(targetLayer, other.getFilterData().categoryBits) | ||
|| amount < 2) // Amount of split projectiles must be >= 2 | ||
return; | ||
|
||
Entity projectile = ((BodyUserData) me.getBody().getUserData()).entity; | ||
|
||
for (int i = 0; i < amount; i++) { | ||
int newDirection = (i * TOTAL_RANGE) / (amount - 1); | ||
|
||
// Boundaries | ||
float newXPosition = (float) (projectile.getPosition().x + 1.75); | ||
if (newXPosition >= 18 || newXPosition <= 1) | ||
return; | ||
|
||
// * RIGHT NOW TARGET IS NPC, SUBJECT TO CHANGE | ||
// Speed is a bit faster than normal but can change. | ||
Entity newProjectile = ProjectileFactory.createFireBall(PhysicsLayer.NPC, | ||
new Vector2(100, projectile.getPosition().y + (newDirection - (TOTAL_RANGE/2))), new Vector2(3f, 3f)); | ||
|
||
newProjectile.setPosition(newXPosition, (float) projectile.getPosition().y); | ||
|
||
newProjectile.setScale(0.5f, 0.5f); | ||
|
||
ServiceLocator.getEntityService().register(newProjectile); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.