Item pickup
This commit is contained in:
@@ -17,6 +17,7 @@ public class Entity {
|
||||
public int spriteNum = 1;
|
||||
|
||||
public Rectangle solidArea;
|
||||
public int solidAreaDefaultX, solidAreaDefaultY;
|
||||
public boolean collisionOn = false;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public class Player extends Entity {
|
||||
|
||||
public final int screenX;
|
||||
public final int screenY;
|
||||
int hasKey = 0;
|
||||
|
||||
public Player(GamePanel panel, KeyHandler keyH) {
|
||||
this.panel = panel;
|
||||
@@ -27,6 +28,8 @@ public class Player extends Entity {
|
||||
solidArea = new Rectangle();
|
||||
solidArea.x = 12;
|
||||
solidArea.y = 20;
|
||||
solidAreaDefaultX = solidArea.x;
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
solidArea.width = 24;
|
||||
solidArea.height = 24;
|
||||
|
||||
@@ -67,6 +70,8 @@ public class Player extends Entity {
|
||||
// CHECK TILE COLLISION
|
||||
collisionOn = false;
|
||||
panel.collisionH.checkTile(this);
|
||||
int objIndex = panel.collisionH.checkObject(this, true);
|
||||
pickObject(objIndex);
|
||||
|
||||
if(!collisionOn) {
|
||||
switch (direction) {
|
||||
@@ -86,6 +91,22 @@ public class Player extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
public void pickObject(int index) {
|
||||
if(index == 999) return;
|
||||
switch(panel.obj[index].name.toLowerCase()) {
|
||||
case "key":
|
||||
hasKey++;
|
||||
panel.obj[index] = null;
|
||||
break;
|
||||
case "door":
|
||||
if(hasKey > 0) {
|
||||
panel.obj[index] = null;
|
||||
hasKey--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphics2d) {
|
||||
BufferedImage image = switch (direction) {
|
||||
case UP -> (spriteNum == 1) ? up1 : up2;
|
||||
|
||||
Reference in New Issue
Block a user