Skip to content

Commit

Permalink
Added Engineer bullet creation
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniSoda17 committed Sep 9, 2023
1 parent 714b446 commit 23d5db0
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 5 deletions.
41 changes: 41 additions & 0 deletions source/core/assets/images/projectiles/engineer_projectile.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

engineer_projectile.png
size: 128, 32
format: RGBA8888
filter: Nearest, Nearest
repeat: none
bullet
rotate: false
xy: 68, 2
size: 19, 19
orig: 19, 19
offset: 0, 0
index: -1
bullet
rotate: false
xy: 25, 2
size: 20, 19
orig: 20, 19
offset: 0, 0
index: -1
default
rotate: false
xy: 25, 2
size: 20, 19
orig: 20, 19
offset: 0, 0
index: -1
bullet
rotate: false
xy: 2, 2
size: 21, 19
orig: 21, 19
offset: 0, 0
index: -1
bulletFinal
rotate: false
xy: 47, 2
size: 19, 19
orig: 19, 19
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.
2 changes: 1 addition & 1 deletion source/core/assets/images/projectiles/mobProjectile.atlas
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rotate
index: -1
default
rotate: false
xy: 54, 2
xy: 28, 2
size: 24, 23
orig: 24, 23
offset: 0, 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public class ForestGameArea extends GameArea {
"images/mobs/rangeBossRight.atlas",
"images/towers/TNTTower.atlas",
"images/projectiles/basic_projectile.atlas",
"images/projectiles/mobProjectile.atlas"
"images/projectiles/mobProjectile.atlas",
"images/projectiles/engineer_bullets.atlas"
};
private static final String[] forestSounds = {
"sounds/Impact4.ogg",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.csse3200.game.components.projectile;

import com.csse3200.game.components.Component;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator; //used for sound

public class EngineerBullets extends Component{
/** Event name constants */

AnimationRenderComponent animator;

@Override
public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener("start", this::animateStart);
entity.getEvents().addListener("final", this::animateFinal);

}

void animateStart() {
animator.startAnimation("bullet");
}

void animateFinal() {
animator.startAnimation("bulletFinal");
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.components;
package com.csse3200.game.components.projectile;

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void start() {

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

public void switchProjectileState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void updateEngineerState() {
if (shotsFired <= 10) {
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(PhysicsLayer.NPC,
Entity newProjectile = ProjectileFactory.createEngineerBullet(PhysicsLayer.NPC,
new Vector2(100, owner.getEntity().getPosition().y),
new Vector2(4f, 4f));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.75), (float) (owner.getEntity().getPosition().y + 0.4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.csse3200.game.components.tasks.TrajectTask;
import com.csse3200.game.ai.tasks.AITaskComponent;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.MobProjectileAnimationController;
import com.csse3200.game.entities.configs.BaseEntityConfig;
import com.csse3200.game.entities.configs.NPCConfigs;
import com.csse3200.game.files.FileLoader;
Expand All @@ -23,6 +22,7 @@
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.MobProjectileAnimationController;
import com.csse3200.game.components.projectile.ProjectileAnimationController;

/**
Expand Down Expand Up @@ -115,6 +115,31 @@ public static Entity createFireBall(short targetLayer, Vector2 destination, Vect

return projectile;
}
/**
* Creates a enginner bullet
*
* @param targetLayer The enemy layer that the projectile collides with.
* @param destination The destination the projectile heads towards.
* @param speed The speed of the projectile.
* @return Returns a new fireball projectile entity.
*/
public static Entity createEngineerBullet(short targetLayer, Vector2 destination, Vector2 speed) {
Entity projectile = createBaseProjectile(targetLayer, destination, speed);

AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService()
.getAsset(BASE_PROJECTILE_ATLAS, TextureAtlas.class));
animator.addAnimation("bullet", START_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation("bulletFinal", FINAL_SPEED, Animation.PlayMode.NORMAL);

projectile
.addComponent(animator)
.addComponent(new ProjectileAnimationController());
// .addComponent(new SelfDestructOnHitComponent(PhysicsLayer.OBSTACLE));

return projectile;
}

/**
* Creates a projectile specifically for mobs to shoot
Expand Down

0 comments on commit 23d5db0

Please sign in to comment.