added collision to NPCs

This commit is contained in:
2025-11-28 17:21:35 +01:00
parent b294eb49c8
commit 1f614916b5
3 changed files with 98 additions and 0 deletions

View File

@@ -35,6 +35,8 @@ public class Entity {
setAction();
collisionOn = false;
panel.collisionH.checkTile(this);
panel.collisionH.checkObject(this, false);
panel.collisionH.checkPlayer(this);
if(!collisionOn) {
switch (direction) {

View File

@@ -62,9 +62,15 @@ public class Player extends Entity {
// CHECK TILE COLLISION
collisionOn = false;
panel.collisionH.checkTile(this);
// CHECK OBJECT COLLISION
int objIndex = panel.collisionH.checkObject(this, true);
pickObject(objIndex);
// CHECK ENTITY COLLISION
int npcIndex = panel.collisionH.checkEntity(this, panel.npc);
interactNPC(npcIndex);
if(!collisionOn) {
switch (direction) {
case UP -> worldY -= speed;
@@ -88,6 +94,11 @@ public class Player extends Entity {
}
public void interactNPC(int index) {
if(index == 999) return;
System.out.println("npc collision detected");
}
public void draw(Graphics2D graphics2d) {
BufferedImage image = switch (direction) {
case UP -> (spriteNum == 1) ? up1 : up2;