diff options
Diffstat (limited to 'shared/src/main/java/kz/ilotterytea/frogartha')
7 files changed, 169 insertions, 0 deletions
diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/FrogarthaConstants.java b/shared/src/main/java/kz/ilotterytea/frogartha/FrogarthaConstants.java new file mode 100644 index 0000000..d5cdb06 --- /dev/null +++ b/shared/src/main/java/kz/ilotterytea/frogartha/FrogarthaConstants.java @@ -0,0 +1,13 @@ +package kz.ilotterytea.frogartha; + +public class FrogarthaConstants { + public static class URLS { + public static final String SESSION_WSS = "ws://localhost:20015"; + } + + public static class Player { + public static final float MAX_JUMP_STRENGTH = 1.5f; + public static final float MAX_JUMP_HEIGHT = 2f; + public static final float JUMP_SPEED = 10f; + } +} diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java b/shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java new file mode 100644 index 0000000..15ba015 --- /dev/null +++ b/shared/src/main/java/kz/ilotterytea/frogartha/domain/PlayerState.java @@ -0,0 +1,42 @@ +package kz.ilotterytea.frogartha.domain; + +import com.badlogic.gdx.math.Vector3; + +public class PlayerState { + private final Vector3 position, direction; + private float nextJumpTimestamp; + + public PlayerState() { + this(new Vector3(), new Vector3()); + } + + public PlayerState(Vector3 position, Vector3 direction) { + this.position = position; + this.direction = direction; + this.nextJumpTimestamp = 0; + } + + public Vector3 getPosition() { + return position; + } + + public void setPosition(float x, float y, float z) { + this.position.set(x, y, z); + } + + public Vector3 getDirection() { + return direction; + } + + public float getNextJumpTimestamp() { + return nextJumpTimestamp; + } + + public void setNextJumpTimestamp(float nextJumpTimestamp) { + this.nextJumpTimestamp = nextJumpTimestamp; + } + + public void setDirection(float x, float y, float z) { + this.position.set(x, y, z); + } +} diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/domain/client/PlayerJumpAction.java b/shared/src/main/java/kz/ilotterytea/frogartha/domain/client/PlayerJumpAction.java new file mode 100644 index 0000000..272f514 --- /dev/null +++ b/shared/src/main/java/kz/ilotterytea/frogartha/domain/client/PlayerJumpAction.java @@ -0,0 +1,32 @@ +package kz.ilotterytea.frogartha.domain.client; + +import com.github.czyzby.websocket.serialization.SerializationException; +import com.github.czyzby.websocket.serialization.Transferable; +import com.github.czyzby.websocket.serialization.impl.Deserializer; +import com.github.czyzby.websocket.serialization.impl.Serializer; +import kz.ilotterytea.frogartha.FrogarthaConstants; + +public class PlayerJumpAction implements Transferable<PlayerJumpAction> { + private float jumpStrength; + + public PlayerJumpAction() { + } + + public PlayerJumpAction(Float jumpStrength) { + this.jumpStrength = Math.min(jumpStrength, FrogarthaConstants.Player.MAX_JUMP_STRENGTH); + } + + public float getJumpStrength() { + return jumpStrength; + } + + @Override + public void serialize(Serializer serializer) throws SerializationException { + serializer.serializeFloat(jumpStrength); + } + + @Override + public PlayerJumpAction deserialize(Deserializer deserializer) throws SerializationException { + return new PlayerJumpAction(deserializer.deserializeFloat()); + } +} diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/events/Event.java b/shared/src/main/java/kz/ilotterytea/frogartha/events/Event.java new file mode 100644 index 0000000..dcc0177 --- /dev/null +++ b/shared/src/main/java/kz/ilotterytea/frogartha/events/Event.java @@ -0,0 +1,16 @@ +package kz.ilotterytea.frogartha.events; + +public class Event { + protected int playerId; + + public Event() { + } + + public Event(int playerId) { + this.playerId = playerId; + } + + public int getPlayerId() { + return playerId; + } +} diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/events/PlayerJumpEvent.java b/shared/src/main/java/kz/ilotterytea/frogartha/events/PlayerJumpEvent.java new file mode 100644 index 0000000..a084555 --- /dev/null +++ b/shared/src/main/java/kz/ilotterytea/frogartha/events/PlayerJumpEvent.java @@ -0,0 +1,58 @@ +package kz.ilotterytea.frogartha.events; + +import com.badlogic.gdx.math.Vector3; +import com.github.czyzby.websocket.serialization.SerializationException; +import com.github.czyzby.websocket.serialization.Transferable; +import com.github.czyzby.websocket.serialization.impl.Deserializer; +import com.github.czyzby.websocket.serialization.impl.Serializer; + +public class PlayerJumpEvent extends Event implements Transferable<PlayerJumpEvent> { + private Vector3 startPosition, endPosition; + private float jumpStrength; + + public PlayerJumpEvent() { + super(); + } + + public PlayerJumpEvent(Integer playerId, Vector3 startPosition, Vector3 endPosition, Float jumpStrength) { + super(playerId); + this.startPosition = startPosition; + this.endPosition = endPosition; + this.jumpStrength = jumpStrength; + } + + public Vector3 getStartPosition() { + return startPosition; + } + + public Vector3 getEndPosition() { + return endPosition; + } + + public float getJumpStrength() { + return jumpStrength; + } + + @Override + public void serialize(Serializer serializer) throws SerializationException { + serializer + // id + .serializeInt(playerId) + // start position + .serializeFloatArray(new float[]{startPosition.x, startPosition.y, startPosition.z}) + // end position + .serializeFloatArray(new float[]{endPosition.x, endPosition.y, endPosition.z}) + // jump strength + .serializeFloat(jumpStrength); + } + + @Override + public PlayerJumpEvent deserialize(Deserializer deserializer) throws SerializationException { + return new PlayerJumpEvent( + deserializer.deserializeInt(), + new Vector3(deserializer.deserializeFloatArray()), + new Vector3(deserializer.deserializeFloatArray()), + deserializer.deserializeFloat() + ); + } +} diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/exceptions/PlayerKickException.java b/shared/src/main/java/kz/ilotterytea/frogartha/exceptions/PlayerKickException.java index 4eaf389..ec0deb4 100644 --- a/shared/src/main/java/kz/ilotterytea/frogartha/exceptions/PlayerKickException.java +++ b/shared/src/main/java/kz/ilotterytea/frogartha/exceptions/PlayerKickException.java @@ -21,6 +21,10 @@ public class PlayerKickException extends RuntimeException implements Transferabl return new PlayerKickException("Internal Server Error"); } + public static PlayerKickException jumpSpam() { + return new PlayerKickException("Kicked for jump spamming"); + } + @Override public void serialize(Serializer serializer) throws SerializationException { serializer.serializeString(getMessage()); diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/utils/SerializerUtils.java b/shared/src/main/java/kz/ilotterytea/frogartha/utils/SerializerUtils.java index bf0c3f3..1c62e0d 100644 --- a/shared/src/main/java/kz/ilotterytea/frogartha/utils/SerializerUtils.java +++ b/shared/src/main/java/kz/ilotterytea/frogartha/utils/SerializerUtils.java @@ -2,7 +2,9 @@ package kz.ilotterytea.frogartha.utils; import com.github.czyzby.websocket.serialization.impl.ManualSerializer; import kz.ilotterytea.frogartha.domain.Identity; +import kz.ilotterytea.frogartha.domain.client.PlayerJumpAction; import kz.ilotterytea.frogartha.domain.server.Acknowledge; +import kz.ilotterytea.frogartha.events.PlayerJumpEvent; import kz.ilotterytea.frogartha.exceptions.PlayerKickException; public class SerializerUtils { @@ -10,5 +12,7 @@ public class SerializerUtils { serializer.register(new Acknowledge()); serializer.register(new Identity()); serializer.register(new PlayerKickException()); + serializer.register(new PlayerJumpAction()); + serializer.register(new PlayerJumpEvent()); } } |
