added monster damage
This commit is contained in:
@@ -31,7 +31,8 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
public final int maxWorldRow = 50;
|
public final int maxWorldRow = 50;
|
||||||
|
|
||||||
//FPS
|
//FPS
|
||||||
int FPS = 60;
|
final int FPS = 60;
|
||||||
|
int fpsMeasure;
|
||||||
|
|
||||||
// SYSTEM
|
// SYSTEM
|
||||||
public TileManager tileM = new TileManager(this);
|
public TileManager tileM = new TileManager(this);
|
||||||
@@ -96,7 +97,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
drawCount++;
|
drawCount++;
|
||||||
}
|
}
|
||||||
if(timer >= 1000000000) {
|
if(timer >= 1000000000) {
|
||||||
System.out.println("FPS: " + drawCount);
|
fpsMeasure = drawCount;
|
||||||
drawCount = 0;
|
drawCount = 0;
|
||||||
timer = 0;
|
timer = 0;
|
||||||
}
|
}
|
||||||
@@ -150,8 +151,9 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
if(keyH.checkDrawTime) {
|
if(keyH.checkDrawTime) {
|
||||||
graphics2d.setColor(Color.white);
|
graphics2d.setColor(Color.white);
|
||||||
graphics2d.drawString("Draw Time: " + passed, 10, 400);
|
graphics2d.drawString("Draw Time: " + passed, 10, 400);
|
||||||
System.out.println("Draw Time: " + passed);
|
graphics2d.drawString("FPS: " + fpsMeasure, 10, 400+tileSize);
|
||||||
Logger.getLogger("DEBUG").log(Level.FINE, "Draw Time: " + passed);
|
graphics2d.drawString("Invincible: " + player.invincibleCount, 10, 400+tileSize*2);
|
||||||
|
Boot.logger.log(Level.FINE, "Draw Time: " + passed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// END
|
// END
|
||||||
|
|||||||
9
src/de/miaurizius/jgame2d/core/enums/EntityType.java
Normal file
9
src/de/miaurizius/jgame2d/core/enums/EntityType.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package de.miaurizius.jgame2d.core.enums;
|
||||||
|
|
||||||
|
public enum EntityType {
|
||||||
|
|
||||||
|
PLAYER,
|
||||||
|
NPC,
|
||||||
|
MONSTER,
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ 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.monster.GreenSlimeMON;
|
||||||
import de.miaurizius.jgame2d.entity.objects.DoorObj;
|
|
||||||
|
|
||||||
public class AssetSetter {
|
public class AssetSetter {
|
||||||
|
|
||||||
@@ -18,31 +17,31 @@ public class AssetSetter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setNPC() {
|
public void setNPC() {
|
||||||
// panel.npc[0] = new OldManNPC(panel);
|
|
||||||
// panel.npc[0].worldX = panel.tileSize*21;
|
|
||||||
// panel.npc[0].worldY = panel.tileSize*21;
|
|
||||||
|
|
||||||
panel.npc[0] = new OldManNPC(panel);
|
panel.npc[0] = new OldManNPC(panel);
|
||||||
panel.npc[0].worldX = panel.tileSize*9;
|
panel.npc[0].worldX = panel.tileSize*21;
|
||||||
panel.npc[0].worldY = panel.tileSize*10;
|
panel.npc[0].worldY = panel.tileSize*21;
|
||||||
|
|
||||||
|
// panel.npc[0] = new OldManNPC(panel);
|
||||||
|
// panel.npc[0].worldX = panel.tileSize*9;
|
||||||
|
// panel.npc[0].worldY = panel.tileSize*10;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMonster() {
|
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;
|
|
||||||
|
|
||||||
panel.monster[0] = new GreenSlimeMON(panel);
|
panel.monster[0] = new GreenSlimeMON(panel);
|
||||||
panel.monster[0].worldX = panel.tileSize*11;
|
panel.monster[0].worldX = panel.tileSize*23;
|
||||||
panel.monster[0].worldY = panel.tileSize*10;
|
panel.monster[0].worldY = panel.tileSize*36;
|
||||||
|
|
||||||
panel.monster[1] = new GreenSlimeMON(panel);
|
panel.monster[1] = new GreenSlimeMON(panel);
|
||||||
panel.monster[1].worldX = panel.tileSize*11;
|
panel.monster[1].worldX = panel.tileSize*23;
|
||||||
panel.monster[1].worldY = panel.tileSize*11;
|
panel.monster[1].worldY = panel.tileSize*37;
|
||||||
|
|
||||||
|
// panel.monster[0] = new GreenSlimeMON(panel);
|
||||||
|
// panel.monster[0].worldX = panel.tileSize*11;
|
||||||
|
// panel.monster[0].worldY = panel.tileSize*10;
|
||||||
|
//
|
||||||
|
// panel.monster[1] = new GreenSlimeMON(panel);
|
||||||
|
// panel.monster[1].worldX = panel.tileSize*11;
|
||||||
|
// panel.monster[1].worldY = panel.tileSize*11;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ public class CollisionHandler {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkPlayer(Entity entity) {
|
public boolean checkPlayer(Entity entity) {
|
||||||
|
boolean contactPlayer = false;
|
||||||
entity.solidArea.x += entity.worldX;
|
entity.solidArea.x += entity.worldX;
|
||||||
entity.solidArea.y += entity.worldY;
|
entity.solidArea.y += entity.worldY;
|
||||||
|
|
||||||
@@ -122,12 +123,16 @@ public class CollisionHandler {
|
|||||||
|
|
||||||
parseSolidArea(entity);
|
parseSolidArea(entity);
|
||||||
|
|
||||||
if (entity.solidArea.intersects(panel.player.solidArea)) entity.collisionOn = true;
|
if (entity.solidArea.intersects(panel.player.solidArea)) {
|
||||||
|
entity.collisionOn = true;
|
||||||
|
contactPlayer = true;
|
||||||
|
}
|
||||||
|
|
||||||
entity.solidArea.x = entity.solidAreaDefaultX;
|
entity.solidArea.x = entity.solidAreaDefaultX;
|
||||||
entity.solidArea.y = entity.solidAreaDefaultY;
|
entity.solidArea.y = entity.solidAreaDefaultY;
|
||||||
panel.player.solidArea.x = panel.player.solidAreaDefaultX;
|
panel.player.solidArea.x = panel.player.solidAreaDefaultX;
|
||||||
panel.player.solidArea.y = panel.player.solidAreaDefaultY;
|
panel.player.solidArea.y = panel.player.solidAreaDefaultY;
|
||||||
|
return contactPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseSolidArea(Entity entity) {
|
private void parseSolidArea(Entity entity) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.miaurizius.jgame2d.core.Boot;
|
|||||||
import de.miaurizius.jgame2d.core.enums.Direction;
|
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||||
import de.miaurizius.jgame2d.core.GamePanel;
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
import de.miaurizius.jgame2d.core.Utility;
|
import de.miaurizius.jgame2d.core.Utility;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -25,11 +26,14 @@ public class Entity {
|
|||||||
public int solidAreaDefaultX, solidAreaDefaultY;
|
public int solidAreaDefaultX, solidAreaDefaultY;
|
||||||
public boolean collisionOn = false;
|
public boolean collisionOn = false;
|
||||||
public int actionLock = 0;
|
public int actionLock = 0;
|
||||||
|
public boolean invincible = false;
|
||||||
|
public int invincibleCount = 0;
|
||||||
String[] dialogue = new String[20];
|
String[] dialogue = new String[20];
|
||||||
int dialogueIndex = 0;
|
int dialogueIndex = 0;
|
||||||
public BufferedImage image, image2, image3;
|
public BufferedImage image, image2, image3;
|
||||||
public String name;
|
public String name;
|
||||||
public boolean collision = false;
|
public boolean collision = false;
|
||||||
|
public EntityType type;
|
||||||
|
|
||||||
// CHARACTER STATUS
|
// CHARACTER STATUS
|
||||||
public int maxLife;
|
public int maxLife;
|
||||||
@@ -61,7 +65,13 @@ 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.checkPlayer(this);
|
boolean contactPlayer = panel.collisionH.checkPlayer(this);
|
||||||
|
|
||||||
|
if(this.type == EntityType.MONSTER && contactPlayer) {
|
||||||
|
if(panel.player.invincible) return;
|
||||||
|
panel.player.life -= 1;
|
||||||
|
panel.player.invincible = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(!collisionOn) {
|
if(!collisionOn) {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
@@ -81,7 +91,7 @@ public class Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics graphics2d) {
|
public void draw(Graphics2D graphics2d) {
|
||||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||||
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public class OldManNPC extends Entity {
|
|||||||
dialogue[1] = "So you've come to this island to \nfind the treasure?";
|
dialogue[1] = "So you've come to this island to \nfind the treasure?";
|
||||||
dialogue[2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure.";
|
dialogue[2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure.";
|
||||||
dialogue[3] = "Well, good luck on you.";
|
dialogue[3] = "Well, good luck on you.";
|
||||||
|
dialogue[4] = "I heard drinking the water of the \nholy lake makes you feel fine again...";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAction() {
|
public void setAction() {
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ public class Player extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultValues() {
|
public void setDefaultValues() {
|
||||||
// worldX = panel.tileSize * 23;
|
worldX = panel.tileSize * 23;
|
||||||
// worldY = panel.tileSize * 21;
|
worldY = panel.tileSize * 21;
|
||||||
worldX = panel.tileSize * 10;
|
// worldX = panel.tileSize * 10;
|
||||||
worldY = panel.tileSize * 13;
|
// worldY = panel.tileSize * 13;
|
||||||
speed = 4;
|
speed = 4;
|
||||||
direction = Direction.DOWN;
|
direction = Direction.DOWN;
|
||||||
|
|
||||||
@@ -79,6 +79,7 @@ public class Player extends Entity {
|
|||||||
|
|
||||||
// CHECK MONSTER COLLISION
|
// CHECK MONSTER COLLISION
|
||||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster);
|
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster);
|
||||||
|
interactMonster(monsterIndex);
|
||||||
|
|
||||||
// CHECK EVENT
|
// CHECK EVENT
|
||||||
panel.eventH.checkEvent();
|
panel.eventH.checkEvent();
|
||||||
@@ -102,6 +103,25 @@ public class Player extends Entity {
|
|||||||
spriteCounter = 0;
|
spriteCounter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!invincible) return;
|
||||||
|
invincibleCount++;
|
||||||
|
if(invincibleCount > 60) {
|
||||||
|
invincible = false;
|
||||||
|
invincibleCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Graphics2D graphics2d) {
|
||||||
|
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||||
|
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
||||||
|
|
||||||
|
if(invincible) {
|
||||||
|
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
|
||||||
|
}
|
||||||
|
|
||||||
|
graphics2d.drawImage(parseSprite(), screenX, screenY, null);
|
||||||
|
|
||||||
|
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pickObject(int index) {
|
public void pickObject(int index) {
|
||||||
@@ -115,8 +135,11 @@ public class Player extends Entity {
|
|||||||
panel.npc[index].speak();
|
panel.npc[index].speak();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics2D graphics2d) {
|
public void interactMonster(int index) {
|
||||||
graphics2d.drawImage(parseSprite(), screenX, screenY, null);
|
if(index == 999) return;
|
||||||
|
if(invincible) return;
|
||||||
|
life -= 1;
|
||||||
|
invincible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void speak() {
|
public void speak() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.miaurizius.jgame2d.entity.monster;
|
|||||||
|
|
||||||
import de.miaurizius.jgame2d.core.GamePanel;
|
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.entity.Entity;
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -10,6 +11,7 @@ public class GreenSlimeMON extends Entity {
|
|||||||
|
|
||||||
public GreenSlimeMON(GamePanel panel) {
|
public GreenSlimeMON(GamePanel panel) {
|
||||||
super(panel);
|
super(panel);
|
||||||
|
type = EntityType.MONSTER;
|
||||||
name = "green-slime";
|
name = "green-slime";
|
||||||
speed = 1;
|
speed = 1;
|
||||||
maxLife = 4;
|
maxLife = 4;
|
||||||
|
|||||||
Reference in New Issue
Block a user