added monster drops

This commit is contained in:
2025-12-07 00:57:54 +01:00
parent 6254eb2501
commit 1443722f0c
3 changed files with 27 additions and 2 deletions

View File

@@ -46,7 +46,7 @@ public class GamePanel extends JPanel implements Runnable {
// ENTITY AND OBJECT
public Player player = new Player(this, keyH);
public Entity[] obj = new Entity[10];
public Entity[] obj = new Entity[20];
public Entity[] npc = new Entity[10];
public Entity[] monster = new Entity[20];
public ArrayList<Entity> projectileList = new ArrayList<>();
@@ -107,7 +107,10 @@ public class GamePanel extends JPanel implements Runnable {
Entity m = monster[i];
if(m != null) {
if(m.alive && !m.dying) m.update();
if(!m.alive) monster[i] = null;
if(!m.alive) {
monster[i].checkDrop();
monster[i] = null;
}
}
}
for(int i = 0; i < projectileList.size(); i++) {

View File

@@ -199,6 +199,19 @@ public class Entity {
}
public void use(Entity entity) {
} //If entity is consumable
public void checkDrop() {
}
public void dropItem(Entity droppedItem) {
for(int i = 0; i < panel.obj.length; i++) {
if(panel.obj[i] == null) {
panel.obj[i] = droppedItem;
panel.obj[i].worldX = worldX;
panel.obj[i].worldY = worldY;
break;
}
}
}
// SETTING THINGS UP
BufferedImage parseSprite() {

View File

@@ -4,6 +4,9 @@ import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.enums.Direction;
import de.miaurizius.jgame2d.core.enums.EntityType;
import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.entity.item.CoinObj;
import de.miaurizius.jgame2d.entity.item.HeartObj;
import de.miaurizius.jgame2d.entity.item.PotionObj;
import de.miaurizius.jgame2d.entity.projectile.RockObj;
import java.util.Random;
@@ -56,6 +59,12 @@ public class GreenSlimeMON extends Entity {
actionLock = 0;
direction = panel.player.direction;
}
public void checkDrop() {
int i = new Random().nextInt(100)+1;
if(i < 50) dropItem(new CoinObj(panel));
if(i >= 50 && i < 75) dropItem(new HeartObj(panel));
if(i >= 75 && i < 100) dropItem(new PotionObj(panel));
}
// SETTING THINGS UP
public void getImage() {