package entity;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import main.GamePanel;
import main.KeyHandler;
public final class Player extends Entity{
GamePanel gp;
KeyHandler KeyH;
public Player(GamePanel gp, KeyHandler KeyH) {
this.gp = gp;
this.KeyH = KeyH;
setDefaultValues();
getPlayerImage();
}
public void setDefaultValues() {
x = 100;
y = 100;
speed = 4;
direction = "down";
}
public void getPlayerImage() {
try {
up1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_up_1.png"));
up2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_up_2.png"));
down1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_down_1.png"));
down2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_down_2.png"));
left1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_left_1.png"));
left2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_left_2.png"));
right1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_right_1.png"));
right2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_right_2.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void update() {
if(KeyH.upPressed == true) {
direction = "up";
y -= speed;
}
if(KeyH.downPressed == true) {
direction = "down";
y += speed;
}
if(KeyH.leftPressed == true) {
direction = "left";
x -= speed;
}
if(KeyH.rightPressed == true) {
direction = "right";
x += speed;
}
if(KeyH.upPressed == true & KeyH.leftPressed == true) {
direction = "left";
y -= speed;
}
if(KeyH.upPressed == true && KeyH.rightPressed == true) {
direction = "right";
y -= speed;
}
if(KeyH.downPressed == true && KeyH.leftPressed == true) {
direction = "left";
y += speed;
}
if(KeyH.downPressed == true && KeyH.rightPressed == true) {
direction = "right";
y += speed;
}
}
public void draw(Graphics2D g2) {
BufferedImage image = null;
switch (direction) {
case "up":
image = up1;
break;
case "down":
image = down1;
break;
case "left":
image = left1;
break;
case "right":
image = right1;
break;
}
g2.drawImage(image, x, y, gp.tileSize, gp.tileSize, null);
}
}
Me ajudem porfavor!
A aplicação executa, pórem, aparece este erro
java.lang.IllegalArgumentException: input == null! at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1402) at entity.Player.getPlayerImage(Player.java:35) at entity.Player.<init>(Player.java:22) at main.GamePanel.<init>(GamePanel.java:25) at main.MyGame.main(MyGame.java:14)