added collision to NPCs
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user