added concept for monsters

This commit is contained in:
2025-11-28 23:35:30 +01:00
parent f212e5e4a8
commit 71dc34b418
58 changed files with 73 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

BIN
assets/monster/orc_up_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

BIN
assets/monster/orc_up_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 495 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 549 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

View File

@@ -48,6 +48,7 @@ public class GamePanel extends JPanel implements Runnable {
public Player player = new Player(this, keyH); public Player player = new Player(this, keyH);
public Entity[] obj = new Entity[10]; public Entity[] obj = new Entity[10];
public Entity[] npc = new Entity[10]; public Entity[] npc = new Entity[10];
public Entity[] monster = new Entity[20];
ArrayList<Entity> entityList = new ArrayList<>(); ArrayList<Entity> entityList = new ArrayList<>();
// GAME STATE // GAME STATE
@@ -64,7 +65,7 @@ public class GamePanel extends JPanel implements Runnable {
public void setupGame() { public void setupGame() {
assetSetter.setObject(); assetSetter.setObject();
assetSetter.setNPC(); assetSetter.setNPC();
//playMusic(0); //Play main theme assetSetter.setMonster();
gameState = GameState.TITLE; gameState = GameState.TITLE;
} }
@@ -107,6 +108,7 @@ public class GamePanel extends JPanel implements Runnable {
case PLAY: case PLAY:
player.update(); player.update();
for(Entity entity : npc) if(entity != null) entity.update(); for(Entity entity : npc) if(entity != null) entity.update();
for(Entity entity : monster) if(entity != null) entity.update();
break; break;
case PAUSE: case PAUSE:
break; break;
@@ -134,6 +136,7 @@ public class GamePanel extends JPanel implements Runnable {
entityList.add(player); entityList.add(player);
for(Entity entity : npc) if(entity != null) entityList.add(entity); for(Entity entity : npc) if(entity != null) entityList.add(entity);
for(Entity entity : obj) if(entity != null) entityList.add(entity); for(Entity entity : obj) if(entity != null) entityList.add(entity);
for(Entity entity : monster) if(entity != null) entityList.add(entity);
entityList.sort(Comparator.comparingInt(o -> o.worldY)); entityList.sort(Comparator.comparingInt(o -> o.worldY));
for(Entity entity : entityList) entity.draw(graphics2d); for(Entity entity : entityList) entity.draw(graphics2d);
entityList.clear(); entityList.clear();

View File

@@ -2,6 +2,7 @@ package de.miaurizius.jgame2d.core.handlers;
import de.miaurizius.jgame2d.core.GamePanel; import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.OldManNPC; import de.miaurizius.jgame2d.entity.OldManNPC;
import de.miaurizius.jgame2d.entity.monster.GreenSlimeMON;
import de.miaurizius.jgame2d.entity.objects.DoorObj; import de.miaurizius.jgame2d.entity.objects.DoorObj;
public class AssetSetter { public class AssetSetter {
@@ -14,14 +15,6 @@ public class AssetSetter {
public void setObject() { public void setObject() {
panel.obj[0] = new DoorObj(panel);
panel.obj[0].worldX = panel.tileSize*21;
panel.obj[0].worldY = panel.tileSize*22;
panel.obj[1] = new DoorObj(panel);
panel.obj[1].worldX = panel.tileSize*23;
panel.obj[1].worldY = panel.tileSize*25;
} }
public void setNPC() { public void setNPC() {
@@ -30,4 +23,14 @@ public class AssetSetter {
panel.npc[0].worldY = panel.tileSize*21; panel.npc[0].worldY = panel.tileSize*21;
} }
public void setMonster() {
panel.monster[0] = new GreenSlimeMON(panel);
panel.monster[0].worldX = panel.tileSize*23;
panel.monster[0].worldY = panel.tileSize*36;
panel.monster[1] = new GreenSlimeMON(panel);
panel.monster[1].worldX = panel.tileSize*23;
panel.monster[1].worldY = panel.tileSize*37;
}
} }

View File

@@ -0,0 +1,51 @@
package de.miaurizius.jgame2d.entity.monster;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.enums.Direction;
import de.miaurizius.jgame2d.entity.Entity;
import java.util.Random;
public class GreenSlimeMON extends Entity {
public GreenSlimeMON(GamePanel panel) {
super(panel);
name = "green-slime";
speed = 1;
maxLife = 4;
life = maxLife;
solidArea.x = 3;
solidArea.y = 18;
solidArea.width = 42;
solidArea.height = 30;
solidAreaDefaultX = solidArea.x;
solidAreaDefaultY = solidArea.y;
getImage();
}
public void getImage() {
up1 = initEntitySprites("monster/greenslime_down_1");
up2 = initEntitySprites("monster/greenslime_down_2");
down1 = initEntitySprites("monster/greenslime_down_1");
down2 = initEntitySprites("monster/greenslime_down_2");
left1 = initEntitySprites("monster/greenslime_down_1");
left2 = initEntitySprites("monster/greenslime_down_2");
right1 = initEntitySprites("monster/greenslime_down_1");
right2 = initEntitySprites("monster/greenslime_down_2");
}
public void setAction() {
actionLock++;
if(actionLock != 120) return; //lock action for x frames
Random rand = new Random();
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
if(i <= 25) direction = Direction.UP;
if(i > 25 && i <= 50) direction = Direction.DOWN;
if(i > 50 && i <= 75) direction = Direction.LEFT;
if(i > 75) direction = Direction.RIGHT;
actionLock = 0;
}
}

View File

@@ -10,6 +10,13 @@ public class DoorObj extends Entity {
name = "door"; name = "door";
down1 = initEntitySprites("objects/door"); down1 = initEntitySprites("objects/door");
collision = true; collision = true;
solidArea.x = 0;
solidArea.y = 16;
solidArea.width = 48;
solidArea.height = 32;
solidAreaDefaultX = solidArea.x;
solidAreaDefaultY = solidArea.y;
} }
} }