refactor invincibility handling by consolidating invincible counting logic into a separate method
This commit is contained in:
@@ -55,12 +55,14 @@ public class Player extends Entity {
|
||||
// ATTACKING
|
||||
if(attacking) {
|
||||
attacking();
|
||||
invincibleCounting();
|
||||
return;
|
||||
}
|
||||
|
||||
// BLOCKING
|
||||
if(keyH.CTLKeyPressed) {
|
||||
guarding = true;
|
||||
invincibleCounting();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,12 +140,7 @@ public class Player extends Entity {
|
||||
|
||||
// INVINCIBLE COUNTER
|
||||
if(!invincible) return;
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 60) {
|
||||
invincible = false;
|
||||
transparent = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
invincibleCounting();
|
||||
|
||||
if(life <= 0) {
|
||||
panel.gameState = GameState.GAMEOVER;
|
||||
@@ -204,6 +201,7 @@ public class Player extends Entity {
|
||||
panel.playSE(5);
|
||||
if(knockbackVal > 0) setKnockback(panel.monster[panel.currentMap.getIndex()][index], attacker, knockbackVal);
|
||||
panel.monster[panel.currentMap.getIndex()][index].life -= damage;
|
||||
panel.monster[panel.currentMap.getIndex()][index].transparent = true;
|
||||
panel.monster[panel.currentMap.getIndex()][index].invincible = true;
|
||||
}
|
||||
|
||||
@@ -395,5 +393,14 @@ public class Player extends Entity {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void invincibleCounting() {
|
||||
if(!invincible) return;
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 60) {
|
||||
invincible = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user