obstacles and chest loot
This commit is contained in:
57
src/de/miaurizius/jgame2d/entity/obstacle/ChestObj.java
Normal file
57
src/de/miaurizius/jgame2d/entity/obstacle/ChestObj.java
Normal file
@@ -0,0 +1,57 @@
|
||||
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.inventory.size() == panel.player.maxInvSize) {
|
||||
sb.append("\nBut your inventory is full...");
|
||||
panel.ui.currentDialogue = sb.toString();
|
||||
return;
|
||||
}
|
||||
sb.append("\nYou obtain the ").append(loot.name).append("!");
|
||||
panel.player.inventory.add(loot);
|
||||
down1 = image2;
|
||||
opened = true;
|
||||
panel.ui.currentDialogue = sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user