Weapon Drop Function - UQdeco2800/2022-studio-2 GitHub Wiki
Summary
This wiki page explains how the dropWeapon()
function works and is implemented by the player and the enemy.
Key Binds
As a temporary implementation, when the player presses y
key the player will drop a dagger into the game. When equipped is implemented there will be changes made to how the player interacts with the dropWeapon() function.
This function is also automatically called when an enemy is killed to drop the enemies weapon into the game.
dropFunction in CombatStatsComponent
Located in: source/core/src/main/com/deco2800/game/components/CombatStatsComponent.java
First I want to get the position of the entity which has called this method
float x = getEntity().getPosition().x;
float y = getEntity().getPosition().y;
The dropWeapon() function then compares what type of entity has called dropWeapon(). The first if clause checks whether the player called the function. For this implementation, since the equip function is not yet active, what I have implemented is a drop dagger, as this is the current weapon our CombatTeam have designed animations for. The next stage will be to check that the player has a weapon equipped and if so, to identify the type of weapon and drop it into the game.
if (getEntity().checkEntityType(EntityTypes.PLAYER)) {
Entity newWeapon = WeaponFactory.createDagger();
ServiceLocator.getEntityService().register(newWeapon);
newWeapon.setPosition(x , (float) (y - 1.2));
}
The second clause of the if/else statement is what drops the games enemies weapon. More specifically it drops the dumbbell weapon belonging to the gym bro character in the game.
else if (getEntity().checkEntityType(EntityTypes.MELEE)) {
Entity newWeapon = WeaponFactory.createDumbbell();
ServiceLocator.getEntityService().register(newWeapon);
newWeapon.setPosition(x , (float) (y - 1));
}
drop weapons on attack in PlayerTouchAttackComponent
Located in: source/core/src/main/com/deco2800/game/components/player/PlayerTouchAttackComponent.java
In this component within the attack() function, I added the third line which calls the dropWeapon() function. This then checks the entity type is an enemy and drops the appropriate weapon.
if (target.getComponent(CombatStatsComponent.class).getHealth() == 0) {
target.dispose();
target.getComponent(CombatStatsComponent.class).dropWeapon();
Back to Combat Items Contents Page
Author
- Madi Feddema
- GitHub: @madifeddema
- Discord: madi-feddema#3384
- Slack: Madi Feddema