diff options
| author | ilotterytea <iltsu@alright.party> | 2025-01-22 21:17:25 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-01-22 21:17:25 +0500 |
| commit | 80e7342650a9d71b73a838230733c54c50ffcc1b (patch) | |
| tree | b555c40ef4d15f493f2df7b6b7fe527087c4a58f /shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java | |
| parent | cbcb7b4bebeadd3f61e2f0c6071a000827188887 (diff) | |
upd: Vector2 instead of Vector3 for directions (because we don't actually need the y coordinate)
Diffstat (limited to 'shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java')
| -rw-r--r-- | shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java | 19 |
1 files changed, 11 insertions, 8 deletions
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<PlayerState> { - 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<PlayerState> { this.position.set(x, y, z); } - public Vector3 getDirection() { + public Vector2 getDirection() { return direction; } @@ -40,22 +42,23 @@ public class PlayerState implements Transferable<PlayerState> { 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()) ); } } |
