created destructible tiles

This commit is contained in:
2025-12-08 04:48:27 +01:00
parent 5f9fd8ea99
commit 49c8b59d68
10 changed files with 65 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@@ -10,7 +10,7 @@
12 12 12 12 12 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 17 12 12 12 18 10 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 12 12 12 12 12 12 12 12 12 12 12 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 17 12 12 12 18 10 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 12 12 12 12 12 12
12 12 12 13 12 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 17 12 12 12 18 11 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 13 12 12 12 12 12 12 12 12 13 12 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 17 12 12 12 18 11 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 13 12 12 12 12 12
12 12 12 12 13 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 19 20 20 20 21 10 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 12 12 12 12 12 12 12 12 12 12 13 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 19 20 20 20 21 10 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 12 12 12 12 12 12
12 12 12 12 12 12 18 41 40 40 39 40 40 41 41 41 41 41 41 41 11 10 35 33 36 10 10 41 41 41 41 41 41 41 37 28 28 29 26 27 28 38 17 13 12 12 12 12 12 12 12 12 12 12 12 12 18 41 40 40 39 40 40 41 41 41 41 41 41 41 11 10 35 33 36 10 10 10 10 10 10 10 10 10 37 28 28 29 26 27 28 38 17 13 12 12 12 12 12 12
12 12 12 12 12 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 14 15 25 12 12 12 12 12 12 12 12 12 12 12 12 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 14 15 25 12 12 12 12 12 12 12
12 12 12 12 13 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 13 12 12 12 12 12 12 12 12 13 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 13 12 12 12 12
12 12 12 12 12 12 24 15 16 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 24 15 16 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 12 12 12 12 12

View File

@@ -5,6 +5,7 @@ import de.miaurizius.jgame2d.core.handlers.*;
import de.miaurizius.jgame2d.entity.Entity; import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.entity.Player; import de.miaurizius.jgame2d.entity.Player;
import de.miaurizius.jgame2d.tile.TileManager; import de.miaurizius.jgame2d.tile.TileManager;
import de.miaurizius.jgame2d.tile.interactive.InteractiveTile;
import javax.sound.sampled.Clip; import javax.sound.sampled.Clip;
import javax.swing.*; import javax.swing.*;
@@ -49,6 +50,7 @@ public class GamePanel extends JPanel implements Runnable {
public Entity[] obj = new Entity[20]; public Entity[] obj = new Entity[20];
public Entity[] npc = new Entity[10]; public Entity[] npc = new Entity[10];
public Entity[] monster = new Entity[20]; public Entity[] monster = new Entity[20];
public InteractiveTile[] iTile = new InteractiveTile[50];
public ArrayList<Entity> projectileList = new ArrayList<>(); public ArrayList<Entity> projectileList = new ArrayList<>();
ArrayList<Entity> entityList = new ArrayList<>(); ArrayList<Entity> entityList = new ArrayList<>();
@@ -120,6 +122,7 @@ public class GamePanel extends JPanel implements Runnable {
else projectileList.remove(i); else projectileList.remove(i);
} }
} }
for(Entity entity : iTile) if(entity != null) entity.update();
break; break;
case PAUSE: case PAUSE:
break; break;
@@ -141,6 +144,7 @@ public class GamePanel extends JPanel implements Runnable {
// GAME // GAME
tileM.draw(graphics2d); tileM.draw(graphics2d);
for(Entity entity : iTile) if(entity != null) entity.draw(graphics2d);
// ENTITY RENDER SYSTEM // ENTITY RENDER SYSTEM
entityList.add(player); entityList.add(player);
@@ -196,6 +200,7 @@ public class GamePanel extends JPanel implements Runnable {
assetSetter.setObject(); assetSetter.setObject();
assetSetter.setNPC(); assetSetter.setNPC();
assetSetter.setMonster(); assetSetter.setMonster();
assetSetter.setITiles();
gameState = GameState.TITLE; gameState = GameState.TITLE;
} }

View File

@@ -4,6 +4,7 @@ import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.item.*; import de.miaurizius.jgame2d.entity.item.*;
import de.miaurizius.jgame2d.entity.npc.OldManNPC; import de.miaurizius.jgame2d.entity.npc.OldManNPC;
import de.miaurizius.jgame2d.entity.monster.GreenSlimeMON; import de.miaurizius.jgame2d.entity.monster.GreenSlimeMON;
import de.miaurizius.jgame2d.tile.interactive.DryTreeTI;
public class AssetSetter { public class AssetSetter {
@@ -74,4 +75,15 @@ public class AssetSetter {
panel.monster[i].worldY = panel.tileSize*42; panel.monster[i].worldY = panel.tileSize*42;
} }
public void setITiles() {
int i = 0;
panel.iTile[i] = new DryTreeTI(panel,27,12);i++;
panel.iTile[i] = new DryTreeTI(panel,28,12);i++;
panel.iTile[i] = new DryTreeTI(panel,29,12);i++;
panel.iTile[i] = new DryTreeTI(panel,30,12);i++;
panel.iTile[i] = new DryTreeTI(panel,31,12);i++;
panel.iTile[i] = new DryTreeTI(panel,32,12);i++;
panel.iTile[i] = new DryTreeTI(panel,33,12);i++;
}
} }

View File

@@ -8,6 +8,7 @@ import de.miaurizius.jgame2d.core.handlers.KeyHandler;
import de.miaurizius.jgame2d.entity.item.ShieldWoodObj; import de.miaurizius.jgame2d.entity.item.ShieldWoodObj;
import de.miaurizius.jgame2d.entity.item.SwordNormalObj; import de.miaurizius.jgame2d.entity.item.SwordNormalObj;
import de.miaurizius.jgame2d.entity.projectile.FireballObj; import de.miaurizius.jgame2d.entity.projectile.FireballObj;
import de.miaurizius.jgame2d.tile.interactive.InteractiveTile;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
@@ -79,6 +80,9 @@ public class Player extends Entity {
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster); int monsterIndex = panel.collisionH.checkEntity(this, panel.monster);
interactMonster(monsterIndex); interactMonster(monsterIndex);
// CHECK INTERACTIVE TILE COLLISION
int iTileIndex = panel.collisionH.checkEntity(this, panel.iTile);
// CHECK EVENT // CHECK EVENT
panel.eventH.checkEvent(); panel.eventH.checkEvent();
@@ -181,6 +185,9 @@ public class Player extends Entity {
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster); int monsterIndex = panel.collisionH.checkEntity(this, panel.monster);
damageMonster(monsterIndex, attack); damageMonster(monsterIndex, attack);
int iTileIndex = panel.collisionH.checkEntity(this, panel.iTile);
interactTile(iTileIndex);
worldX = currentWorldX; worldX = currentWorldX;
worldY = currentWorldY; worldY = currentWorldY;
solidArea.width = solidAreaWidth; solidArea.width = solidAreaWidth;
@@ -213,6 +220,10 @@ public class Player extends Entity {
checkLevelUp(); checkLevelUp();
} }
} }
public void interactTile(int index) {
if(index == 999 || !panel.iTile[index].destructible) return;
panel.iTile[index] = null;
}
public void interactNPC(int index) { public void interactNPC(int index) {
if(index == 999) return; if(index == 999) return;

View File

@@ -0,0 +1,18 @@
package de.miaurizius.jgame2d.tile.interactive;
import de.miaurizius.jgame2d.core.GamePanel;
public class DryTreeTI extends InteractiveTile{
GamePanel panel;
public DryTreeTI(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/drytree");
destructible = true;
}
}

View File

@@ -0,0 +1,18 @@
package de.miaurizius.jgame2d.tile.interactive;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.Entity;
public class InteractiveTile extends Entity {
GamePanel panel;
public boolean destructible;
public InteractiveTile(GamePanel panel, int col, int row) {
super(panel);
this.panel = panel;
}
public void update() {
}
}