fix errors after code review, added entity height and width properties for inner editor use
This commit is contained in:
@ -8,10 +8,13 @@ public class Entity {
|
||||
private Hitbox thisHitbox;
|
||||
private String type;
|
||||
private BufferedImage sprite;
|
||||
private int width = 0;
|
||||
private int height = 0;
|
||||
|
||||
public Entity(String name,String drawbox,String hitbox) {
|
||||
public Entity(String name, String drawbox, String hitbox, BufferedImage sprite) {
|
||||
thisName = new String(name);
|
||||
thisDrawbox = new Drawbox(drawbox);
|
||||
setImage(sprite); // updates entity width and height, should be called before creating hitbox
|
||||
thisHitbox = new Hitbox(hitbox);
|
||||
}
|
||||
|
||||
@ -58,8 +61,13 @@ public class Entity {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
/** NOTE: Image setter updates entity width and height */
|
||||
public void setImage(BufferedImage sprite) {
|
||||
this.sprite = sprite;
|
||||
if(sprite != null) {
|
||||
width = sprite.getHeight();
|
||||
height = sprite.getHeight();
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintEntity() {
|
||||
@ -69,4 +77,20 @@ public class Entity {
|
||||
this.thisHitbox.printToConsole();
|
||||
System.out.println("---------------------");
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,9 +174,8 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener {
|
||||
}
|
||||
}
|
||||
|
||||
Entity e = new Entity(entityName, newDrawbox, newHitbox);
|
||||
Entity e = new Entity(entityName, newDrawbox, newHitbox, sprite);
|
||||
e.setType(type);
|
||||
e.setImage(sprite);
|
||||
listEntity.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user