added hit detection when player hits monsters

This commit is contained in:
2025-11-29 22:57:39 +01:00
parent 005662e800
commit 0dde029719
3 changed files with 72 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ public class Entity {
public BufferedImage attackUp1, attackUp2, attackDown1, attackDown2, attackLeft1, attackLeft2, attackRight1, attackRight2;
public BufferedImage image, image2, image3;
public Rectangle solidArea = new Rectangle(0, 0, 48, 48);
public Rectangle attackArea = new Rectangle(0, 0, 0, 0);
public int solidAreaDefaultX, solidAreaDefaultY;
public boolean collision = false;
String[] dialogue = new String[20];
@@ -119,6 +120,15 @@ public class Entity {
};
}
BufferedImage parseSpriteATK() {
return switch (direction) {
case UP -> (spriteNum == 1) ? attackUp1 : attackUp2;
case DOWN -> (spriteNum == 1) ? attackDown1 : attackDown2;
case LEFT -> (spriteNum == 1) ? attackLeft1 : attackLeft2;
case RIGHT -> (spriteNum == 1) ? attackRight1 : attackRight2;
};
}
public BufferedImage initEntitySprites(String name) {
try {
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), panel.tileSize, panel.tileSize);