Compare commits
2 Commits
54458293ba
...
1443722f0c
| Author | SHA1 | Date | |
|---|---|---|---|
|
1443722f0c
|
|||
|
6254eb2501
|
@@ -46,7 +46,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
|
|
||||||
// ENTITY AND OBJECT
|
// ENTITY AND OBJECT
|
||||||
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[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 ArrayList<Entity> projectileList = new ArrayList<>();
|
public ArrayList<Entity> projectileList = new ArrayList<>();
|
||||||
@@ -107,7 +107,10 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
Entity m = monster[i];
|
Entity m = monster[i];
|
||||||
if(m != null) {
|
if(m != null) {
|
||||||
if(m.alive && !m.dying) m.update();
|
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++) {
|
for(int i = 0; i < projectileList.size(); i++) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public enum EntityType {
|
|||||||
MONSTER,
|
MONSTER,
|
||||||
ITEM,
|
ITEM,
|
||||||
WORLD,
|
WORLD,
|
||||||
|
PICKUP,
|
||||||
PROJECTILE,
|
PROJECTILE,
|
||||||
WEAPON,
|
WEAPON,
|
||||||
SHIELD;
|
SHIELD;
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
package de.miaurizius.jgame2d.core.handlers;
|
package de.miaurizius.jgame2d.core.handlers;
|
||||||
|
|
||||||
import de.miaurizius.jgame2d.core.GamePanel;
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
import de.miaurizius.jgame2d.entity.item.AxeObj;
|
import de.miaurizius.jgame2d.entity.item.*;
|
||||||
import de.miaurizius.jgame2d.entity.item.IronShieldObj;
|
|
||||||
import de.miaurizius.jgame2d.entity.item.KeyObj;
|
|
||||||
import de.miaurizius.jgame2d.entity.item.PotionObj;
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -18,12 +15,12 @@ public class AssetSetter {
|
|||||||
|
|
||||||
public void setObject() {
|
public void setObject() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
panel.obj[i] = new KeyObj(panel);
|
panel.obj[i] = new HeartObj(panel);
|
||||||
panel.obj[i].worldX = panel.tileSize*25;
|
panel.obj[i].worldX = panel.tileSize*25;
|
||||||
panel.obj[i].worldY = panel.tileSize*23;
|
panel.obj[i].worldY = panel.tileSize*23;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
panel.obj[i] = new KeyObj(panel);
|
panel.obj[i] = new CoinObj(panel);
|
||||||
panel.obj[i].worldX = panel.tileSize*21;
|
panel.obj[i].worldX = panel.tileSize*21;
|
||||||
panel.obj[i].worldY = panel.tileSize*19;
|
panel.obj[i].worldY = panel.tileSize*19;
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class Entity {
|
|||||||
public int defenseValue;
|
public int defenseValue;
|
||||||
public String description;
|
public String description;
|
||||||
public int useCost;
|
public int useCost;
|
||||||
|
public int value;
|
||||||
|
|
||||||
public Entity(GamePanel panel) {
|
public Entity(GamePanel panel) {
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
@@ -198,6 +199,19 @@ public class Entity {
|
|||||||
}
|
}
|
||||||
public void use(Entity entity) {
|
public void use(Entity entity) {
|
||||||
} //If entity is consumable
|
} //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
|
// SETTING THINGS UP
|
||||||
BufferedImage parseSprite() {
|
BufferedImage parseSprite() {
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ public class Player extends Entity {
|
|||||||
|
|
||||||
// DEFAULT
|
// DEFAULT
|
||||||
public void update() {
|
public void update() {
|
||||||
|
if(life > maxLife) life = maxLife;
|
||||||
|
|
||||||
if(attacking) {
|
if(attacking) {
|
||||||
attacking();
|
attacking();
|
||||||
return;
|
return;
|
||||||
@@ -124,14 +126,22 @@ public class Player extends Entity {
|
|||||||
|
|
||||||
// INTERACTION
|
// INTERACTION
|
||||||
public void pickObject(int index) {
|
public void pickObject(int index) {
|
||||||
if(index == 999) return;
|
if(index == 999 || panel.obj[index] == null) return;
|
||||||
if(inventory.size() == maxInvSize) {
|
|
||||||
panel.ui.addMessage("Your inventory is full!");
|
// PICKUP ONLY
|
||||||
return;
|
if(panel.obj[index].type == EntityType.PICKUP) {
|
||||||
|
panel.obj[index].use(this);
|
||||||
|
}
|
||||||
|
// INVENTORY ITEMS
|
||||||
|
else {
|
||||||
|
if(inventory.size() == maxInvSize) {
|
||||||
|
panel.ui.addMessage("Your inventory is full!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
inventory.add(panel.obj[index]);
|
||||||
|
panel.playSE(1);
|
||||||
|
panel.ui.addMessage("Picked up " + panel.obj[index].name + "!");
|
||||||
}
|
}
|
||||||
inventory.add(panel.obj[index]);
|
|
||||||
panel.playSE(1);
|
|
||||||
panel.ui.addMessage("Picked up " + panel.obj[index].name + "!");
|
|
||||||
panel.obj[index] = null;
|
panel.obj[index] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
src/de/miaurizius/jgame2d/entity/item/CoinObj.java
Normal file
26
src/de/miaurizius/jgame2d/entity/item/CoinObj.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package de.miaurizius.jgame2d.entity.item;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
|
|
||||||
|
public class CoinObj extends Entity {
|
||||||
|
|
||||||
|
GamePanel panel;
|
||||||
|
|
||||||
|
public CoinObj(GamePanel panel) {
|
||||||
|
super(panel);
|
||||||
|
this.panel = panel;
|
||||||
|
|
||||||
|
name = "Coin";
|
||||||
|
type = EntityType.PICKUP;
|
||||||
|
value = 1;
|
||||||
|
down1 = initEntitySprites("/objects/coin_bronze");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void use(Entity entity) {
|
||||||
|
panel.playSE(1);
|
||||||
|
panel.ui.addMessage("Coin +"+value);
|
||||||
|
panel.player.coins += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,13 +6,26 @@ import de.miaurizius.jgame2d.entity.Entity;
|
|||||||
|
|
||||||
public class HeartObj extends Entity {
|
public class HeartObj extends Entity {
|
||||||
|
|
||||||
|
GamePanel panel;
|
||||||
|
|
||||||
public HeartObj(GamePanel panel) {
|
public HeartObj(GamePanel panel) {
|
||||||
super(panel);
|
super(panel);
|
||||||
name = "Heart Container";
|
this.panel = panel;
|
||||||
type = EntityType.ITEM;
|
|
||||||
|
name = "Heart";
|
||||||
|
type = EntityType.PICKUP;
|
||||||
|
value = 2;
|
||||||
|
|
||||||
|
down1 = initEntitySprites("objects/heart_full");
|
||||||
image = initEntitySprites("objects/heart_full");
|
image = initEntitySprites("objects/heart_full");
|
||||||
image2 = initEntitySprites("objects/heart_half");
|
image2 = initEntitySprites("objects/heart_half");
|
||||||
image3 = initEntitySprites("objects/heart_blank");
|
image3 = initEntitySprites("objects/heart_blank");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void use(Entity entity) {
|
||||||
|
panel.playSE(2);
|
||||||
|
panel.ui.addMessage("Life +"+value);
|
||||||
|
entity.life += value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import de.miaurizius.jgame2d.core.GamePanel;
|
|||||||
import de.miaurizius.jgame2d.core.enums.Direction;
|
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
import de.miaurizius.jgame2d.entity.Entity;
|
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 de.miaurizius.jgame2d.entity.projectile.RockObj;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -56,6 +59,12 @@ public class GreenSlimeMON extends Entity {
|
|||||||
actionLock = 0;
|
actionLock = 0;
|
||||||
direction = panel.player.direction;
|
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
|
// SETTING THINGS UP
|
||||||
public void getImage() {
|
public void getImage() {
|
||||||
|
|||||||
Reference in New Issue
Block a user