Skip to content

Commit

Permalink
Added atlas file and animations for basic projectile
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyle1 committed Sep 6, 2023
1 parent 2b4130f commit ffde6f4
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 8 deletions.
50 changes: 50 additions & 0 deletions source/core/assets/images/projectiles/basic_projectile.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

basic_projectile.png
size: 128, 32
format: RGBA8888
filter: Nearest, Nearest
repeat: none
projectileFinal5
rotate: false
xy: 2, 17
size: 24, 13
orig: 24, 13
offset: 0, 0
index: 5
projectile4
rotate: false
xy: 2, 2
size: 23, 13
orig: 23, 13
offset: 0, 0
index: 4
projectile3
rotate: false
xy: 27, 2
size: 23, 13
orig: 23, 13
offset: 0, 0
index: 3
projectile2
rotate: false
xy: 28, 17
size: 23, 13
orig: 23, 13
offset: 0, 0
index: 2
projectileStart1
rotate: false
xy: 53, 16
size: 22, 14
orig: 22, 14
offset: 0, 0
index: 1
default
rotate: false
xy: 53, 16
size: 22, 14
orig: 22, 14
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.
Binary file modified source/core/assets/images/towers/mine_tower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/towers/turret.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/towers/turret_deployed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/towers/wallTower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public class ForestGameArea extends GameArea {
"images/background/building2.png",
"images/iso_grass_3.png",
"images/economy/scrap.png",
"images/towers/mine_tower.png"
"images/towers/mine_tower.png",
"images/projectiles/basic_projectiles.png"
};
private static final String[] forestTextureAtlases = {
"images/terrain_iso_grass.atlas",
Expand All @@ -94,7 +95,8 @@ public class ForestGameArea extends GameArea {
"images/towers/turret01.atlas",
"images/mobs/xenoGruntRunning.atlas",
"images/mobs/robot.atlas",
"images/mobs/rangeBossRight.atlas"
"images/mobs/rangeBossRight.atlas",
"images/projectiles/basic_projectile.atlas"
};
private static final String[] forestSounds = {
"sounds/Impact4.ogg",
Expand Down Expand Up @@ -190,6 +192,7 @@ private void spawnTerrain() {
new GridPoint2(0, tileBounds.y),
false,
false);

// Bottom
spawnEntityAt(
ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH), GridPoint2Utils.ZERO, false, false);
Expand All @@ -204,6 +207,7 @@ private void spawnBuilding1() {
spawnEntityAt(building1, randomPos, true, false);
}
}

private void spawnBuilding2() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);
Expand Down Expand Up @@ -308,7 +312,6 @@ private void spawnProjectile(Vector2 position, Entity target, int space, int di
// false);
// }
// return bossKing1;

// }

private void spawnXenoGrunts() {
Expand Down Expand Up @@ -398,7 +401,6 @@ private void spawnWeaponTower() {
}
}


private void playMusic() {
Music music = ServiceLocator.getResourceService().getAsset(backgroundMusic, Music.class);
music.setLooping(true);
Expand Down Expand Up @@ -458,5 +460,4 @@ private void spawnIncome() {
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.csse3200.game.components.projectile;

import com.csse3200.game.components.Component;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;

public class ProjectileAnimationController extends Component{
/** Event name constants */
private static final String START = "startProjectileStart1";
private static final String PHASE1 = "startProjectile2";
private static final String PHASE2 = "startProjectile3";
private static final String PHASE3 = "startProjectile4";
private static final String FINAL = "startProjectileFinish5";

/** Animation name constants */
private static final String START_ANIM = "projectileStart1";
private static final String PHASE1_ANIM = "projectile2";
private static final String PHASE2_ANIM = "projectile3";
private static final String PHASE3_ANIM = "projectile4";
private static final String FINAL_ANIM = "projectileFinish5";

AnimationRenderComponent animator;

@Override
public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener(START, this::animateStart);
entity.getEvents().addListener(START, this::animatePhase1);
entity.getEvents().addListener(START, this::animatePhase2);
entity.getEvents().addListener(START, this::animatePhase3);
entity.getEvents().addListener(START, this::animateFinal);

}

void animateStart() {
animator.startAnimation(START_ANIM);
}

void animatePhase1() {
animator.startAnimation(PHASE1_ANIM);
}

void animatePhase2() {
animator.startAnimation(PHASE2_ANIM);
}

void animatePhase3() {
animator.startAnimation(PHASE3_ANIM);
}

void animateFinal() {
animator.startAnimation(FINAL_ANIM);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.csse3200.game.entities.factories;

import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.csse3200.game.components.AoeComponent;
import com.csse3200.game.components.TouchAttackComponent;
import com.csse3200.game.components.tasks.TrajectTask;
Expand All @@ -9,6 +11,7 @@
import com.csse3200.game.entities.configs.NPCConfigs;
import com.csse3200.game.files.FileLoader;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.rendering.TextureRenderComponent;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.PhysicsUtils;
Expand All @@ -17,11 +20,25 @@
import com.csse3200.game.physics.components.PhysicsComponent;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.components.projectile.ProjectileAnimationController;
import com.csse3200.game.services.ServiceLocator;

/**
* Responsible for creating projectiles within the game.
*/
public class ProjectileFactory {
/** Animation constants */
private static final String BASE_PROJECTILE_ATLAS = "images/projectiles/basic_projectile.atlas";
private static final String START_ANIM = "projectileStart1";
private static final String PHASE1_ANIM = "projectile2";
private static final String PHASE2_ANIM = "projectile3";
private static final String PHASE3_ANIM = "projectile4";
private static final String FINAL_ANIM = "projectileFinish5";
private static final float START_SPEED = 0.3f;
private static final float PHASE1_SPEED = 0.3f;
private static final float PHASE2_SPEED = 0.3f;
private static final float PHASE3_SPEED = 0.3f;
private static final float FINAL_SPEED = 0.3f;

private static final NPCConfigs configs =
FileLoader.readClass(NPCConfigs.class, "configs/NPCs.json");
Expand All @@ -40,19 +57,28 @@ public static Entity createFireBall(Entity target, Vector2 destination, Vector2
Entity projectile = createBaseProjectile(target, destination);

projectile
.addComponent(new TextureRenderComponent("images/projectiles/projectile.png"))
// .addComponent(new TextureRenderComponent("images/projectiles/projectile.png"))
.addComponent(new ColliderComponent().setSensor(true))

// This is the component that allows the projectile to damage a specified target.
.addComponent(new TouchAttackComponent(PhysicsLayer.PLAYER, 1.5f, true))
.addComponent(new CombatStatsComponent(config.health, config.baseAttack));

projectile
.getComponent(TextureRenderComponent.class).scaleEntity();
// projectile
// .getComponent(TextureRenderComponent.class).scaleEntity();

projectile
.getComponent(PhysicsMovementComponent.class).setSpeed(speed);

AnimationRenderComponent animator = new AnimationRenderComponent(
ServiceLocator.getResourceService()
.getAsset(BASE_PROJECTILE_ATLAS, TextureAtlas.class));
animator.addAnimation(START_ANIM, START_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(PHASE1_ANIM, PHASE1_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(PHASE2_ANIM, PHASE2_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(PHASE3_ANIM, PHASE3_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(FINAL_ANIM, FINAL_SPEED, Animation.PlayMode.NORMAL);

return projectile;
}

Expand Down

0 comments on commit ffde6f4

Please sign in to comment.