Skip to content

Commit

Permalink
Fixed merge conflicts from Team-1 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyle1 committed Sep 7, 2023
2 parents 8919913 + 7eaa3fe commit 755b606
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 46 deletions.
41 changes: 41 additions & 0 deletions source/core/assets/images/projectiles/mobProjectile.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

mobProjectile.png
size: 128, 32
format: RGBA8888
filter: Nearest, Nearest
repeat: none
rotate
rotate: false
xy: 54, 2
size: 24, 23
orig: 24, 23
offset: 0, 0
index: -1
rotate
rotate: false
xy: 2, 2
size: 24, 23
orig: 24, 23
offset: 0, 0
index: -1
default
rotate: false
xy: 54, 2
size: 24, 23
orig: 24, 23
offset: 0, 0
index: -1
rotate
rotate: false
xy: 28, 2
size: 24, 23
orig: 24, 23
offset: 0, 0
index: -1
rotate
rotate: false
xy: 80, 2
size: 24, 23
orig: 24, 23
offset: 0, 0
index: -1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 44 additions & 19 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.components.ProjectileEffects;
import com.csse3200.game.input.DropInputComponent;
import com.csse3200.game.areas.terrain.TerrainFactory;
import com.csse3200.game.areas.terrain.TerrainFactory.TerrainType;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.*;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.utils.math.GridPoint2Utils;
import com.csse3200.game.utils.math.RandomUtils;
import com.csse3200.game.services.ResourceService;
Expand Down Expand Up @@ -85,7 +87,9 @@ public class ForestGameArea extends GameArea {
"images/iso_grass_3.png",
"images/economy/scrap.png",
"images/towers/mine_tower.png",
"images/projectiles/basic_projectile.png"
"images/projectiles/basic_projectile.png",
"images/projectiles/mobProjectile.png"

};
private static final String[] forestTextureAtlases = {
"images/terrain_iso_grass.atlas",
Expand All @@ -96,7 +100,8 @@ public class ForestGameArea extends GameArea {
"images/mobs/xenoGruntRunning.atlas",
"images/mobs/robot.atlas",
"images/mobs/rangeBossRight.atlas",
"images/projectiles/basic_projectile.atlas"
"images/projectiles/basic_projectile.atlas",
"images/projectiles/mobProjectile.atlas"
};
private static final String[] forestSounds = {
"sounds/Impact4.ogg",
Expand All @@ -114,6 +119,7 @@ public class ForestGameArea extends GameArea {
// Variables to be used with spawn projectile methods. This is the variable
// that should occupy the direction param.
private static final int towardsMobs = 100;
private static final int towardsTowers = 0;
private Entity bossKing1;
private Entity bossKing2;

Expand Down Expand Up @@ -143,10 +149,12 @@ public void create() {

playMusic();

// Types of projectile
spawnAoeProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), 1);
spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f));
spawnMultiProjectile(new Vector2(0, 10), player, towardsMobs, 20, new Vector2(2f, 2f), 7);
spawnEffectProjectile(new Vector2(0, 10), PhysicsLayer.PLAYER, towardsMobs, new Vector2(2f, 2f), ProjectileEffects.FIREBALL, true);
// spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f));
//
spawnMobBall(new Vector2(15, 10), PhysicsLayer.PLAYER, towardsTowers, new Vector2(2f, 2f));
spawnMultiProjectile(new Vector2(0, 10), PhysicsLayer.PLAYER, towardsMobs, 20, new Vector2(2f, 2f), 7);

spawnXenoGrunts();

spawnGhosts();
Expand Down Expand Up @@ -273,13 +281,13 @@ private Entity spawnBossKing1() {
* Spawns a projectile that only heads towards the enemies in its lane.
*
* @param position The position of the Entity that's shooting the projectile.
* @param target The enemy entities of the "shooter".
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
*/
private void spawnProjectile(Vector2 position, Entity target, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createFireBall(target, new Vector2(direction, position.y), speed);
private void spawnProjectile(Vector2 position, short targetLayer, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y), speed);
Projectile.setPosition(position);
spawnEntity(Projectile);
}
Expand All @@ -288,14 +296,29 @@ private void spawnProjectile(Vector2 position, Entity target, int direction, Vec
* Spawns a projectile to be used for multiple projectile function.
*
* @param position The position of the Entity that's shooting the projectile.
* @param target The enemy entities of the "shooter".
* @param targetLayer The enemy layer of the "shooter".
* @param space The space between the projectiles' destination.
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
*/
private void spawnProjectile(Vector2 position, Entity target, int space, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createFireBall(target, new Vector2(direction, position.y + space), speed);
private void spawnProjectile(Vector2 position, short targetLayer, int space, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y + space), speed);
Projectile.setPosition(position);
spawnEntity(Projectile);
}

/**
* Spawns a mob based projectile to be used for multiple projectile function.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
*/
private void spawnMobBall(Vector2 position, short targetLayer, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createMobBall(targetLayer, new Vector2(direction, position.y), speed);
Projectile.setPosition(position);
spawnEntity(Projectile);
}
Expand Down Expand Up @@ -359,16 +382,16 @@ private Entity spawnBossKing2() {
* the starting point but different destinations.
*
* @param position The position of the Entity that's shooting the projectile.
* @param target The enemy entities of the "shooter".
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param space The space between the projectiles' destination.
* @param speed The speed of the projectiles.
* @param quantity The amount of projectiles to spawn.
*/
private void spawnMultiProjectile(Vector2 position, Entity target, int direction, int space, Vector2 speed, int quantity) {
private void spawnMultiProjectile(Vector2 position, short targetLayer, int direction, int space, Vector2 speed, int quantity) {
int half = quantity / 2;
for (int i = 0; i < quantity; i++) {
spawnProjectile(position, target, space * half, direction, speed);
spawnProjectile(position, targetLayer, space * half, direction, speed);
--half;
}
}
Expand All @@ -377,13 +400,15 @@ private void spawnMultiProjectile(Vector2 position, Entity target, int direction
* Returns projectile that can do an area of effect damage
*
* @param position The position of the Entity that's shooting the projectile.
* @param target The enemy entities of the "shooter".
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
* @param aoeSize The size of the area of effect.
* @param effect Type of effect.
* @param aoe Whether it is an aoe projectile.
*/
private void spawnAoeProjectile(Vector2 position, Entity target, int direction, Vector2 speed, int aoeSize) {
Entity Projectile = ProjectileFactory.createAOEFireBall(target, new Vector2(direction, position.y), speed, aoeSize);
private void spawnEffectProjectile(Vector2 position, short targetLayer, int direction, Vector2 speed,
ProjectileEffects effect, boolean aoe) {
Entity Projectile = ProjectileFactory.createEffectProjectile(targetLayer, new Vector2(direction, position.y), speed, effect, aoe);
Projectile.setPosition(position);
spawnEntity(Projectile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@

import com.badlogic.gdx.physics.box2d.Fixture;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.physics.BodyUserData;
import com.csse3200.game.entities.factories.ProjectileFactory;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.components.HitboxComponent;
import com.csse3200.game.services.ServiceLocator;

import com.badlogic.gdx.utils.Array;

public class AoeComponent extends Component {
public class EffectsComponent extends Component {
private final float radius;
private final ProjectileEffects effect;
private final boolean aoe;
private HitboxComponent hitboxComponent;
private final short targetLayer;

/**
* Constructor for the AoEComponent.
*
* @param radius The radius of the area-of-effect.
*/
public AoeComponent(float radius) {
public EffectsComponent(short targetLayer, float radius, ProjectileEffects effect, boolean aoe) {
this.targetLayer = targetLayer;
this.radius = radius;
this.effect = effect;
this.aoe = aoe;
}

@Override
public void create() {
entity.getEvents().addListener("collisionStart", this::onCollisionStart);
entity.getEvents().addListener("collisionEnd", this::onCollisionEnd);
entity.getEvents().addListener("projectileCollisionStart", this::onCollisionStart);
entity.getEvents().addListener("projectileCollisionEnd", this::onCollisionEnd);
hitboxComponent = entity.getComponent(HitboxComponent.class);
}

Expand All @@ -37,12 +44,27 @@ private void onCollisionEnd(Fixture me, Fixture other) {
// Not triggered by hitbox, ignore
return;
}
applyAoeDamage();

if (!PhysicsLayer.contains(targetLayer, other.getFilterData().categoryBits)) {
// Doesn't match our target layer, ignore
return;
}

switch (effect) {
case FIREBALL -> {
if (aoe) {
applyAoeEffect(ProjectileEffects.FIREBALL);
}
}
case BURN -> {}
case SLOW -> {}
case STUN -> {}
}
}
/**
* Apply damage to all entities within the area of effect (radius).
* Used for aoe fireball projectile to apply damage to all entities within the area of effect (radius).
*/
public void applyAoeDamage() {
public void applyAoeEffect(ProjectileEffects effect) {
Entity hostEntity = getEntity();
CombatStatsComponent hostCombatStats = hostEntity.getComponent(CombatStatsComponent.class);

Expand Down
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
@@ -0,0 +1,8 @@
package com.csse3200.game.components;

public enum ProjectileEffects {
FIREBALL, //fireball projectile - deals damage based on baseAttack
BURN, //burn projectile - does 5 extra ticks of damage over 5 seconds
SLOW, //slow projectile - slows entity by half for 5 seconds
STUN //stun projectile - stuns entity for 5 seconds
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ public void updateTowerState() {
} else {
owner.getEntity().getEvents().trigger(FIRING);
// this might be changed to an event which gets triggered everytime the tower enters the firing state
Entity newProjectile = ProjectileFactory.createFireBall(owner.getEntity(), new Vector2(100, owner.getEntity().getPosition().y), new Vector2(2f,2f));

Entity newProjectile = ProjectileFactory.createFireBall(PhysicsLayer.PLAYER, new Vector2(100, owner.getEntity().getPosition().y), new Vector2(2f,2f));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.75), (float) (owner.getEntity().getPosition().y + 0.4));

ServiceLocator.getEntityService().register(newProjectile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class TrajectTask extends DefaultTask implements PriorityTask {
private static final String START = "startProjectile";
private static final String FINAL = "startProjectileFinal";



private enum STATE {
START, FINAL
}
Expand All @@ -36,7 +38,9 @@ public void start() {
movementTask = new MovementTask(destination);
movementTask.create(owner);
movementTask.start();

this.owner.getEntity().getEvents().trigger(START);
this.owner.getEntity().getEvents().trigger("rotate");
}

public void switchProjectileState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public Array<Entity> getEntities() {
public Array<Entity> getNearbyEntities(Entity source, float radius) {
Array<Entity> nearbyEntities = new Array<Entity>();
Array<Entity> allEntities = ServiceLocator.getEntityService().getEntities();
for (Entity otherEntity : allEntities) {
for (int i = 0; i < allEntities.size; i++) {
Entity otherEntity = allEntities.get(i);

if (source == otherEntity) continue; // Skip the source entity

Vector2 positionSource = source.getPosition();
Expand Down
Loading

0 comments on commit 755b606

Please sign in to comment.