simplified duplicated code
This commit is contained in:
@@ -2,22 +2,19 @@ package de.miaurizius.jgame2d.entity;
|
||||
|
||||
import de.miaurizius.jgame2d.core.*;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Player extends Entity {
|
||||
|
||||
GamePanel panel;
|
||||
KeyHandler keyH;
|
||||
|
||||
public final int screenX;
|
||||
public final int screenY;
|
||||
|
||||
public Player(GamePanel panel, KeyHandler keyH) {
|
||||
this.panel = panel;
|
||||
super(panel);
|
||||
this.keyH = keyH;
|
||||
|
||||
screenX = panel.screenWidth/2 - panel.tileSize/2;
|
||||
@@ -43,23 +40,14 @@ public class Player extends Entity {
|
||||
}
|
||||
|
||||
public void getPlayerImage() {
|
||||
up1 = initPlayerImage("boy_up_1");
|
||||
up2 = initPlayerImage("boy_up_2");
|
||||
down1 = initPlayerImage("boy_down_1");
|
||||
down2 = initPlayerImage("boy_down_2");
|
||||
left1 = initPlayerImage("boy_left_1");
|
||||
left2 = initPlayerImage(("boy_left_2"));
|
||||
right1 = initPlayerImage(("boy_right_1"));
|
||||
right2 = initPlayerImage(("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;
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user