add guarding mechanic and implement guard sprite handling
This commit is contained in:
@@ -18,6 +18,7 @@ public class Player extends Entity {
|
||||
KeyHandler keyH;
|
||||
public final int screenX;
|
||||
public final int screenY;
|
||||
private int standCount;
|
||||
|
||||
// STATE
|
||||
public boolean attackCancel;
|
||||
@@ -44,16 +45,25 @@ public class Player extends Entity {
|
||||
setDefaultValues();
|
||||
getPlayerImage();
|
||||
getPlayerAttackImage();
|
||||
getGuardImages();
|
||||
}
|
||||
|
||||
// DEFAULT
|
||||
public void update() {
|
||||
if(life > maxLife) life = maxLife;
|
||||
|
||||
// ATTACKING
|
||||
if(attacking) {
|
||||
attacking();
|
||||
return;
|
||||
}
|
||||
|
||||
// BLOCKING
|
||||
if(keyH.CTLKeyPressed) {
|
||||
guarding = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// MOVEMENT
|
||||
if(keyH.upPressed || keyH.downPressed || keyH.leftPressed || keyH.rightPressed || keyH.spacePressed) {
|
||||
if(!keyH.spacePressed) {
|
||||
@@ -102,6 +112,7 @@ public class Player extends Entity {
|
||||
|
||||
attackCancel = false;
|
||||
panel.keyH.spacePressed = false;
|
||||
guarding = false;
|
||||
|
||||
spriteCount++;
|
||||
if(spriteCount > 12) {
|
||||
@@ -110,6 +121,13 @@ public class Player extends Entity {
|
||||
else spriteNum = 0;
|
||||
spriteCount = 0;
|
||||
}
|
||||
} else {
|
||||
standCount++;
|
||||
if(standCount == 20) {
|
||||
spriteNum = 1;
|
||||
standCount = 0;
|
||||
}
|
||||
guarding = false;
|
||||
}
|
||||
|
||||
if(panel.keyH.shotKeyPressed && !projectile.alive) {
|
||||
@@ -123,6 +141,7 @@ public class Player extends Entity {
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 60) {
|
||||
invincible = false;
|
||||
transparent = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
|
||||
@@ -169,11 +188,10 @@ public class Player extends Entity {
|
||||
|
||||
int damage = panel.monster[panel.currentMap.getIndex()][index].attack - defense;
|
||||
|
||||
if(damage > 0) {
|
||||
panel.playSE(6);
|
||||
life -= damage;
|
||||
invincible = true;
|
||||
}
|
||||
panel.playSE(6);
|
||||
life -= Math.max(damage, 0);
|
||||
if(damage != 0) panel.player.transparent = true;
|
||||
invincible = true;
|
||||
|
||||
}
|
||||
public void damageMonster(int index, Entity attacker, int attack, int knockbackVal) {
|
||||
@@ -347,6 +365,12 @@ public class Player extends Entity {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void getGuardImages() {
|
||||
guardUp = initEntitySprites("player/guarding/boy_guard_up");
|
||||
guardDown = initEntitySprites("player/guarding/boy_guard_down");
|
||||
guardLeft = initEntitySprites("player/guarding/boy_guard_left");
|
||||
guardRight = initEntitySprites("player/guarding/boy_guard_right");
|
||||
}
|
||||
public int searchItemInInventory(String itemName) {
|
||||
for(int i = 0; i < inventory.size(); i++) {
|
||||
if(inventory.get(i).name.equals(itemName)) {
|
||||
|
||||
Reference in New Issue
Block a user