Compare commits

...

6 Commits

Author SHA1 Message Date
600a225064 added hitbox of ITiles to entities 2025-12-08 05:11:46 +01:00
9916fa8b25 added iTile life 2025-12-08 05:09:21 +01:00
285b18b4cc play sound and change presence of tile if interacted with 2025-12-08 05:02:36 +01:00
730c7d406e added item requirements 2025-12-08 04:52:48 +01:00
49c8b59d68 created destructible tiles 2025-12-08 04:48:27 +01:00
5f9fd8ea99 added jpackage config 2025-12-08 04:29:15 +01:00
16 changed files with 143 additions and 2 deletions

3
.gitignore vendored
View File

@@ -30,3 +30,6 @@ bin/
### Mac OS ### ### Mac OS ###
.DS_Store .DS_Store
### JPackage ###
JGame2D

View File

@@ -3,6 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />

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

7
build.sh Normal file
View File

@@ -0,0 +1,7 @@
jpackage \
--input out/artifacts/JGame2D_jar/ \
--main-jar JGame2D.jar \
--main-class de.miaurizius.jgame2d.core.Boot \
--name JGame2D \
--type app-image \
--add-modules ALL-MODULE-PATH

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

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

View File

@@ -86,6 +86,7 @@ public class Entity {
panel.collisionH.checkObject(this, false); panel.collisionH.checkObject(this, false);
panel.collisionH.checkEntity(this, panel.npc); panel.collisionH.checkEntity(this, panel.npc);
panel.collisionH.checkEntity(this, panel.monster); panel.collisionH.checkEntity(this, panel.monster);
panel.collisionH.checkEntity(this, panel.iTile);
boolean contactPlayer = panel.collisionH.checkPlayer(this); boolean contactPlayer = panel.collisionH.checkPlayer(this);
if(this.type == EntityType.MONSTER && contactPlayer) damagePlayer(attack); if(this.type == EntityType.MONSTER && contactPlayer) damagePlayer(attack);

View File

@@ -79,6 +79,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 +184,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 +219,14 @@ public class Player extends Entity {
checkLevelUp(); checkLevelUp();
} }
} }
public void interactTile(int index) {
if(index == 999 || !panel.iTile[index].destructible || panel.iTile[index].invincible) return;
if(!panel.iTile[index].meetItemReq(this)) return;
panel.iTile[index].playSE();
panel.iTile[index].life--;
panel.iTile[index].invincible = true;
if(panel.iTile[index].life == 0) panel.iTile[index] = panel.iTile[index].getDestroyedForm();
}
public void interactNPC(int index) { public void interactNPC(int index) {
if(index == 999) return; if(index == 999) return;

View File

@@ -0,0 +1,34 @@
package de.miaurizius.jgame2d.tile.interactive;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.enums.EntityType;
import de.miaurizius.jgame2d.entity.Entity;
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;
life = 3;
}
// PRE_CONFIGURED
public void playSE() {
panel.playSE(11);
}
// GETTERS
public boolean meetItemReq(Entity entity) {
return entity.currentWeapon.weaponType == EntityType.WeaponType.AXE;
}
public InteractiveTile getDestroyedForm() {
return new TrunkIT(panel, worldX/panel.tileSize, worldY/panel.tileSize);
}
}

View File

@@ -0,0 +1,37 @@
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;
}
// GENERAL
public void update() {
// INVINCIBLE COUNTER
if(!invincible) return;
invincibleCount++;
if(invincibleCount > 20) {
invincible = false;
invincibleCount = 0;
}
}
// PRE-CONFIGURED
public void playSE() {}
// UTILITY
public boolean meetItemReq(Entity entity) {
return false;
}
public InteractiveTile getDestroyedForm() {
return null;
}
}

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;
}
}