refactor Orc monster actions and improve attack image initialization (closes #8)
This commit is contained in:
@@ -121,7 +121,8 @@ public class Entity {
|
|||||||
knockback = false;
|
knockback = false;
|
||||||
knockbackCount = 0;
|
knockbackCount = 0;
|
||||||
speed = defaultSpeed;
|
speed = defaultSpeed;
|
||||||
} else if(attacking) attacking(); else {
|
} else if(attacking) attacking();
|
||||||
|
else {
|
||||||
setAction();
|
setAction();
|
||||||
checkCollision();
|
checkCollision();
|
||||||
|
|
||||||
@@ -223,7 +224,7 @@ public class Entity {
|
|||||||
solidArea.width = attackArea.width;
|
solidArea.width = attackArea.width;
|
||||||
solidArea.height = attackArea.height;
|
solidArea.height = attackArea.height;
|
||||||
|
|
||||||
if(type == EntityType.MONSTER) if(panel.collisionH.checkPlayer(this)) damagePlayer(attackValue);
|
if(type == EntityType.MONSTER) if(panel.collisionH.checkPlayer(this)) damagePlayer(attack);
|
||||||
|
|
||||||
if(type == EntityType.PLAYER) {
|
if(type == EntityType.PLAYER) {
|
||||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster[panel.currentMap.getIndex()]);
|
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster[panel.currentMap.getIndex()]);
|
||||||
@@ -400,7 +401,7 @@ public class Entity {
|
|||||||
return Math.abs(worldY - target.worldY);
|
return Math.abs(worldY - target.worldY);
|
||||||
}
|
}
|
||||||
public int dTile(Entity target) {
|
public int dTile(Entity target) {
|
||||||
if(Objects.equals(name, "orc")) System.out.println("dX: " + dX(target) + " dY: " + dY(target));
|
//if(Objects.equals(name, "orc")) System.out.println("dX: " + dX(target) + " dY: " + dY(target));
|
||||||
return (dX(target) + dY(target)) / panel.tileSize;
|
return (dX(target) + dY(target)) / panel.tileSize;
|
||||||
}
|
}
|
||||||
public int getGoalCol(Entity target) {
|
public int getGoalCol(Entity target) {
|
||||||
@@ -532,7 +533,7 @@ public class Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void checkStopChasing(Entity target, int distance, int rate) {
|
public void checkStopChasing(Entity target, int distance, int rate) {
|
||||||
if(Objects.equals(name, "orc")) System.out.println("dTile: " + dTile(target) + " distance: " + distance);
|
//if(Objects.equals(name, "orc")) System.out.println("dTile: " + dTile(target) + " distance: " + distance);
|
||||||
if(dTile(target) > distance) onPath = false;
|
if(dTile(target) > distance) onPath = false;
|
||||||
}
|
}
|
||||||
public void checkStartChasing(Entity target, int distance, int rate) {
|
public void checkStartChasing(Entity target, int distance, int rate) {
|
||||||
|
|||||||
@@ -39,12 +39,8 @@ public class OrcMON extends Entity {
|
|||||||
|
|
||||||
// INTERACTION
|
// INTERACTION
|
||||||
public void setAction() {
|
public void setAction() {
|
||||||
if(!onPath) checkStartChasing(panel.player, 10 ,100);
|
if(!onPath) checkStartChasing(panel.player, 10 ,100); else followPlayer();
|
||||||
checkStopChasing(panel.player, 15, 100);
|
checkStopChasing(panel.player, 15, 100);
|
||||||
if(onPath) {
|
|
||||||
followPlayer();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setRandomDirection();
|
setRandomDirection();
|
||||||
if(!attacking) checkAttack(30, panel.tileSize*4, panel.tileSize);
|
if(!attacking) checkAttack(30, panel.tileSize*4, panel.tileSize);
|
||||||
}
|
}
|
||||||
@@ -71,13 +67,13 @@ public class OrcMON extends Entity {
|
|||||||
right2 = initEntitySprites("monster/orc_right_2");
|
right2 = initEntitySprites("monster/orc_right_2");
|
||||||
}
|
}
|
||||||
public void getAttackImage() {
|
public void getAttackImage() {
|
||||||
attackUp1 = initEntitySprites("monster/orc_attack_up_1");
|
attackUp1 = initEntitySprites("monster/orc_attack_up_1", panel.tileSize, panel.tileSize * 2);
|
||||||
attackUp2 = initEntitySprites("monster/orc_attack_up_2");
|
attackUp2 = initEntitySprites("monster/orc_attack_up_2", panel.tileSize, panel.tileSize * 2);
|
||||||
attackDown1 = initEntitySprites("monster/orc_attack_down_1");
|
attackDown1 = initEntitySprites("monster/orc_attack_down_1", panel.tileSize, panel.tileSize * 2);
|
||||||
attackDown2 = initEntitySprites("monster/orc_attack_down_2");
|
attackDown2 = initEntitySprites("monster/orc_attack_down_2", panel.tileSize, panel.tileSize * 2);
|
||||||
attackLeft1 = initEntitySprites("monster/orc_attack_left_1");
|
attackLeft1 = initEntitySprites("monster/orc_attack_left_1", panel.tileSize*2, panel.tileSize);
|
||||||
attackLeft2 = initEntitySprites("monster/orc_attack_left_2");
|
attackLeft2 = initEntitySprites("monster/orc_attack_left_2", panel.tileSize*2, panel.tileSize);
|
||||||
attackRight1 = initEntitySprites("monster/orc_attack_right_1");
|
attackRight1 = initEntitySprites("monster/orc_attack_right_1", panel.tileSize*2, panel.tileSize);
|
||||||
attackRight2 = initEntitySprites("monster/orc_attack_right_2");
|
attackRight2 = initEntitySprites("monster/orc_attack_right_2", panel.tileSize*2, panel.tileSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user