Compare commits

...

10 Commits

100 changed files with 331 additions and 256 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

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: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

View File

@@ -4,13 +4,13 @@ import de.miaurizius.jgame2d.core.enums.GameState;
import de.miaurizius.jgame2d.core.handlers.*;
import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.entity.Player;
import de.miaurizius.jgame2d.object.SuperObject;
import de.miaurizius.jgame2d.tile.TileManager;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;
public class GamePanel extends JPanel implements Runnable {
@@ -30,7 +30,8 @@ public class GamePanel extends JPanel implements Runnable {
public final int maxWorldRow = 50;
//FPS
int FPS = 60;
final int FPS = 60;
int fpsMeasure;
// SYSTEM
public TileManager tileM = new TileManager(this);
@@ -45,8 +46,10 @@ public class GamePanel extends JPanel implements Runnable {
// ENTITY AND OBJECT
public Player player = new Player(this, keyH);
public SuperObject[] obj = new SuperObject[10];
public Entity[] obj = new Entity[10];
public Entity[] npc = new Entity[10];
public Entity[] monster = new Entity[20];
ArrayList<Entity> entityList = new ArrayList<>();
// GAME STATE
public GameState gameState;
@@ -62,7 +65,7 @@ public class GamePanel extends JPanel implements Runnable {
public void setupGame() {
assetSetter.setObject();
assetSetter.setNPC();
//playMusic(0); //Play main theme
assetSetter.setMonster();
gameState = GameState.TITLE;
}
@@ -93,7 +96,7 @@ public class GamePanel extends JPanel implements Runnable {
drawCount++;
}
if(timer >= 1000000000) {
System.out.println("FPS: " + drawCount);
fpsMeasure = drawCount;
drawCount = 0;
timer = 0;
}
@@ -105,6 +108,7 @@ public class GamePanel extends JPanel implements Runnable {
case PLAY:
player.update();
for(Entity entity : npc) if(entity != null) entity.update();
for(Entity entity : monster) if(entity != null) entity.update();
break;
case PAUSE:
break;
@@ -127,9 +131,16 @@ public class GamePanel extends JPanel implements Runnable {
// GAME
tileM.draw(graphics2d);
for (SuperObject superObject : obj) if (superObject != null) superObject.draw(graphics2d, this);
for(Entity npc : npc) if(npc != null) npc.draw(graphics2d);
player.draw(graphics2d);
// ENTITY RENDER SYSTEM
entityList.add(player);
for(Entity entity : npc) 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));
for(Entity entity : entityList) entity.draw(graphics2d);
entityList.clear();
ui.draw(graphics2d);
long drawEnd = System.nanoTime();
@@ -139,8 +150,9 @@ public class GamePanel extends JPanel implements Runnable {
if(keyH.checkDrawTime) {
graphics2d.setColor(Color.white);
graphics2d.drawString("Draw Time: " + passed, 10, 400);
System.out.println("Draw Time: " + passed);
Logger.getLogger("DEBUG").log(Level.FINE, "Draw Time: " + passed);
graphics2d.drawString("FPS: " + fpsMeasure, 10, 400+tileSize);
graphics2d.drawString("Invincible: " + player.invincibleCount, 10, 400+tileSize*2);
Boot.logger.log(Level.FINE, "Draw Time: " + passed);
}
// END

View File

@@ -1,8 +1,8 @@
package de.miaurizius.jgame2d.core;
import de.miaurizius.jgame2d.core.enums.GameState;
import de.miaurizius.jgame2d.object.HeartObj;
import de.miaurizius.jgame2d.object.SuperObject;
import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.entity.objects.HeartObj;
import java.awt.*;
import java.awt.image.BufferedImage;
@@ -22,7 +22,7 @@ public class UI {
arial_80B = new Font("Arial", Font.BOLD, 80);
// CREATE HUD OBJECT
SuperObject heart = new HeartObj(panel);
Entity heart = new HeartObj(panel);
heart_full = heart.image;
heart_half = heart.image2;
heart_blank = heart.image3;

View File

@@ -0,0 +1,9 @@
package de.miaurizius.jgame2d.core.enums;
public enum EntityType {
PLAYER,
NPC,
MONSTER,
}

View File

@@ -2,6 +2,7 @@ package de.miaurizius.jgame2d.core.handlers;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.OldManNPC;
import de.miaurizius.jgame2d.entity.monster.GreenSlimeMON;
public class AssetSetter {
@@ -11,12 +12,36 @@ public class AssetSetter {
this.panel = panel;
}
public void setObject() {}
public void setObject() {
}
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].worldX = panel.tileSize*9;
// panel.npc[0].worldY = panel.tileSize*10;
}
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].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;
}
}

View File

@@ -2,7 +2,6 @@ package de.miaurizius.jgame2d.core.handlers;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.object.SuperObject;
public class CollisionHandler {
@@ -57,7 +56,7 @@ public class CollisionHandler {
int index = 999;
int c = -1;
for(SuperObject obj : panel.obj) {
for(Entity obj : panel.obj) {
c++;
if (obj != null) {
@@ -67,36 +66,13 @@ public class CollisionHandler {
obj.solidArea.x += obj.worldX;
obj.solidArea.y += obj.worldY;
switch (entity.direction) {
case UP:
entity.solidArea.y -= entity.speed;
parseSolidArea(entity);
if (entity.solidArea.intersects(obj.solidArea)) {
if (obj.collision) entity.collisionOn = true;
if (player) index = c;
}
break;
case DOWN:
entity.solidArea.y += entity.speed;
if (entity.solidArea.intersects(obj.solidArea)) {
if (obj.collision) entity.collisionOn = true;
if (player) index = c;
}
break;
case LEFT:
entity.solidArea.x -= entity.speed;
if (entity.solidArea.intersects(obj.solidArea)) {
if (obj.collision) entity.collisionOn = true;
if (player) index = c;
}
break;
case RIGHT:
entity.solidArea.x += entity.speed;
if (entity.solidArea.intersects(obj.solidArea)) {
if (obj.collision) entity.collisionOn = true;
if (player) index = c;
}
break;
}
entity.solidArea.x = entity.solidAreaDefaultX;
entity.solidArea.y = entity.solidAreaDefaultY;
obj.solidArea.x = obj.solidAreaDefaultX;
@@ -121,36 +97,13 @@ public class CollisionHandler {
e.solidArea.x += e.worldX;
e.solidArea.y += e.worldY;
switch (entity.direction) {
case UP:
entity.solidArea.y -= entity.speed;
if (entity.solidArea.intersects(e.solidArea)) {
parseSolidArea(entity);
if (entity.solidArea.intersects(e.solidArea) && e != entity) {
entity.collisionOn = true;
index = c;
}
break;
case DOWN:
entity.solidArea.y += entity.speed;
if (entity.solidArea.intersects(e.solidArea)) {
entity.collisionOn = true;
index = c;
}
break;
case LEFT:
entity.solidArea.x -= entity.speed;
if (entity.solidArea.intersects(e.solidArea)) {
entity.collisionOn = true;
index = c;
}
break;
case RIGHT:
entity.solidArea.x += entity.speed;
if (entity.solidArea.intersects(e.solidArea)) {
entity.collisionOn = true;
index = c;
}
break;
}
entity.solidArea.x = entity.solidAreaDefaultX;
entity.solidArea.y = entity.solidAreaDefaultY;
e.solidArea.x = e.solidAreaDefaultX;
@@ -160,35 +113,35 @@ public class CollisionHandler {
return index;
}
public void checkPlayer(Entity entity) {
public boolean checkPlayer(Entity entity) {
boolean contactPlayer = false;
entity.solidArea.x += entity.worldX;
entity.solidArea.y += entity.worldY;
panel.player.solidArea.x += panel.player.worldX;
panel.player.solidArea.y += panel.player.worldY;
switch (entity.direction) {
case UP:
entity.solidArea.y -= entity.speed;
if (entity.solidArea.intersects(panel.player.solidArea)) entity.collisionOn = true;
break;
case DOWN:
entity.solidArea.y += entity.speed;
if (entity.solidArea.intersects(panel.player.solidArea)) entity.collisionOn = true;
break;
case LEFT:
entity.solidArea.x -= entity.speed;
if (entity.solidArea.intersects(panel.player.solidArea)) entity.collisionOn = true;
break;
case RIGHT:
entity.solidArea.x += entity.speed;
if (entity.solidArea.intersects(panel.player.solidArea)) entity.collisionOn = true;
break;
parseSolidArea(entity);
if (entity.solidArea.intersects(panel.player.solidArea)) {
entity.collisionOn = true;
contactPlayer = true;
}
entity.solidArea.x = entity.solidAreaDefaultX;
entity.solidArea.y = entity.solidAreaDefaultY;
panel.player.solidArea.x = panel.player.solidAreaDefaultX;
panel.player.solidArea.y = panel.player.solidAreaDefaultY;
return contactPlayer;
}
private void parseSolidArea(Entity entity) {
switch (entity.direction) {
case UP -> entity.solidArea.y -= entity.speed;
case DOWN -> entity.solidArea.y += entity.speed;
case LEFT -> entity.solidArea.x -= entity.speed;
case RIGHT -> entity.solidArea.x += entity.speed;
}
}
}

View File

@@ -47,6 +47,9 @@ public class EventHandler {
if(hit(23,12, null)) healingPool(GameState.DIALOGUE);
}
/**
* @param reqDirection Set to null if no direction is required
*/
public boolean hit(int eventCol, int eventRow, Direction reqDirection) {
boolean hit = false;
panel.player.solidArea.x = panel.player.worldX + panel.player.solidArea.x;

View File

@@ -69,6 +69,9 @@ public class KeyHandler implements KeyListener {
}
}
break;
case PAUSE:
if(code == KeyEvent.VK_ESCAPE) panel.gameState = GameState.PLAY;
break;
}
}

View File

@@ -4,6 +4,7 @@ import de.miaurizius.jgame2d.core.Boot;
import de.miaurizius.jgame2d.core.enums.Direction;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.Utility;
import de.miaurizius.jgame2d.core.enums.EntityType;
import javax.imageio.ImageIO;
import java.awt.*;
@@ -15,20 +16,32 @@ import java.util.logging.Level;
public class Entity {
GamePanel panel;
public int worldX, worldY;
public int speed;
public BufferedImage up1, up2, down1, down2, left1, left2, right1, right2;
public Direction direction;
public int spriteCounter = 0;
public int spriteNum = 1;
public BufferedImage attackUp1, attackUp2, attackDown1, attackDown2, attackLeft1, attackLeft2, attackRight1, attackRight2;
public BufferedImage image, image2, image3;
public Rectangle solidArea = new Rectangle(0, 0, 48, 48);
public int solidAreaDefaultX, solidAreaDefaultY;
public boolean collisionOn = false;
public int actionLock = 0;
public boolean collision = false;
String[] dialogue = new String[20];
int dialogueIndex = 0;
// CHARACTER STATUS
// STATE
public int worldX, worldY;
public Direction direction = Direction.DOWN;
public int spriteNum = 1;
int dialogueIndex = 0;
public boolean collisionOn = false;
public boolean invincible = false;
boolean attacking = false; //TODO: https://youtu.be/HL39xRzPpm4?t=551
// COUNTER
public int spriteCounter = 0;
public int actionLock = 0;
public int invincibleCount = 0;
// ATTRIBUTES
public EntityType type;
public String name;
public int speed;
public int maxLife;
public int life;
@@ -56,7 +69,15 @@ public class Entity {
collisionOn = false;
panel.collisionH.checkTile(this);
panel.collisionH.checkObject(this, false);
panel.collisionH.checkPlayer(this);
panel.collisionH.checkEntity(this, panel.npc);
panel.collisionH.checkEntity(this, panel.monster);
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) {
switch (direction) {
@@ -76,7 +97,7 @@ public class Entity {
}
}
public void draw(Graphics graphics2d) {
public void draw(Graphics2D graphics2d) {
int screenX = worldX - panel.player.worldX + panel.player.screenX;
int screenY = worldY - panel.player.worldY + panel.player.screenY;
@@ -98,7 +119,7 @@ public class Entity {
};
}
BufferedImage initEntitySprites(String name) {
public BufferedImage initEntitySprites(String name) {
try {
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), panel.tileSize, panel.tileSize);
} catch (IOException e) {
@@ -107,4 +128,13 @@ public class Entity {
return null;
}
public BufferedImage initEntitySprites(String name, int width, int height) {
try {
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), width, height);
} catch (IOException e) {
Boot.logger.log(Level.SEVERE, "Could not load entity-image", e);
}
return null;
}
}

View File

@@ -32,6 +32,7 @@ public class OldManNPC extends Entity {
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[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() {

View File

@@ -31,6 +31,7 @@ public class Player extends Entity {
setDefaultValues();
getPlayerImage();
getPlayerAttackImage();
}
public void setDefaultValues() {
@@ -44,20 +45,9 @@ public class Player extends Entity {
life = maxLife;
}
public void getPlayerImage() {
up1 = initEntitySprites("player/boy_up_1");
up2 = initEntitySprites("player/boy_up_2");
down1 = initEntitySprites("player/boy_down_1");
down2 = initEntitySprites("player/boy_down_2");
left1 = initEntitySprites("player/boy_left_1");
left2 = initEntitySprites("player/boy_left_2");
right1 = initEntitySprites("player/boy_right_1");
right2 = initEntitySprites("player/boy_right_2");
}
public void update() {
// MOVEMENT
if(keyH.upPressed || keyH.downPressed || keyH.leftPressed || keyH.rightPressed) {
if(keyH.upPressed || keyH.downPressed || keyH.leftPressed || keyH.rightPressed || keyH.spacePressed) {
if(keyH.upPressed) direction = Direction.UP;
else if(keyH.downPressed) direction = Direction.DOWN;
else if(keyH.leftPressed) direction = Direction.LEFT;
@@ -75,12 +65,14 @@ public class Player extends Entity {
int npcIndex = panel.collisionH.checkEntity(this, panel.npc);
interactNPC(npcIndex);
// CHECK MONSTER COLLISION
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster);
interactMonster(monsterIndex);
// CHECK EVENT
panel.eventH.checkEvent();
panel.keyH.spacePressed = false;
if(!collisionOn) {
if(!collisionOn && !keyH.spacePressed) {
switch (direction) {
case UP -> worldY -= speed;
case DOWN -> worldY += speed;
@@ -89,6 +81,8 @@ public class Player extends Entity {
}
}
panel.keyH.spacePressed = false;
spriteCounter++;
if(spriteCounter > 12) {
if(spriteNum == 1) spriteNum = 2;
@@ -97,6 +91,25 @@ public class Player extends Entity {
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) {
@@ -110,8 +123,11 @@ public class Player extends Entity {
panel.npc[index].speak();
}
public void draw(Graphics2D graphics2d) {
graphics2d.drawImage(parseSprite(), screenX, screenY, null);
public void interactMonster(int index) {
if(index == 999) return;
if(invincible) return;
life -= 1;
invincible = true;
}
public void speak() {
@@ -119,4 +135,26 @@ public class Player extends Entity {
super.speak();
}
public void getPlayerImage() {
up1 = initEntitySprites("player/boy_up_1");
up2 = initEntitySprites("player/boy_up_2");
down1 = initEntitySprites("player/boy_down_1");
down2 = initEntitySprites("player/boy_down_2");
left1 = initEntitySprites("player/boy_left_1");
left2 = initEntitySprites("player/boy_left_2");
right1 = initEntitySprites("player/boy_right_1");
right2 = initEntitySprites("player/boy_right_2");
}
public void getPlayerAttackImage() {
attackUp1 = initEntitySprites("player/attack/boy_attack_up_1", panel.tileSize, panel.tileSize*2);
attackUp2 = initEntitySprites("player/attack/boy_attack_up_2", panel.tileSize, panel.tileSize*2);
attackDown1 = initEntitySprites("player/attack/boy_attack_down_1", panel.tileSize, panel.tileSize*2);
attackDown2 = initEntitySprites("player/attack/boy_attack_down_2", panel.tileSize, panel.tileSize*2);
attackLeft1 = initEntitySprites("player/attack/boy_attack_left_1", panel.tileSize*2, panel.tileSize);
attackLeft2 = initEntitySprites("player/attack/boy_attack_left_2", panel.tileSize*2, panel.tileSize);
attackRight1 = initEntitySprites("player/attack/boy_attack_right_1", panel.tileSize*2, panel.tileSize);
attackRight2 = initEntitySprites("player/attack/boy_attack_right_2", panel.tileSize*2, panel.tileSize);
}
}

View File

@@ -0,0 +1,53 @@
package de.miaurizius.jgame2d.entity.monster;
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 java.util.Random;
public class GreenSlimeMON extends Entity {
public GreenSlimeMON(GamePanel panel) {
super(panel);
type = EntityType.MONSTER;
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

@@ -0,0 +1,14 @@
package de.miaurizius.jgame2d.entity.objects;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.Entity;
public class BootsObj extends Entity {
public BootsObj(GamePanel panel) {
super(panel);
name = "boots";
down1 = initEntitySprites("objects/boots.png");
}
}

View File

@@ -0,0 +1,14 @@
package de.miaurizius.jgame2d.entity.objects;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.Entity;
public class ChestObj extends Entity {
public ChestObj(GamePanel panel) {
super(panel);
name = "chest";
down1 = initEntitySprites("objects/chest");
}
}

View File

@@ -0,0 +1,22 @@
package de.miaurizius.jgame2d.entity.objects;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.Entity;
public class DoorObj extends Entity {
public DoorObj(GamePanel panel) {
super(panel);
name = "door";
down1 = initEntitySprites("objects/door");
collision = true;
solidArea.x = 0;
solidArea.y = 16;
solidArea.width = 48;
solidArea.height = 32;
solidAreaDefaultX = solidArea.x;
solidAreaDefaultY = solidArea.y;
}
}

View File

@@ -0,0 +1,16 @@
package de.miaurizius.jgame2d.entity.objects;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.Entity;
public class HeartObj extends Entity {
public HeartObj(GamePanel panel) {
super(panel);
name = "heart";
image = initEntitySprites("objects/heart_full");
image2 = initEntitySprites("objects/heart_half");
image3 = initEntitySprites("objects/heart_blank");
}
}

View File

@@ -0,0 +1,14 @@
package de.miaurizius.jgame2d.entity.objects;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.Entity;
public class KeyObj extends Entity {
public KeyObj(GamePanel panel) {
super(panel);
name = "key";
down1 = initEntitySprites("objects/key");
}
}

View File

@@ -1,10 +1,11 @@
package de.miaurizius.jgame2d.object;
package de.miaurizius.jgame2d.entity.objects;
import de.miaurizius.jgame2d.core.GamePanel;
import java.awt.*;
import java.awt.image.BufferedImage;
@Deprecated
public class SuperObject {
public BufferedImage image, image2, image3;

View File

@@ -1,26 +0,0 @@
package de.miaurizius.jgame2d.object;
import de.miaurizius.jgame2d.core.Boot;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.Utility;
import javax.imageio.ImageIO;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
public class BootsObj extends SuperObject {
GamePanel panel;
public BootsObj(GamePanel panel) {
this.panel = panel;
name = "boots";
try {
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/boots.png")), panel.tileSize, panel.tileSize);
} catch(IOException e) {
Boot.logger.log(Level.SEVERE, "Could not load image", e);
}
}
}

View File

@@ -1,26 +0,0 @@
package de.miaurizius.jgame2d.object;
import de.miaurizius.jgame2d.core.Boot;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.Utility;
import javax.imageio.ImageIO;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
public class ChestObj extends SuperObject {
GamePanel panel;
public ChestObj(GamePanel panel) {
this.panel = panel;
name = "chest";
try {
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/chest.png")), panel.tileSize, panel.tileSize);
} catch(IOException e) {
Boot.logger.log(Level.SEVERE, "Could not load image", e);
}
}
}

View File

@@ -1,27 +0,0 @@
package de.miaurizius.jgame2d.object;
import de.miaurizius.jgame2d.core.Boot;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.Utility;
import javax.imageio.ImageIO;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
public class DoorObj extends SuperObject {
GamePanel panel;
public DoorObj(GamePanel panel) {
this.panel = panel;
name = "door";
try {
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/door.png")), panel.tileSize, panel.tileSize);
} catch(IOException e) {
Boot.logger.log(Level.SEVERE, "Could not load image", e);
}
collision = true;
}
}

View File

@@ -1,28 +0,0 @@
package de.miaurizius.jgame2d.object;
import de.miaurizius.jgame2d.core.Boot;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.Utility;
import javax.imageio.ImageIO;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
public class HeartObj extends SuperObject {
GamePanel panel;
public HeartObj(GamePanel panel) {
this.panel = panel;
name = "heart";
try {
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/heart_full.png")), panel.tileSize, panel.tileSize);
image2 = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/heart_half.png")), panel.tileSize, panel.tileSize);
image3 = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/heart_blank.png")), panel.tileSize, panel.tileSize);
} catch(IOException e) {
Boot.logger.log(Level.SEVERE, "Could not load image", e);
}
}
}

View File

@@ -1,26 +0,0 @@
package de.miaurizius.jgame2d.object;
import de.miaurizius.jgame2d.core.Boot;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.Utility;
import javax.imageio.ImageIO;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
public class KeyObj extends SuperObject {
GamePanel panel;
public KeyObj(GamePanel panel) {
this.panel = panel;
name = "key";
try {
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/key.png")), panel.tileSize, panel.tileSize);
} catch(IOException e) {
Boot.logger.log(Level.SEVERE, "Could not load image", e);
}
}
}