simplified duplicated code
BIN
assets/npc/bigrock.png
Normal file
|
After Width: | Height: | Size: 896 B |
BIN
assets/npc/merchant_down_1.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/npc/merchant_down_2.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/npc/oldman_down_1.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/npc/oldman_down_2.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/npc/oldman_left_1.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/npc/oldman_left_2.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/npc/oldman_right_1.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/npc/oldman_right_2.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/npc/oldman_up_1.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/npc/oldman_up_2.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
@@ -1,23 +1,41 @@
|
|||||||
package de.miaurizius.jgame2d.entity;
|
package de.miaurizius.jgame2d.entity;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.Boot;
|
||||||
import de.miaurizius.jgame2d.core.Direction;
|
import de.miaurizius.jgame2d.core.Direction;
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.Utility;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Entity {
|
public class Entity {
|
||||||
|
|
||||||
|
GamePanel panel;
|
||||||
public int worldX, worldY;
|
public int worldX, worldY;
|
||||||
public int speed;
|
public int speed;
|
||||||
|
|
||||||
public BufferedImage up1, up2, down1, down2, left1, left2, right1, right2;
|
public BufferedImage up1, up2, down1, down2, left1, left2, right1, right2;
|
||||||
public Direction direction;
|
public Direction direction;
|
||||||
|
|
||||||
public int spriteCounter = 0;
|
public int spriteCounter = 0;
|
||||||
public int spriteNum = 1;
|
public int spriteNum = 1;
|
||||||
|
public Rectangle solidArea = new Rectangle(0, 0, 48, 48);
|
||||||
public Rectangle solidArea;
|
|
||||||
public int solidAreaDefaultX, solidAreaDefaultY;
|
public int solidAreaDefaultX, solidAreaDefaultY;
|
||||||
public boolean collisionOn = false;
|
public boolean collisionOn = false;
|
||||||
|
|
||||||
|
public Entity(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage initEntitySprites(String name) {
|
||||||
|
try {
|
||||||
|
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), panel.tileSize, panel.tileSize);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Boot.logger.log(Level.SEVERE, "Could not load entity-image", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/de/miaurizius/jgame2d/entity/OldManNPC.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package de.miaurizius.jgame2d.entity;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.Direction;
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
|
||||||
|
public class OldManNPC extends Entity {
|
||||||
|
|
||||||
|
public OldManNPC(GamePanel panel) {
|
||||||
|
super(panel);
|
||||||
|
|
||||||
|
direction = Direction.DOWN;
|
||||||
|
speed = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getPlayerImage() {
|
||||||
|
up1 = initEntitySprites("boy_up_1");
|
||||||
|
up2 = initEntitySprites("boy_up_2");
|
||||||
|
down1 = initEntitySprites("boy_down_1");
|
||||||
|
down2 = initEntitySprites("boy_down_2");
|
||||||
|
left1 = initEntitySprites("boy_left_1");
|
||||||
|
left2 = initEntitySprites("boy_left_2");
|
||||||
|
right1 = initEntitySprites("boy_right_1");
|
||||||
|
right2 = initEntitySprites("boy_right_2");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,22 +2,19 @@ package de.miaurizius.jgame2d.entity;
|
|||||||
|
|
||||||
import de.miaurizius.jgame2d.core.*;
|
import de.miaurizius.jgame2d.core.*;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class Player extends Entity {
|
public class Player extends Entity {
|
||||||
|
|
||||||
GamePanel panel;
|
|
||||||
KeyHandler keyH;
|
KeyHandler keyH;
|
||||||
|
|
||||||
public final int screenX;
|
public final int screenX;
|
||||||
public final int screenY;
|
public final int screenY;
|
||||||
|
|
||||||
public Player(GamePanel panel, KeyHandler keyH) {
|
public Player(GamePanel panel, KeyHandler keyH) {
|
||||||
this.panel = panel;
|
super(panel);
|
||||||
this.keyH = keyH;
|
this.keyH = keyH;
|
||||||
|
|
||||||
screenX = panel.screenWidth/2 - panel.tileSize/2;
|
screenX = panel.screenWidth/2 - panel.tileSize/2;
|
||||||
@@ -43,23 +40,14 @@ public class Player extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void getPlayerImage() {
|
public void getPlayerImage() {
|
||||||
up1 = initPlayerImage("boy_up_1");
|
up1 = initEntitySprites("player/boy_up_1");
|
||||||
up2 = initPlayerImage("boy_up_2");
|
up2 = initEntitySprites("player/boy_up_2");
|
||||||
down1 = initPlayerImage("boy_down_1");
|
down1 = initEntitySprites("player/boy_down_1");
|
||||||
down2 = initPlayerImage("boy_down_2");
|
down2 = initEntitySprites("player/boy_down_2");
|
||||||
left1 = initPlayerImage("boy_left_1");
|
left1 = initEntitySprites("player/boy_left_1");
|
||||||
left2 = initPlayerImage(("boy_left_2"));
|
left2 = initEntitySprites("player/boy_left_2");
|
||||||
right1 = initPlayerImage(("boy_right_1"));
|
right1 = initEntitySprites("player/boy_right_1");
|
||||||
right2 = initPlayerImage(("boy_right_2"));
|
right2 = initEntitySprites("player/boy_right_2");
|
||||||
}
|
|
||||||
|
|
||||||
public BufferedImage initPlayerImage(String name) {
|
|
||||||
try {
|
|
||||||
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/player/" + name + ".png")), panel.tileSize, panel.tileSize);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Boot.logger.log(Level.SEVERE, "Could not load player-image", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|||||||