play sound and change presence of tile if interacted with

This commit is contained in:
2025-12-08 05:02:36 +01:00
parent 730c7d406e
commit 285b18b4cc
5 changed files with 44 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ public class Sound {
load(8, "assets/sounds/levelup.wav");
load(9, "assets/sounds/cursor.wav");
load(10, "assets/sounds/burning.wav");
load(11, "assets/sounds/cuttree.wav");
}
@Deprecated

View File

@@ -222,7 +222,8 @@ public class Player extends Entity {
public void interactTile(int index) {
if(index == 999 || !panel.iTile[index].destructible) return;
if(!panel.iTile[index].meetItemReq(this)) return;
panel.iTile[index] = null;
panel.iTile[index].playSE();
panel.iTile[index] = panel.iTile[index].getDestroyedForm();
}
public void interactNPC(int index) {

View File

@@ -21,4 +21,12 @@ public class DryTreeTI extends InteractiveTile{
public boolean meetItemReq(Entity entity) {
return entity.currentWeapon.weaponType == EntityType.WeaponType.AXE;
}
public void playSE() {
panel.playSE(11);
}
public InteractiveTile getDestroyedForm() {
return new TrunkIT(panel, worldX/panel.tileSize, worldY/panel.tileSize);
}
}

View File

@@ -16,6 +16,13 @@ public class InteractiveTile extends Entity {
public void update() {
}
public void playSE() {}
public InteractiveTile getDestroyedForm() {
return null;
}
public boolean meetItemReq(Entity entity) {
return false;
}

View File

@@ -0,0 +1,26 @@
package de.miaurizius.jgame2d.tile.interactive;
import de.miaurizius.jgame2d.core.GamePanel;
public class TrunkIT extends InteractiveTile {
GamePanel panel;
public TrunkIT(GamePanel panel, int col, int row) {
super(panel, col, row);
this.panel = panel;
this.worldX = panel.tileSize * col;
this.worldY = panel.tileSize * row;
down1 = initEntitySprites("/interactive_tiles/trunk");
solidArea.x = 0;
solidArea.y = 0;
solidArea.width = 0;
solidArea.height = 0;
solidAreaDefaultX = 0;
solidAreaDefaultY = 0;
}
}