refactor invincibility handling by consolidating invincible counting logic into a separate method
This commit is contained in:
@@ -108,6 +108,7 @@ public class Entity {
|
|||||||
knockbackCount = 0;
|
knockbackCount = 0;
|
||||||
knockback = false;
|
knockback = false;
|
||||||
speed = defaultSpeed;
|
speed = defaultSpeed;
|
||||||
|
invincibleCounting();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +120,10 @@ public class Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
knockbackCount++;
|
knockbackCount++;
|
||||||
if(knockbackCount != 10) return;
|
if(knockbackCount != 10) {
|
||||||
|
invincibleCounting();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
knockback = false;
|
knockback = false;
|
||||||
knockbackCount = 0;
|
knockbackCount = 0;
|
||||||
@@ -146,14 +150,7 @@ public class Entity {
|
|||||||
spriteCount = 0;
|
spriteCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
invincibleCounting();
|
||||||
// INVINCIBLE COUNTER
|
|
||||||
if(!invincible) return;
|
|
||||||
invincibleCount++;
|
|
||||||
if(invincibleCount > 40) {
|
|
||||||
invincible = false;
|
|
||||||
invincibleCount = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public void draw(Graphics2D graphics2d) {
|
public void draw(Graphics2D graphics2d) {
|
||||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||||
@@ -613,5 +610,13 @@ public class Entity {
|
|||||||
actionLock = 0;
|
actionLock = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void invincibleCounting() {
|
||||||
|
if(!invincible) return;
|
||||||
|
invincibleCount++;
|
||||||
|
if(invincibleCount > 40) {
|
||||||
|
invincible = false;
|
||||||
|
invincibleCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,12 +55,14 @@ public class Player extends Entity {
|
|||||||
// ATTACKING
|
// ATTACKING
|
||||||
if(attacking) {
|
if(attacking) {
|
||||||
attacking();
|
attacking();
|
||||||
|
invincibleCounting();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BLOCKING
|
// BLOCKING
|
||||||
if(keyH.CTLKeyPressed) {
|
if(keyH.CTLKeyPressed) {
|
||||||
guarding = true;
|
guarding = true;
|
||||||
|
invincibleCounting();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,12 +140,7 @@ public class Player extends Entity {
|
|||||||
|
|
||||||
// INVINCIBLE COUNTER
|
// INVINCIBLE COUNTER
|
||||||
if(!invincible) return;
|
if(!invincible) return;
|
||||||
invincibleCount++;
|
invincibleCounting();
|
||||||
if(invincibleCount > 60) {
|
|
||||||
invincible = false;
|
|
||||||
transparent = false;
|
|
||||||
invincibleCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(life <= 0) {
|
if(life <= 0) {
|
||||||
panel.gameState = GameState.GAMEOVER;
|
panel.gameState = GameState.GAMEOVER;
|
||||||
@@ -204,6 +201,7 @@ public class Player extends Entity {
|
|||||||
panel.playSE(5);
|
panel.playSE(5);
|
||||||
if(knockbackVal > 0) setKnockback(panel.monster[panel.currentMap.getIndex()][index], attacker, knockbackVal);
|
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].life -= damage;
|
||||||
|
panel.monster[panel.currentMap.getIndex()][index].transparent = true;
|
||||||
panel.monster[panel.currentMap.getIndex()][index].invincible = true;
|
panel.monster[panel.currentMap.getIndex()][index].invincible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,5 +393,14 @@ public class Player extends Entity {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void invincibleCounting() {
|
||||||
|
if(!invincible) return;
|
||||||
|
invincibleCount++;
|
||||||
|
if(invincibleCount > 60) {
|
||||||
|
invincible = false;
|
||||||
|
invincibleCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user