add hero walk graphics, objects atlas packing and refactor components to be records

This commit is contained in:
Quillraven
2025-05-24 16:35:40 +02:00
parent 77f494b8a1
commit 85ba3d894d
47 changed files with 331 additions and 22 deletions

View File

@@ -9,9 +9,9 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
* Component that stores the visual representation of an entity.
* Contains a texture region and a color for tinting.
*/
public class Graphic implements Component {
public record Graphic(
TextureRegion region,
Color color
) implements Component {
public static final ComponentMapper<Graphic> MAPPER = ComponentMapper.getFor(Graphic.class);
public TextureRegion region;
public final Color color = new Color(Color.WHITE);
}

View File

@@ -8,13 +8,13 @@ import com.badlogic.gdx.math.Vector2;
* Component that stores the position, z-index, and size of an entity.
* Implements Comparable to allow sorting entities by z-index and position.
*/
public class Transform implements Component, Comparable<Transform> {
public record Transform(
Vector2 position,
int z,
Vector2 size
) implements Component, Comparable<Transform> {
public static final ComponentMapper<Transform> MAPPER = ComponentMapper.getFor(Transform.class);
public final Vector2 position = new Vector2();
public int z = 0;
public final Vector2 size = new Vector2(1f, 1f);
@Override
public int compareTo(Transform other) {
if (this.z != other.z) {

View File

@@ -74,16 +74,16 @@ public class RenderSystem extends SortedIteratingSystem implements Disposable {
protected void processEntity(Entity entity, float deltaTime) {
Transform transform = Transform.MAPPER.get(entity);
Graphic graphic = Graphic.MAPPER.get(entity);
if (graphic.region == null) {
if (graphic.region() == null) {
return;
}
batch.setColor(graphic.color);
batch.setColor(graphic.color());
batch.draw(
graphic.region,
transform.position.x, transform.position.y,
transform.size.x / 2, transform.size.y / 2,
transform.size.x, transform.size.y,
graphic.region(),
transform.position().x, transform.position().y,
transform.size().x / 2, transform.size().y / 2,
transform.size().x, transform.size().y,
1, 1,
0
);