Main Character Death Respawn - UQdeco2800/2022-studio-1 GitHub Wiki
Respawn/Death Overview
During sprint 3, team 5 worked closely together with team 1 (Story Team) to decide whether the main character should have the ability to respawn and/or permanently die. It was concluded that if the Main Character's health bar was depleted, it would 'die' in the game. Meaning that the sprite would be removed and the player would not be able to do any further damage to enemies but instead watch the rest of the game carry out in from a spectator format. Despite this, at the beginning of each new round, the player is to be respawned on the map (if he died in the previous round) to continue the game. The players health/life is not a factor in the game's win condition; instead that all depends on the crystals health.
The Design Process
Inspiration:
PixelArt First Attempt
PixelArt Revised
Mainly changed some of the colours and shading, alongside the last frame.
Animation
The Programming Process
The main character death is triggered by the method killEntity() in the CombatStatsComponent class. The killEntity() method was designed to be a general method that can be called when any entity's health reaches 0. When killEntity() is called, it sends an event trigger that can be received by a listener for that specific entity. At the moment it is being used to handle the main character and crystal death events.
public void killEntity(String entityName) {
switch (entityName) {
case "player":
entity.getEvents().trigger("playerDeath");
break;
case "crystal":
entity.getEvents().trigger("crystalDeath");
break;
default:
//do nothing
}
}
Once the "playerDeath" event is triggered, a listener in the PlayerActions class calls the method die(). This method handles the removal of the main character from the game. The player is "killed" by having his sprite hidden from the viewer and all keyboard inputs disabled. A boolean value in the PlayerActions class keeps track of the current dead/alive state of the player.
entity.getEvents().addListener("playerDeath", this::die);
.
.
.
public void die() {
entity.getEvents().trigger("death_anim");
entity.setScale(11f, 10.5f);
playerAlive = false;
dieTask = new TimerTask() {
@Override
public void run() {
//hide the character sprite
entity.setScale(0.1F, 0.1F);
}
};
timer.schedule(dieTask, 1000);
}
Per the decision from the user research conducted by the Storyline team, the main character is respawned each morning with no penalty to the player. This is done by listening to the DayNightCycleService for morning. The main character is then respawned by resizing the sprite, updating the boolean value and resetting the health full.
ServiceLocator.getDayNightCycleService().getEvents().addListener(DayNightCycleService.EVENT_PART_OF_DAY_PASSED, this::respawn);
.
.
.
public void respawn(DayNightCycleStatus partOfDay) {
if (partOfDay == DayNightCycleStatus.DAY) {
if (ServiceLocator.getDayNightCycleService().getCurrentCycleStatus() == DayNightCycleStatus.DAY) {
//respawn
entity.getEvents().trigger("after_death");
entity.setScale(10.5f, 9.5f);
playerAlive = true;
entity.getComponent(CombatStatsComponent.class).setHealth(100);
}
}
}
References
- Artwork, B. (n.d.). 3D Illustration of Centaur with Axe and Armor. Retrieved from dreamstime: https://www.dreamstime.com/d-illustration-centaur-axe-armor-d-illustration-male-centaur-armor-holding-axe-ready-battle-image147448346
- Centaur Slam GIF. (2016, October 28). Retrieved from gfycat: https://gfycat.com/earlyneathoneybee
- Eaton, S. (n.d.). Death of the Centaur . Retrieved from solo3d: https://solo3d.wordpress.com/scenes/sculpture/death-of-the-centaur/
- Lemon, A. (1996). Death of a Centaur. Retrieved from liverpool museums: https://www.liverpoolmuseums.org.uk/artifact/death-of-centaur