Skip to content

Commit

Permalink
Implemented the Dragon Knight Mob attack, run & death animation
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniSoda17 committed Sep 19, 2023
1 parent 954eb95 commit b385099
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 2 deletions.
174 changes: 174 additions & 0 deletions source/core/assets/images/mobs/dragon_knight.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@

dragon_knight.png
size: 512, 512
format: RGBA8888
filter: Nearest, Nearest
repeat: none
dragon_knight_attack
rotate: false
xy: 308, 105
size: 99, 99
orig: 99, 99
offset: 0, 0
index: -1
dragon_knight_attack
rotate: false
xy: 410, 207
size: 100, 99
orig: 100, 99
offset: 0, 0
index: -1
dragon_knight_attack
rotate: false
xy: 308, 4
size: 99, 99
orig: 99, 99
offset: 0, 0
index: -1
dragon_knight_attack
rotate: false
xy: 2, 308
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_attack
rotate: false
xy: 206, 206
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_attack
rotate: false
xy: 2, 2
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 104, 308
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 308, 206
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 410, 410
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 2, 206
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 308, 308
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 206, 104
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 206, 308
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 2, 410
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 104, 2
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 2, 104
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 206, 2
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 308, 410
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_death
rotate: false
xy: 104, 410
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_run
rotate: false
xy: 104, 104
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_run
rotate: false
xy: 206, 410
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_run
rotate: false
xy: 410, 308
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
dragon_knight_run
rotate: false
xy: 104, 206
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
default
rotate: false
xy: 104, 206
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
Binary file added source/core/assets/images/mobs/dragon_knight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public class ForestGameArea extends GameArea {
"images/projectiles/firework_anim.atlas",
"images/projectiles/mobProjectile.atlas",
"images/projectiles/stun_effect.atlas",
"images/mobs/fire_worm.atlas"
"images/mobs/fire_worm.atlas",
"images/mobs/dragon_knight.atlas"
};
private static final String[] forestSounds = {
"sounds/Impact4.ogg",
Expand Down Expand Up @@ -201,6 +202,7 @@ private void spawnWave() {
case 1:
case 2:
spawnFireWorm();
spawnDragonKnight();
break;
case 3:
mobBoss2 = spawnMobBoss2();
Expand Down Expand Up @@ -487,6 +489,18 @@ private void spawnFireWorm() {
}
}

private void spawnDragonKnight() {
int[] pickedLanes = new Random().ints(1, 7)
.distinct().limit(5).toArray();
for (int i = 0; i < NUM_GRUNTS; i++) {
GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]);
System.out.println(randomPos);
Entity fireWorm = NPCFactory.createDragonKnight(player);
fireWorm.setScale(1.5f, 1.5f);
spawnEntityAt(fireWorm, randomPos, true, false);
}
}

// private Entity spawnGhostKing() {
// GridPoint2 minPos = new GridPoint2(0, 0);
// GridPoint2 maxPos = terrain.getMapBounds(0).sub(0, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.csse3200.game.components.npc;

import com.badlogic.gdx.audio.Sound;
import com.csse3200.game.components.Component;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;

import java.util.Random;

/**
* This class listens to events relevant to a ghost entity's state and plays the animation when one
* of the events is triggered.
*/
public class DragonKnightAnimationController extends Component {
// // For on collision sounds later
// private static final String COLLISION_SFX = "sounds/projectiles/on_collision.mp3";
// Sound onCollisionSound = ServiceLocator.getResourceService().getAsset(
// COLLISION_SFX, Sound.class);
AnimationRenderComponent animator;
Random rand = new Random();

@Override
public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener("wanderStart", this::animateWalk);
entity.getEvents().addListener("shootStart", this::animateAttack);
entity.getEvents().addListener("dieStart", this::animateDeath);
}

void animateWalk() {
animator.startAnimation("dragon_knight_run");
}

void animateAttack() {
animator.startAnimation("dragon_knight_attack");
}

void animateDeath() {
animator.startAnimation("dragon_knight_death");
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void start() {
currentTask = movementTask;


// this.owner.getEntity().getEvents().trigger("wanderStart");
// this.owner.getEntity().getEvents().trigger("wanderStart");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.csse3200.game.ai.tasks.AITaskComponent;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.TouchAttackComponent;
import com.csse3200.game.components.npc.DragonKnightAnimationController;
import com.csse3200.game.components.npc.FireWormAnimationController;
import com.csse3200.game.components.npc.GhostAnimationController;
import com.csse3200.game.components.npc.XenoAnimationController;
Expand Down Expand Up @@ -127,6 +128,36 @@ public static Entity createFireWorm(Entity target) {

return fireWorm;
}
/**
* Creates a dragon Knight entity
*
* @param target entity to chase
* @return entity
*/
public static Entity createDragonKnight(Entity target) {
Entity dragonKnight = createBaseNPC(target);
BaseEnemyConfig config = configs.xenoGrunt;
ArrayList<Melee> melee = new ArrayList<>(Arrays.asList(PredefinedWeapons.sword, PredefinedWeapons.kick));
// tester projectiles
ArrayList<ProjectileConfig> projectiles = new ArrayList<>(Arrays.asList(PredefinedWeapons.fireBall, PredefinedWeapons.frostBall));
ArrayList<Currency> drops = new ArrayList<>();

AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService().getAsset("images/mobs/dragon_knight.atlas", TextureAtlas.class));
animator.addAnimation("dragon_knight_run", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("dragon_knight_attack", 0.1f);
animator.addAnimation("dragon_knight_death", 0.1f);
dragonKnight
.addComponent(new CombatStatsComponent(config.fullHeath, config.baseAttack, drops, melee, projectiles))
.addComponent(animator)
.addComponent(new DragonKnightAnimationController());

dragonKnight.getComponent(HitboxComponent.class).setAsBoxAligned(new Vector2(.3f, .5f), PhysicsComponent.AlignX.RIGHT, PhysicsComponent.AlignY.BOTTOM);
dragonKnight.getComponent(AnimationRenderComponent.class).scaleEntity();

return dragonKnight;
}


/**
Expand Down

0 comments on commit b385099

Please sign in to comment.