From f09730cdfbe32ea513b7703d2c841c6068898170 Mon Sep 17 00:00:00 2001 From: Lost-Fly <114507453+Lost-Fly@users.noreply.github.com> Date: Tue, 7 May 2024 11:22:47 +0500 Subject: [PATCH] 0705 not working but upd --- .../packandgo/client/MessageProcessor.java | 1 - assets/Map.tmx | 22 +- .../packandgo/AssetManagerSingleton.java | 44 ++-- .../packandgo/GraphicsObj/GraphicsObj.java | 2 - core/src/com/aqwsxlostfly/packandgo/Main.java | 5 - .../packandgo/Screens/HomeSc.java | 34 ++-- .../packandgo/Screens/PlayScreen.java | 37 ++-- .../aqwsxlostfly/packandgo/Tools/GameHud.java | 190 +++++++++--------- .../packandgo/Tools/Joystick.java | 2 + .../packandgo/Tools/TileMapHelper.java | 3 - .../packandgo/constants/ScreensConstants.java | 19 ++ .../packandgo/render/Renderer.java | 11 +- .../Sessions/GameSessionManager.java | 3 +- 13 files changed, 179 insertions(+), 194 deletions(-) create mode 100644 core/src/com/aqwsxlostfly/packandgo/constants/ScreensConstants.java diff --git a/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java b/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java index 2291176..3765108 100644 --- a/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java +++ b/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java @@ -48,7 +48,6 @@ private void processObject(JsonValue object) { main.setMeId(meId); break; case "sessionRoom": - String sessionId = object.getString("id"); String sessionPassword = object.getString("password"); String sessionMsg = object.getString("msg"); diff --git a/assets/Map.tmx b/assets/Map.tmx index 18d6802..d55443e 100644 --- a/assets/Map.tmx +++ b/assets/Map.tmx @@ -1,5 +1,5 @@ - + @@ -25,10 +25,12 @@ + eJztmVlsVFUYxz+S0lJpCy6Jxg4z05Z2KLglaiguD+IuSNIWWXyagi8u4BYB8cm6RMFXoLhO4gJlirGFoPiksmgMLl1mphSNCyq4vKiJ+4O/6703cz1zOnPPnUtsEx9++b77nTPn+8+535x7v3Zoqrw1CMMwNIl811ocqZbk1diFcBVMBh/N4nyPFLHUH5UiYZCbKkk19if8pfgjTk7dmB+f75IctEnhpzZViehoj4t0QCcsjevneMmyphrbDE8pfsbJqRvz47PnSfY+yT1IcT9S504TsWiIiTRCU8y+7kfzAOyBvXE75jI/KtIGCyAJXbClRpJnJ0TOSeTn1UNE8bNOTt2YH3+hrT3p1s8uYhYXoPtCuChmXxfjGvReC9fBGljr6F+P9g2J/Lw09Cl+zsmpG/Pjq/XTPUXkEbgc3VfAlTH72o3rbDt6O6ATNsJD0EI8h/bRhD3nUQX3syOenC+S66VYfu0e/O3wNDwDz8Jz8Dy8AKlYYf0U02liW3zOzXhyvoaefo/+l/FfgR2wE3qtWoA09MHuWGH9nCr9WxtFtkEPbG/Mx7MBc+5H+5ux8etHtU9QE0/CJtgcNdf/C5p/hd/gd4/+XJl75rd+tqB5K2yDHh/6rfPfG1vWJLIcVsDKJn39B7F+6+db9uw7+B5+aCy9dlbRvw/Nr8MbsN+jP1Omfr/1cyM5b4JFsLip9NoZRf94drzfeYXzO45h484ZWKE5C/3WTy+ad0Ea+nzoHylTv2vPQ/P5Rc5wv/VTPVvkNJgONbPN6z/o/i/AXlZk//3Wj6lV6z/o/od1/phav/Uf9Pw3rR9T67f+yz3/T1X9+K3/cs9/tX5Yz7r31n21NEgY191T8ji1Fdr6av2U6nc+dfoqkx5J3bNi663hfXVtQr/e3cTvSRTvv3Q9zvX0KzfEbf8Tp68y6ZFU/d4xdz03xwfo+zBhjy3iejHcDEvgI+IfJ+zPu/PV+tH1ODuYtzNu+8eYq/ZCvXN4tkEa+uYUft46I714x9z13BzesTTXfbAbXo3/O6c7X62fLO9mORiN5nucIfzhqO2PMVfthapbebbBdKhpLeyR1P33junWOzRX5PDcwp5LF1fr5zg6v4Kvo/l8n+F/7lwfZa6q53Y03wF3wl2tZmeIbr3medyneYXzdXHT59eoJl85tkUTfwyNj2v06+Jq/Yyxz8ec93tdz6TLF6b+rgaRVbAabmsoHVfr5wTaTzr6dT1T2Pqzyv18G23vwAE42FA6Xqx+dD1TJuT6KXe9Yu8/up5pJGT95a7n1g/fQY5U//N3UStmfS8J03dRnwXesSDrozllabcYdhj0XIflu6j6h0PKO79CpK3CzJrQNs46D/A8WgcP8l6wEfp5fgzAHtjbmo+X0vMuvGdog+hX18mgPQtH0TgGp+OfAWfCWZ54KT1B9n8i2SD7P5Hsf71/fm17s0hH8+Td/360DzRP3v3/v/4npu2qDM4qWK34h+tFLq4VuQQurTX33683y/9jGfwEPyu+pf8AOg7CoVpz39Jvkv/hquB0W39jsP5HHOFsg86Irb+zTmQp3FJn7lv6TfJ/w2dOwMm64P4X6P4SjkfCqR+T3OtmiKyHDTOC+/fOErkP7p8VTv2Y5K6cKVIF02aG44dRPyb5wqgfr7+MGloOK2BlAP/WiFm+vwFEpZ5j + eJztl0lOw0AQRStKAiwY9sACRUoOQhg2EO7AeBBYAScBEiTGezDeBVjwLWzRarpdXbJD3FY96UnVrXT5x3JiFZFSBT6miD7hV6q59tWuPbtXwnaHaNAJy3HTJLqFd/AePsDHJn/udJroDJ6nmmtf7dqzeyUMkX0UmH+1RdSHa3AdbsDNFn9ucYZoCS6nmmtf7dqze211cf/hAO50+RxPyPoMX+ArfIPvAfkvcK1LeJVqrn21a+9PL2QewhG8Dsi/2ybag/vwAB7CozZ/LuO48avks+YZs57tEc3BebjQc/c5afyY19d1naoQe34J0vyxf2/NX16GImf/K3/Zv9lJ58/2yuw3Tur2f6koCo90rgqpJdcs2ls6V4XUHNJ+eb2lc1VIzSHtl9dbOleF1BzSfnm9sxnCnCPstU3Z70lfj1jewUXmLu5ejxtulq57/qoQS9b+yqQTKDGTPD8hVpXY8ytxEfvzFHt+RVEURakT3zUj56E= @@ -51,20 +53,6 @@ - - - - - - - - - - - - - - @@ -80,7 +68,7 @@ - + @@ -90,4 +78,4 @@ - + \ No newline at end of file diff --git a/core/src/com/aqwsxlostfly/packandgo/AssetManagerSingleton.java b/core/src/com/aqwsxlostfly/packandgo/AssetManagerSingleton.java index 6533b41..c1b3425 100644 --- a/core/src/com/aqwsxlostfly/packandgo/AssetManagerSingleton.java +++ b/core/src/com/aqwsxlostfly/packandgo/AssetManagerSingleton.java @@ -1,22 +1,22 @@ -package com.aqwsxlostfly.packandgo; - -import com.badlogic.gdx.assets.AssetManager; -import com.badlogic.gdx.graphics.Texture; - -public class AssetManagerSingleton { - private static AssetManagerSingleton assetManagerSingleton; - - private AssetManager assetManager; - - private AssetManagerSingleton() { - assetManager = new AssetManager(); - } - - public static AssetManager getAssetManager() { - if (assetManagerSingleton == null) { - assetManagerSingleton = new AssetManagerSingleton(); - } - Texture.setAssetManager(assetManagerSingleton.assetManager); - return assetManagerSingleton.assetManager; - } -} +//package com.aqwsxlostfly.packandgo; +// +//import com.badlogic.gdx.assets.AssetManager; +//import com.badlogic.gdx.graphics.Texture; +// +//public class AssetManagerSingleton { +// private static AssetManagerSingleton assetManagerSingleton; +// +// private AssetManager assetManager; +// +// private AssetManagerSingleton() { +// assetManager = new AssetManager(); +// } +// +// public static AssetManager getAssetManager() { +// if (assetManagerSingleton == null) { +// assetManagerSingleton = new AssetManagerSingleton(); +// } +// Texture.setAssetManager(assetManagerSingleton.assetManager); +// return assetManagerSingleton.assetManager; +// } +//} diff --git a/core/src/com/aqwsxlostfly/packandgo/GraphicsObj/GraphicsObj.java b/core/src/com/aqwsxlostfly/packandgo/GraphicsObj/GraphicsObj.java index 48f71a7..730390c 100644 --- a/core/src/com/aqwsxlostfly/packandgo/GraphicsObj/GraphicsObj.java +++ b/core/src/com/aqwsxlostfly/packandgo/GraphicsObj/GraphicsObj.java @@ -12,6 +12,4 @@ public GraphicsObj(Texture img){ public abstract void draw(SpriteBatch batch); - public abstract void update(); - } diff --git a/core/src/com/aqwsxlostfly/packandgo/Main.java b/core/src/com/aqwsxlostfly/packandgo/Main.java index cb9b0c9..9360685 100644 --- a/core/src/com/aqwsxlostfly/packandgo/Main.java +++ b/core/src/com/aqwsxlostfly/packandgo/Main.java @@ -29,13 +29,8 @@ public Main(InputState inputState) { public static int screenWidth; public static int screenHeight; - public static int record; - public boolean socketState; -// public WaitingSc waitingSc; - - @Override public void create() { diff --git a/core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java b/core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java index 19ed50e..210a8fa 100644 --- a/core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java +++ b/core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java @@ -1,6 +1,20 @@ package com.aqwsxlostfly.packandgo.Screens; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.CONNECTING; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.CONNECTING_TEXT; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.CONNECTION_ERROR; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.CREATE_ROOM; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.DOES_NOT_EXIST_TEXT; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.FAILED_TO_CONNECT; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.INCORRECT_PASSWORD_TEXT; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.JOIN_ERROR; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.JOIN_ROOM; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.MAX_PLAYERS_TEXT; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.SESSION_EXISTS; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.SESSION_EXIST_TEXT; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.SOME_ERROR; +import static com.aqwsxlostfly.packandgo.constants.ScreensConstants.SOME_ERROR_TEXT; import static com.aqwsxlostfly.packandgo.render.Renderer.setGameScreen; import com.aqwsxlostfly.packandgo.Heroes.Player; @@ -264,29 +278,13 @@ public void clicked(InputEvent event, float x, float y) { } - - private static final String CONNECTING = "CONNECTING"; - private static final String CONNECTING_TEXT = "CONNECTING..."; - private static final String CONNECTION_ERROR = "Connection Error"; - private static final String FAILED_TO_CONNECT = "Failed to connect to the server. Check your internet."; - private static final String CREATE_ROOM = "CREATE ROOM"; - private static final String JOIN_ROOM = "JOIN ROOM"; - private static final String SESSION_EXISTS = "Creation Error"; - private static final String SESSION_EXIST_TEXT = "Session already exist."; - private static final String DOES_NOT_EXIST_TEXT = "Session does not exist."; - private static final String INCORRECT_PASSWORD_TEXT = "Incorrect session password."; - private static final String JOIN_ERROR = "Joining Error"; - private static final String MAX_PLAYERS_TEXT = "Room is full. Players limit exceeded."; - - private static final String SOME_ERROR = "Error occured"; - private static final String SOME_ERROR_TEXT = "Some error occured. Restart game."; - private void connectToServer(String password, String roomId, boolean isCreating) { String action = isCreating ? "createRoom" : "joinRoom"; SessionState sessionState = new SessionStateToSend(action, roomId, password); try { Main.messageSender.sendMessage(sessionState); startConnectionTimer(isCreating, roomId, password); + } catch (Exception e) { showErrorDialog(CONNECTION_ERROR, FAILED_TO_CONNECT, 5); Gdx.app.log(isCreating ? "ERROR CREATE" : "ERROR JOIN", action + "State " + main.gameSession.getSessionMsg()); @@ -317,7 +315,7 @@ private void checkConnectionStatus(boolean isCreating, String roomId, String pas case "connected_ok": Gdx.app.log(isCreating ? CREATE_ROOM : JOIN_ROOM, "Creating a room with ID: " + roomId + " and password: " + password + " response " + main.gameSession.getSessionMsg()); - setGameScreen(new PlayScreen()); + setGameScreen(); break; case "session_exists": showErrorDialog(SESSION_EXISTS, SESSION_EXIST_TEXT, 5); diff --git a/core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java b/core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java index 5d68a3d..379efe7 100644 --- a/core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java +++ b/core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java @@ -10,22 +10,17 @@ import com.aqwsxlostfly.packandgo.Heroes.Player; import com.aqwsxlostfly.packandgo.InputState; import com.aqwsxlostfly.packandgo.Main; -import com.aqwsxlostfly.packandgo.Tools.GameHud; import com.aqwsxlostfly.packandgo.Tools.Joystick; import com.aqwsxlostfly.packandgo.Tools.Point2D; import com.aqwsxlostfly.packandgo.Tools.TileMapHelper; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.InputAdapter; -import com.badlogic.gdx.InputMultiplexer; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.maps.MapProperties; import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; -import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.Timer; @@ -36,37 +31,33 @@ public class PlayScreen implements Screen { Joystick joy; private final TileMapHelper tileMapHelper; - private static final float frameRate = 1/60f; - public GameHud gameHud; private static final float frameRateRender = 1/60f; private static final float frameRateTimer = 1/50f; - private final int mapWidth, mapHeight, tilePixelWidth, tilePixelHeight, mapPixelWidth, mapPixelHeight; + private final int mapPixelWidth; + private final int mapPixelHeight; public static ObjectMap players = new ObjectMap<>(); private final OrthogonalTiledMapRenderer orthogonalTiledMapRenderer; private final OrthographicCamera hudCamera; - private Box2DDebugRenderer box2DDebugRenderer = new Box2DDebugRenderer(); + private final Box2DDebugRenderer box2DDebugRenderer = new Box2DDebugRenderer(); public PlayScreen() { hudCamera = new OrthographicCamera(screenWidth, screenHeight); hudCamera.viewportWidth = screenWidth; // Размеры для камеры HUD hudCamera.viewportHeight = screenHeight; - hudCamera.position.set(screenWidth / 2, screenHeight / 2, 0); + hudCamera.position.set((float) screenWidth / 2, (float) screenHeight / 2, 0); hudCamera.update(); this.tileMapHelper = new TileMapHelper(); orthogonalTiledMapRenderer = tileMapHelper.setupMap(); updatePlayerArray(meId, 0,0); - InputMultiplexer inputMultiplexer = new InputMultiplexer(); - gameHud = new GameHud(players.get(meId)); // (или передайте player если он нужен для инициализации GameHud) - inputMultiplexer.addProcessor(gameHud.stage); // Первый обработчик, чтобы убедиться, что UI имеет приоритет - inputMultiplexer.addProcessor(new InputAdapter() { // Ваш текущий обработчик событий в PlayScreen + Gdx.input.setInputProcessor(new InputProcessor() { @Override public boolean keyDown(int keycode) { return false; @@ -116,20 +107,17 @@ public boolean scrolled(float amountX, float amountY) { return false; } }); - Gdx.input.setInputProcessor(inputMultiplexer); MapProperties properties = tileMapHelper.tiledMap.getProperties(); - mapWidth = properties.get("width", Integer.class); - mapHeight = properties.get("height", Integer.class); - tilePixelWidth = properties.get("tilewidth", Integer.class); - tilePixelHeight = properties.get("tileheight", Integer.class); + int mapWidth = properties.get("width", Integer.class); + int mapHeight = properties.get("height", Integer.class); + int tilePixelWidth = properties.get("tilewidth", Integer.class); + int tilePixelHeight = properties.get("tileheight", Integer.class); mapPixelWidth = mapWidth * tilePixelWidth; mapPixelHeight = mapHeight * tilePixelHeight; loadHeroes(); - - } public void updatePlayerArray(String id, float x_, float y_) { @@ -179,8 +167,6 @@ public void render(SpriteBatch batch, OrthographicCamera camera) { batch.setProjectionMatrix(hudCamera.combined); joy.draw(batch); // Рисуем джойстик с использованием камеры HUD - gameHud.update(frameRateRender); - gameHud.draw(); box2DDebugRenderer.render(world,camera.combined.scl(1)); @@ -194,7 +180,7 @@ public void updatePlayers(){ @Override public void dispose() { - gameHud.dispose(); + } public void loadHeroes() { @@ -251,8 +237,9 @@ public InputState updateAndGetInputState(Player player) { inputState.setId(meId); inputState.setX(player.getX()); inputState.setY(player.getY()); +// inputState.setX(player.getBody().getLinearVelocity().x); +// inputState.setY(player.getBody().getLinearVelocity().y); return inputState; } } - diff --git a/core/src/com/aqwsxlostfly/packandgo/Tools/GameHud.java b/core/src/com/aqwsxlostfly/packandgo/Tools/GameHud.java index 3ec1522..17923e9 100644 --- a/core/src/com/aqwsxlostfly/packandgo/Tools/GameHud.java +++ b/core/src/com/aqwsxlostfly/packandgo/Tools/GameHud.java @@ -1,95 +1,95 @@ -package com.aqwsxlostfly.packandgo.Tools; - - -import static com.aqwsxlostfly.packandgo.AssetManagerSingleton.getAssetManager; - -import com.aqwsxlostfly.packandgo.Heroes.Player; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.scenes.scene2d.Stage; -import com.badlogic.gdx.scenes.scene2d.ui.Skin; -import com.badlogic.gdx.scenes.scene2d.ui.TextButton; -import com.badlogic.gdx.scenes.scene2d.InputEvent; -import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; -import com.badlogic.gdx.utils.viewport.ScreenViewport; - -public class GameHud { - Texture tabouret; - Texture hero; - public Stage stage; // Используется для управления и отображения UI - public Skin skin; // Скин для стилизации элементов UI - public TextButton takeBtn; // Кнопка в UI - public TextButton fightBtn; // Кнопка в UI - public Player player; - - - public GameHud(Player player) { - tabouret = new Texture("tabouret.png"); - hero = new Texture("tile_0456.png"); - // Инициализация скина и сцены - skin = new Skin(Gdx.files.internal("skin/uiskin.json")); - stage = new Stage(new ScreenViewport()); - - // Установка обработчика ввода в текущую сцену - //Gdx.input.setInputProcessor(stage); - - // Создание и настройка кнопки - takeBtn = new TextButton("Take", skin); - fightBtn = new TextButton("GIVE PUSSY", skin); - takeBtn.setSize(250, 150); // Установка размера кнопки - takeBtn.setPosition(Gdx.graphics.getWidth() -450, Gdx.graphics.getHeight() / 2 - 450); // Позиционирование кнопки - fightBtn.setSize(250, 150); // Установка размера кнопки - fightBtn.setPosition(Gdx.graphics.getWidth() -450, Gdx.graphics.getHeight() / 2 - 250); // Позиционирование кнопки - - this.player = player; - - // Добавление кнопки на сцену - stage.addActor(takeBtn); - stage.addActor(fightBtn); - - // Добавление обработчика событий для кнопки - addListeners(); - - } - - public void draw() { - // Отрисовка сцены (и всех элементов UI на ней) - stage.draw(); - } - - public void update(float delta) { - // Обновление сцены - stage.act(delta); - } - - private void addListeners() { - takeBtn.addListener(new ClickListener() { - - @Override - public void clicked(InputEvent event, float x, float y) { - Texture currentTexture = player.textureMapObject.getTextureRegion().getTexture(); - // Обработка нажатия на кнопку - Gdx.app.log("Button Clicked", "Take button was pressed"); - if (currentTexture != tabouret){ - Gdx.app.log("INFO","смена текстуры"); - player.textureMapObject.getTextureRegion().setTexture(tabouret); - - } else{ - //player.textureMapObject.getTextureRegion().setTexture(null); - player.textureMapObject.getTextureRegion().setTexture(hero); - } - } - }); - } - - // Вызовите этот метод в вашем основном цикле приложения для обеспечения обновления UI - public void resize(int width, int height) { - stage.getViewport().update(width, height, true); - } - - // Не забудьте освободить ресурсы - public void dispose() { - stage.dispose(); - skin.dispose(); - } -} \ No newline at end of file +//package com.aqwsxlostfly.packandgo.Tools; +// +// +//import static com.aqwsxlostfly.packandgo.AssetManagerSingleton.getAssetManager; +// +//import com.aqwsxlostfly.packandgo.Heroes.Player; +//import com.badlogic.gdx.Gdx; +//import com.badlogic.gdx.graphics.Texture; +//import com.badlogic.gdx.scenes.scene2d.Stage; +//import com.badlogic.gdx.scenes.scene2d.ui.Skin; +//import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +//import com.badlogic.gdx.scenes.scene2d.InputEvent; +//import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +//import com.badlogic.gdx.utils.viewport.ScreenViewport; +// +//public class GameHud { +// Texture tabouret; +// Texture hero; +// public Stage stage; // Используется для управления и отображения UI +// public Skin skin; // Скин для стилизации элементов UI +// public TextButton takeBtn; // Кнопка в UI +// public TextButton fightBtn; // Кнопка в UI +// public Player player; +// +// +// public GameHud(Player player) { +// tabouret = new Texture("tabouret.png"); +// hero = new Texture("tile_0456.png"); +// // Инициализация скина и сцены +// skin = new Skin(Gdx.files.internal("skin/uiskin.json")); +// stage = new Stage(new ScreenViewport()); +// +// // Установка обработчика ввода в текущую сцену +// //Gdx.input.setInputProcessor(stage); +// +// // Создание и настройка кнопки +// takeBtn = new TextButton("Take", skin); +// fightBtn = new TextButton("GIVE PUSSY", skin); +// takeBtn.setSize(250, 150); // Установка размера кнопки +// takeBtn.setPosition(Gdx.graphics.getWidth() -450, Gdx.graphics.getHeight() / 2 - 450); // Позиционирование кнопки +// fightBtn.setSize(250, 150); // Установка размера кнопки +// fightBtn.setPosition(Gdx.graphics.getWidth() -450, Gdx.graphics.getHeight() / 2 - 250); // Позиционирование кнопки +// +// this.player = player; +// +// // Добавление кнопки на сцену +// stage.addActor(takeBtn); +// stage.addActor(fightBtn); +// +// // Добавление обработчика событий для кнопки +// addListeners(); +// +// } +// +// public void draw() { +// // Отрисовка сцены (и всех элементов UI на ней) +// stage.draw(); +// } +// +// public void update(float delta) { +// // Обновление сцены +// stage.act(delta); +// } +// +// private void addListeners() { +// takeBtn.addListener(new ClickListener() { +// +// @Override +// public void clicked(InputEvent event, float x, float y) { +// Texture currentTexture = player.textureMapObject.getTextureRegion().getTexture(); +// // Обработка нажатия на кнопку +// Gdx.app.log("Button Clicked", "Take button was pressed"); +// if (currentTexture != tabouret){ +// Gdx.app.log("INFO","смена текстуры"); +// player.textureMapObject.getTextureRegion().setTexture(tabouret); +// +// } else{ +// //player.textureMapObject.getTextureRegion().setTexture(null); +// player.textureMapObject.getTextureRegion().setTexture(hero); +// } +// } +// }); +// } +// +// // Вызовите этот метод в вашем основном цикле приложения для обеспечения обновления UI +// public void resize(int width, int height) { +// stage.getViewport().update(width, height, true); +// } +// +// // Не забудьте освободить ресурсы +// public void dispose() { +// stage.dispose(); +// skin.dispose(); +// } +//} \ No newline at end of file diff --git a/core/src/com/aqwsxlostfly/packandgo/Tools/Joystick.java b/core/src/com/aqwsxlostfly/packandgo/Tools/Joystick.java index 5d7a11b..ba290aa 100644 --- a/core/src/com/aqwsxlostfly/packandgo/Tools/Joystick.java +++ b/core/src/com/aqwsxlostfly/packandgo/Tools/Joystick.java @@ -1,6 +1,7 @@ package com.aqwsxlostfly.packandgo.Tools; import com.aqwsxlostfly.packandgo.Main; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -34,6 +35,7 @@ public void draw(SpriteBatch batch){ } public void update(float x, float y, boolean isDownTouch, int pointer){ + Gdx.app.log("Joystick", "Update called with x: " + x + ", y: " + y + ", isDownTouch: " + isDownTouch + ", pointer: " + pointer); Point2D touch = new Point2D(x, y); if (CircleBounds.isContains(touch) && isDownTouch && this.pointer == -1) this.pointer = pointer; if (CircleBounds.overLaps(StickBounds) && isDownTouch && pointer == this.pointer) atControl(new Point2D(x, y)); diff --git a/core/src/com/aqwsxlostfly/packandgo/Tools/TileMapHelper.java b/core/src/com/aqwsxlostfly/packandgo/Tools/TileMapHelper.java index 0a97253..87ca1ce 100644 --- a/core/src/com/aqwsxlostfly/packandgo/Tools/TileMapHelper.java +++ b/core/src/com/aqwsxlostfly/packandgo/Tools/TileMapHelper.java @@ -34,7 +34,6 @@ public class TileMapHelper { public TiledMap tiledMap; - public static TiledMapTileLayer collisionLayer; public static int worldHeight; public static int worldWigth; private Player player; @@ -79,8 +78,6 @@ public OrthogonalTiledMapRenderer setupMap() { parseMapObjects(tiledMap.getLayers().get("hero").getObjects()); - collisionLayer = (TiledMapTileLayer) tiledMap.getLayers().get(0); - for(MapLayer mapLayer : tiledMap.getLayers()){ // Gdx.app.log("CHECK LAYER", "id " + mapLayer.getName()); diff --git a/core/src/com/aqwsxlostfly/packandgo/constants/ScreensConstants.java b/core/src/com/aqwsxlostfly/packandgo/constants/ScreensConstants.java new file mode 100644 index 0000000..bea4963 --- /dev/null +++ b/core/src/com/aqwsxlostfly/packandgo/constants/ScreensConstants.java @@ -0,0 +1,19 @@ +package com.aqwsxlostfly.packandgo.constants; + +public class ScreensConstants { + public static final String CONNECTING = "CONNECTING"; + public static final String CONNECTING_TEXT = "CONNECTING..."; + public static final String CONNECTION_ERROR = "Connection Error"; + public static final String FAILED_TO_CONNECT = "Failed to connect to the server. Check your internet."; + public static final String CREATE_ROOM = "CREATE ROOM"; + public static final String JOIN_ROOM = "JOIN ROOM"; + public static final String SESSION_EXISTS = "Creation Error"; + public static final String SESSION_EXIST_TEXT = "Session already exist."; + public static final String DOES_NOT_EXIST_TEXT = "Session does not exist."; + public static final String INCORRECT_PASSWORD_TEXT = "Incorrect session password."; + public static final String JOIN_ERROR = "Joining Error"; + public static final String MAX_PLAYERS_TEXT = "Room is full. Players limit exceeded."; + + public static final String SOME_ERROR = "Error occured"; + public static final String SOME_ERROR_TEXT = "Some error occured. Restart game."; +} diff --git a/core/src/com/aqwsxlostfly/packandgo/render/Renderer.java b/core/src/com/aqwsxlostfly/packandgo/render/Renderer.java index d0712ea..6e97d59 100644 --- a/core/src/com/aqwsxlostfly/packandgo/render/Renderer.java +++ b/core/src/com/aqwsxlostfly/packandgo/render/Renderer.java @@ -13,7 +13,7 @@ public class Renderer { - public static final SpriteBatch batch = new SpriteBatch(); + private final SpriteBatch batch = new SpriteBatch(); private final OrthographicCamera camera; @@ -35,6 +35,8 @@ public Renderer() { font = generator.generateFont(parameter); generator.dispose(); + Renderer.gameScreen = new PlayScreen(); + } @@ -76,10 +78,9 @@ public void setHomeScreen(HomeSc screen) { // homeScreen.screenToChange(newScreen -> homeScreen = (HomeSc) screen); } - public static void setGameScreen(PlayScreen screen) { - gameScreen = screen; + public static void setGameScreen() { currentScreen = gameScreen; -// gameScreen.screenToChange(newScreen -> gameScreen = (PlayScreen) screen); +// gameScreen.screenToChange(newScreen -> gameScreen = (PlayScreen) gameScreen); } -} +} \ No newline at end of file diff --git a/server/src/main/java/com/aqwsxlostfly/packandgo/packandgo/Sessions/GameSessionManager.java b/server/src/main/java/com/aqwsxlostfly/packandgo/packandgo/Sessions/GameSessionManager.java index 08e8f32..ceee671 100644 --- a/server/src/main/java/com/aqwsxlostfly/packandgo/packandgo/Sessions/GameSessionManager.java +++ b/server/src/main/java/com/aqwsxlostfly/packandgo/packandgo/Sessions/GameSessionManager.java @@ -43,13 +43,14 @@ public GameSessionManager(Json json) { } public String getSessionIdByUserId(String userSessionId) { + return userToSession.getOrDefault(userSessionId, null); } public void updateGameSession(String userId, JsonNode state) { String sessionId = getSessionIdByUserId(userId); - if (activeGameSessions.containsKey(sessionId)) { + if (sessionId != null && activeGameSessions.containsKey(sessionId)) { activeGameSessions.get(sessionId).updateGameState(state); } else { // TODO