added player stats and re-ordered some classes
This commit is contained in:
@@ -5,6 +5,8 @@ import de.miaurizius.jgame2d.core.enums.Direction;
|
|||||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
import de.miaurizius.jgame2d.core.enums.GameState;
|
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||||
import de.miaurizius.jgame2d.core.handlers.KeyHandler;
|
import de.miaurizius.jgame2d.core.handlers.KeyHandler;
|
||||||
|
import de.miaurizius.jgame2d.entity.item.ShieldWoodObj;
|
||||||
|
import de.miaurizius.jgame2d.entity.item.SwordNormalObj;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@@ -14,6 +16,9 @@ public class Player extends Entity {
|
|||||||
public final int screenX;
|
public final int screenX;
|
||||||
public final int screenY;
|
public final int screenY;
|
||||||
|
|
||||||
|
// STATE
|
||||||
|
public boolean attackCancel;
|
||||||
|
|
||||||
public Player(GamePanel panel, KeyHandler keyH) {
|
public Player(GamePanel panel, KeyHandler keyH) {
|
||||||
super(panel);
|
super(panel);
|
||||||
this.keyH = keyH;
|
this.keyH = keyH;
|
||||||
@@ -83,6 +88,16 @@ public class Player extends Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("cancel: "+attackCancel);
|
||||||
|
if(keyH.spacePressed && !attackCancel) {
|
||||||
|
System.out.println("entered");
|
||||||
|
panel.playSE(7);
|
||||||
|
attacking = true;
|
||||||
|
spriteCounter = 0;
|
||||||
|
}
|
||||||
|
System.out.println("attacking: "+attacking);
|
||||||
|
|
||||||
|
attackCancel = false;
|
||||||
panel.keyH.spacePressed = false;
|
panel.keyH.spacePressed = false;
|
||||||
|
|
||||||
spriteCounter++;
|
spriteCounter++;
|
||||||
@@ -117,6 +132,7 @@ public class Player extends Entity {
|
|||||||
invincible = true;
|
invincible = true;
|
||||||
}
|
}
|
||||||
public void attacking() {
|
public void attacking() {
|
||||||
|
if(attackCancel) return;
|
||||||
spriteCounter++;
|
spriteCounter++;
|
||||||
if(spriteCounter <= 5) spriteNum = 1;
|
if(spriteCounter <= 5) spriteNum = 1;
|
||||||
if(spriteCounter > 5 && spriteCounter <= 25) {
|
if(spriteCounter > 5 && spriteCounter <= 25) {
|
||||||
@@ -161,14 +177,9 @@ public class Player extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void interactNPC(int index) {
|
public void interactNPC(int index) {
|
||||||
if(index == 999) {
|
if(index == 999) return;
|
||||||
if(panel.keyH.spacePressed) {
|
|
||||||
attacking = true;
|
|
||||||
//panel.playSE(7); //remains disabled because game does weird things while playing the sound
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space
|
//if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space
|
||||||
|
attackCancel = true;
|
||||||
panel.gameState = GameState.DIALOGUE;
|
panel.gameState = GameState.DIALOGUE;
|
||||||
panel.npc[index].speak();
|
panel.npc[index].speak();
|
||||||
}
|
}
|
||||||
@@ -187,6 +198,22 @@ public class Player extends Entity {
|
|||||||
// PLAYER STATUS (1 heart = 2 lives)
|
// PLAYER STATUS (1 heart = 2 lives)
|
||||||
maxLife = 6;
|
maxLife = 6;
|
||||||
life = maxLife;
|
life = maxLife;
|
||||||
|
level = 1;
|
||||||
|
strength = 1;
|
||||||
|
dexterity = 1;
|
||||||
|
exp = 0;
|
||||||
|
nextLevelExp = 5;
|
||||||
|
coins = 0;
|
||||||
|
currentWeapon = new SwordNormalObj(panel);
|
||||||
|
currentShield = new ShieldWoodObj(panel);
|
||||||
|
attack = getAttack();
|
||||||
|
defense = getDefense();
|
||||||
|
}
|
||||||
|
public int getAttack() {
|
||||||
|
return attack = strength * currentWeapon.attackValue;
|
||||||
|
}
|
||||||
|
public int getDefense() {
|
||||||
|
return defense = dexterity * currentShield.attackValue;
|
||||||
}
|
}
|
||||||
public void getPlayerImage() {
|
public void getPlayerImage() {
|
||||||
up1 = initEntitySprites("player/boy_up_1");
|
up1 = initEntitySprites("player/boy_up_1");
|
||||||
|
|||||||
Reference in New Issue
Block a user