From 95854947b42e784ac598bb11e48ee97bdcdc3cdc Mon Sep 17 00:00:00 2001 From: Lost-Fly <114507453+Lost-Fly@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:47:17 +0500 Subject: [PATCH] restructed ws client-server logic --- .gitignore | Bin 1682 -> 1760 bytes .../packandgo/client/AndroidLauncher.java | 7 ++- .../packandgo/client/dto/InputStateImpl.java | 43 ++++++++++++------ assets/env.properties | 1 + .../aqwsxlostfly/packandgo/Heroes/Player.java | 9 ++++ .../aqwsxlostfly/packandgo/InputState.java | 4 ++ core/src/com/aqwsxlostfly/packandgo/Main.java | 4 +- .../packandgo/Screens/WaitingSc.java | 13 +++++- .../packandgo/TouchProcessor.java | 11 +++-- 9 files changed, 71 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 3da452091caead65573ad49ac982d9198e9f2773..f680d892e29719bb09c8c845394b5d7b80ef721c 100644 GIT binary patch delta 86 zcmbQl`+#@DBsRZ9hGHO0WheoX`an95p^QO~p@5-?As(); bulletGenerator = new BulletGenerator(); + Timer timer = new Timer(); + timer.scheduleTask(new Timer.Task() { + @Override + public void run() { + handleTimer(); + } + }, 0, 5); } @@ -141,11 +150,13 @@ public void gameRender(SpriteBatch batch) { public void handleTimer() { if (inputProcessor != null && !players.isEmpty()) { Player me = players.get(main.getMeId()); - InputState playerState = inputProcessor.updateAndGetInputState(me.position); + InputState playerState = inputProcessor.updateAndGetInputState(me); main.messageSender.sendMessage(playerState); } } + + public void evict(String idToEvict) { players.remove(idToEvict); } diff --git a/core/src/com/aqwsxlostfly/packandgo/TouchProcessor.java b/core/src/com/aqwsxlostfly/packandgo/TouchProcessor.java index c776ced..bb80e9b 100644 --- a/core/src/com/aqwsxlostfly/packandgo/TouchProcessor.java +++ b/core/src/com/aqwsxlostfly/packandgo/TouchProcessor.java @@ -1,5 +1,6 @@ package com.aqwsxlostfly.packandgo; +import com.aqwsxlostfly.packandgo.Heroes.Player; import com.aqwsxlostfly.packandgo.Tools.Joystick; import com.aqwsxlostfly.packandgo.Tools.Point2D; import com.badlogic.gdx.InputProcessor; @@ -65,9 +66,13 @@ public void multitouch(float x, float y, boolean isDownTouch, int pointer) { } } - public InputState updateAndGetInputState(Point2D playerPos) { - - + public InputState updateAndGetInputState(Player player) { + inputState.setPosition(player.position); + inputState.setGhost(player.isGhost()); + inputState.setHealth(player.getHealth()); + inputState.setRadius(player.radius); + inputState.setScore(player.getScore()); + inputState.setSpeed(player.speed); return inputState; }