57 lines
1.6 KiB
Java
57 lines
1.6 KiB
Java
package de.miaurizius.jgame2d.entity.obstacle;
|
|
|
|
import de.miaurizius.jgame2d.core.GamePanel;
|
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
|
import de.miaurizius.jgame2d.core.enums.GameState;
|
|
import de.miaurizius.jgame2d.entity.Entity;
|
|
|
|
public class ChestObj extends Entity {
|
|
|
|
GamePanel panel;
|
|
Entity loot;
|
|
boolean opened;
|
|
|
|
public ChestObj(GamePanel panel, Entity loot) {
|
|
super(panel);
|
|
this.panel = panel;
|
|
this.loot = loot;
|
|
type = EntityType.OBSTACLE;
|
|
name = "chest";
|
|
|
|
image = initEntitySprites("objects/chest");
|
|
image2 = initEntitySprites("objects/chest_opened");
|
|
down1 = image;
|
|
collision = true;
|
|
|
|
solidArea.x = 4;
|
|
solidArea.y = 16;
|
|
solidArea.width = 40;
|
|
solidArea.height = 32;
|
|
solidAreaDefaultX = solidArea.x;
|
|
solidAreaDefaultY = solidArea.y;
|
|
}
|
|
|
|
@Override
|
|
public void interact() {
|
|
panel.gameState = GameState.DIALOGUE;
|
|
|
|
if(opened) {
|
|
panel.ui.currentDialogue = "It's already empty...";
|
|
return;
|
|
}
|
|
panel.playSE(3);
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("You open the chest and find a ").append(loot.name).append("!");
|
|
if(!panel.player.canObtainItem(loot)) {
|
|
sb.append("\nBut your inventory is full...");
|
|
panel.ui.currentDialogue = sb.toString();
|
|
return;
|
|
}
|
|
sb.append("\nYou obtain the ").append(loot.name).append("!");
|
|
down1 = image2;
|
|
opened = true;
|
|
panel.ui.currentDialogue = sb.toString();
|
|
}
|
|
|
|
}
|