From 80e7342650a9d71b73a838230733c54c50ffcc1b Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 22 Jan 2025 21:17:25 +0500 Subject: upd: Vector2 instead of Vector3 for directions (because we don't actually need the y coordinate) --- .../kz/ilotterytea/frogartha/domain/PlayerState.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java') diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java b/shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java index d745822..0aa89c5 100644 --- a/shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java +++ b/shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java @@ -1,5 +1,6 @@ package kz.ilotterytea.frogartha.domain; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.github.czyzby.websocket.serialization.SerializationException; import com.github.czyzby.websocket.serialization.Transferable; @@ -7,14 +8,15 @@ import com.github.czyzby.websocket.serialization.impl.Deserializer; import com.github.czyzby.websocket.serialization.impl.Serializer; public class PlayerState implements Transferable { - private final Vector3 position, direction; + private final Vector3 position; + private final Vector2 direction; private float nextJumpTimestamp; public PlayerState() { - this(new Vector3(), new Vector3()); + this(new Vector3(), new Vector2()); } - public PlayerState(Vector3 position, Vector3 direction) { + public PlayerState(Vector3 position, Vector2 direction) { this.position = position; this.direction = direction; this.nextJumpTimestamp = 0; @@ -28,7 +30,7 @@ public class PlayerState implements Transferable { this.position.set(x, y, z); } - public Vector3 getDirection() { + public Vector2 getDirection() { return direction; } @@ -40,22 +42,23 @@ public class PlayerState implements Transferable { this.nextJumpTimestamp = nextJumpTimestamp; } - public void setDirection(float x, float y, float z) { - this.direction.set(x, y, z); + public void setDirection(float x, float z) { + this.direction.set(x, z); } @Override public void serialize(Serializer serializer) throws SerializationException { serializer .serializeFloatArray(new float[]{position.x, position.y, position.z}) - .serializeFloatArray(new float[]{direction.x, direction.y, direction.z}); + .serializeFloat(direction.x) + .serializeFloat(direction.y); } @Override public PlayerState deserialize(Deserializer deserializer) throws SerializationException { return new PlayerState( new Vector3(deserializer.deserializeFloatArray()), - new Vector3(deserializer.deserializeFloatArray()) + new Vector2(deserializer.deserializeFloat(), deserializer.deserializeFloat()) ); } } -- cgit v1.2.3