fix errors after code review, added entity height and width properties for inner editor use

This commit is contained in:
2024-11-12 17:08:51 +07:00
parent 6062a8e0d5
commit 3943a9a490
2 changed files with 26 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}