Skip to content

Commit

Permalink
WORKING VERSION UPD BOX2D \ HUD | srever
Browse files Browse the repository at this point in the history
  • Loading branch information
Lost-Fly committed May 7, 2024
1 parent f09730c commit 8e5c8a6
Show file tree
Hide file tree
Showing 28 changed files with 282 additions and 396 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.aqwsxlostfly.packandgo.client.dto;


import com.aqwsxlostfly.packandgo.InputState;
import com.aqwsxlostfly.packandgo.session.InputState;

public class InputStateImpl implements InputState {

Expand Down
36 changes: 19 additions & 17 deletions assets/Map.tmx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="48" height="48" tilewidth="16" tileheight="16" infinite="0" nextlayerid="7" nextobjectid="142">
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="48" height="48" tilewidth="16" tileheight="16" infinite="0" nextlayerid="8" nextobjectid="142">
<tileset firstgid="1" name="atlas16" tilewidth="16" tileheight="16" tilecount="768" columns="48">
<image source="atlas16x.png" width="768" height="256"/>
</tileset>
Expand Down Expand Up @@ -28,20 +28,7 @@
eJztmVlsVFUYxz+S0lJpCy6Jxg4z05Z2KLglaiguD+IuSNIWWXyagi8u4BYB8cm6RMFXoLhO4gJlirGFoPiksmgMLl1mphSNCyq4vKiJ+4O/6703cz1zOnPPnUtsEx9++b77nTPn+8+535x7v3Zoqrw1CMMwNIl811ocqZbk1diFcBVMBh/N4nyPFLHUH5UiYZCbKkk19if8pfgjTk7dmB+f75IctEnhpzZViehoj4t0QCcsjevneMmyphrbDE8pfsbJqRvz47PnSfY+yT1IcT9S504TsWiIiTRCU8y+7kfzAOyBvXE75jI/KtIGCyAJXbClRpJnJ0TOSeTn1UNE8bNOTt2YH3+hrT3p1s8uYhYXoPtCuChmXxfjGvReC9fBGljr6F+P9g2J/Lw09Cl+zsmpG/Pjq/XTPUXkEbgc3VfAl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u+pf8AOg7CoVpz39Jvkv/hquB0W39jsP5HHOFsg86Irb+zTmQp3FJn7lv6TfJ/w2dOwMm64P4X6P4SjkfCqR+T3OtmiKyHDTOC+/fOErkP7p8VTv2Y5K6cKVIF02aG44dRPyb5wqgfr7+MGloOK2BlAP/WiFm+vwFEpZ5j
</data>
</layer>
<layer id="2" name="graphics" width="48" height="48">
<data encoding="base64" compression="zlib">
eJztl0lOw0AQRStKAiwY9sACRUoOQhg2EO7AeBBYAScBEiTGezDeBVjwLWzRarpdXbJD3FY96UnVrXT5x3JiFZFSBT6miD7hV6q59tWuPbtXwnaHaNAJy3HTJLqFd/AePsDHJn/udJroDJ6nmmtf7dqzeyUMkX0UmH+1RdSHa3AdbsDNFn9ucYZoCS6nmmtf7dqze211cf/hAO50+RxPyPoMX+ArfIPvAfkvcK1LeJVqrn21a+9PL2QewhG8Dsi/2ybag/vwAB7CozZ/LuO48avks+YZs57tEc3BebjQc/c5afyY19d1naoQe34J0vyxf2/NX16GImf/K3/Zv9lJ58/2yuw3Tur2f6koCo90rgqpJdcs2ls6V4XUHNJ+eb2lc1VIzSHtl9dbOleF1BzSfnm9sxnCnCPstU3Z70lfj1jewUXmLu5ejxtulq57/qoQS9b+yqQTKDGTPD8hVpXY8ytxEfvzFHt+RVEURakT3zUj56E=
</data>
</layer>
<objectgroup id="3" name="lightObject">
<object id="102" type="flowers" gid="11721" x="337.995" y="544.009" width="32" height="32"/>
<object id="103" type="flowers" gid="11721" x="254.468" y="543.015" width="32" height="32"/>
<object id="110" name="tabouret" type="tabouret" gid="11567" x="469.333" y="745.333" width="32" height="32"/>
</objectgroup>
<objectgroup id="6" name="hero">
<object id="111" name="hero" gid="11991" x="444.667" y="721.333" width="16" height="16"/>
</objectgroup>
<objectgroup id="5" name="ground">
<objectgroup id="7" name="floor">
<object id="34" type="floor" x="31.3333" y="92.6667" width="287.333" height="211.333"/>
<object id="35" type="floor" x="336.667" y="94.6667" width="142.667" height="208.667"/>
<object id="36" type="floor" x="496.667" y="95.3333" width="238.667" height="207.333"/>
Expand All @@ -53,6 +40,21 @@
<object id="42" type="floor" x="416" y="478.667" width="63.3333" height="32.6667"/>
<object id="44" type="floor" x="480" y="400" width="15.3333" height="30"/>
<object id="45" type="floor" x="160.364" y="416.364" width="15.2727" height="30.9091"/>
</objectgroup>
<layer id="2" name="graphics" width="48" height="48">
<data encoding="base64" compression="zlib">
eJztl0lOw0AQRStKAiwY9sACRUoOQhg2EO7AeBBYAScBEiTGezDeBVjwLWzRarpdXbJD3FY96UnVrXT5x3JiFZFSBT6miD7hV6q59tWuPbtXwnaHaNAJy3HTJLqFd/AePsDHJn/udJroDJ6nmmtf7dqzeyUMkX0UmH+1RdSHa3AdbsDNFn9ucYZoCS6nmmtf7dqze211cf/hAO50+RxPyPoMX+ArfIPvAfkvcK1LeJVqrn21a+9PL2QewhG8Dsi/2ybag/vwAB7CozZ/LuO48avks+YZs57tEc3BebjQc/c5afyY19d1naoQe34J0vyxf2/NX16GImf/K3/Zv9lJ58/2yuw3Tur2f6koCo90rgqpJdcs2ls6V4XUHNJ+eb2lc1VIzSHtl9dbOleF1BzSfnm9sxnCnCPstU3Z70lfj1jewUXmLu5ejxtulq57/qoQS9b+yqQTKDGTPD8hVpXY8ytxEfvzFHt+RVEURakT3zUj56E=
</data>
</layer>
<objectgroup id="3" name="lightObject">
<object id="102" name="flowers" type="flowers" gid="11721" x="337.995" y="544.009" width="32" height="32"/>
<object id="103" name="flowers" type="flowers" gid="11721" x="254.468" y="543.015" width="32" height="32"/>
<object id="110" name="tabouret" type="tabouret" gid="11567" x="469.333" y="745.333" width="32" height="32"/>
</objectgroup>
<objectgroup id="6" name="hero">
<object id="111" name="hero" gid="11991" x="444.667" y="721.333" width="16" height="16"/>
</objectgroup>
<objectgroup id="5" name="walls">
<object id="113" name="wall" type="wall" x="-1.33333" y="-4" width="32" height="516"/>
<object id="115" name="wall" type="wall" x="0" y="0" width="769.333" height="94.6667"/>
<object id="116" name="wall" type="wall" x="737.333" y="-1.33333" width="30.6667" height="510.667"/>
Expand All @@ -74,8 +76,8 @@
<object id="135" name="wall" type="wall" x="0" y="655" width="321" height="52"/>
<object id="136" name="wall" type="wall" x="320" y="653" width="15" height="115"/>
<object id="137" name="wall" type="wall" x="321" y="751" width="271" height="16"/>
<object id="139" name="wall" type="wall" x="575.5" y="656" width="20.5" height="114"/>
<object id="139" name="wall" type="wall" x="577" y="656" width="19" height="114"/>
<object id="140" name="wall" type="wall" x="383" y="32" width="67" height="82"/>
</objectgroup>
<objectgroup id="4" name="heavyObjects"/>
</map>
</map>
2 changes: 1 addition & 1 deletion assets/env.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
WS_URI=ws://192.168.170.241:8867/ws
WS_URI=ws://192.168.2.176:8867/ws
44 changes: 22 additions & 22 deletions core/src/com/aqwsxlostfly/packandgo/AssetManagerSingleton.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion core/src/com/aqwsxlostfly/packandgo/Heroes/Heroes.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.aqwsxlostfly.packandgo.Heroes;

import com.aqwsxlostfly.packandgo.Tools.Point2D;
import com.aqwsxlostfly.packandgo.Tools.figures.Point2D;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.objects.TextureMapObject;
Expand Down
8 changes: 3 additions & 5 deletions core/src/com/aqwsxlostfly/packandgo/Heroes/Player.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.aqwsxlostfly.packandgo.Heroes;

import static com.aqwsxlostfly.packandgo.Tools.TileMapHelper.worldHeight;
import static com.aqwsxlostfly.packandgo.Tools.TileMapHelper.worldWigth;
import static com.aqwsxlostfly.packandgo.Tools.maptools.TileMapHelper.worldHeight;
import static com.aqwsxlostfly.packandgo.Tools.maptools.TileMapHelper.worldWigth;

import com.aqwsxlostfly.packandgo.Tools.Point2D;
import com.aqwsxlostfly.packandgo.Tools.figures.Point2D;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.objects.TextureMapObject;
import com.badlogic.gdx.math.Vector2;
Expand Down Expand Up @@ -46,7 +46,6 @@ public float getY(){
}

public void setTransform(float x, float y, float angle){

body.setTransform(x, y, angle);
}

Expand All @@ -69,4 +68,3 @@ public void draw(SpriteBatch batch) {
}
}


10 changes: 6 additions & 4 deletions core/src/com/aqwsxlostfly/packandgo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.aqwsxlostfly.packandgo.Screens.HomeSc;
import com.aqwsxlostfly.packandgo.Screens.PlayScreen;
import com.aqwsxlostfly.packandgo.render.Renderer;
import com.aqwsxlostfly.packandgo.session.GameSession;
import com.aqwsxlostfly.packandgo.session.InputState;
import com.aqwsxlostfly.packandgo.session.MessageSender;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
Expand All @@ -26,11 +29,12 @@ public Main(InputState inputState) {
}



public static int screenWidth;
public static int screenHeight;

public boolean socketState;


@Override
public void create() {

Expand All @@ -47,7 +51,6 @@ public void render() {
}



public void evict(String idToEvict) {
PlayScreen.players.remove(idToEvict);
}
Expand Down Expand Up @@ -89,5 +92,4 @@ public void setSocketState(boolean socketState) {
}



}
}
14 changes: 7 additions & 7 deletions core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
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.changeToPlayScreen;
import static com.aqwsxlostfly.packandgo.render.Renderer.setGameScreen;

import com.aqwsxlostfly.packandgo.Heroes.Player;
import com.aqwsxlostfly.packandgo.Main;
import com.aqwsxlostfly.packandgo.SessionState;
import com.aqwsxlostfly.packandgo.SessionStateToSend;
import com.aqwsxlostfly.packandgo.Tools.FlyingObject;
import com.aqwsxlostfly.packandgo.Tools.ScreenConsumer;
import com.aqwsxlostfly.packandgo.Tools.hud.FlyingObject;
import com.aqwsxlostfly.packandgo.session.SessionState;
import com.aqwsxlostfly.packandgo.session.SessionStateToSend;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL20;
Expand Down Expand Up @@ -282,9 +282,9 @@ private void connectToServer(String password, String roomId, boolean isCreating)
String action = isCreating ? "createRoom" : "joinRoom";
SessionState sessionState = new SessionStateToSend(action, roomId, password);
try {
setGameScreen(new PlayScreen());
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());
Expand Down Expand Up @@ -315,12 +315,12 @@ 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();
changeToPlayScreen();
break;
case "session_exists":
showErrorDialog(SESSION_EXISTS, SESSION_EXIST_TEXT, 5);
break;
case "does_not_exist":
case "does_not_exists":
showErrorDialog(JOIN_ERROR, DOES_NOT_EXIST_TEXT, 5);
break;
case "incorrect_password":
Expand Down
59 changes: 36 additions & 23 deletions core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
import static com.aqwsxlostfly.packandgo.Main.messageSender;
import static com.aqwsxlostfly.packandgo.Main.screenHeight;
import static com.aqwsxlostfly.packandgo.Main.screenWidth;
import static com.aqwsxlostfly.packandgo.Tools.TileMapHelper.world;
import static com.aqwsxlostfly.packandgo.Tools.maptools.TileMapHelper.world;

import com.aqwsxlostfly.packandgo.Heroes.Player;
import com.aqwsxlostfly.packandgo.InputState;
import com.aqwsxlostfly.packandgo.Main;
import com.aqwsxlostfly.packandgo.Tools.Joystick;
import com.aqwsxlostfly.packandgo.Tools.Point2D;
import com.aqwsxlostfly.packandgo.Tools.TileMapHelper;
import com.aqwsxlostfly.packandgo.Tools.figures.Point2D;
import com.aqwsxlostfly.packandgo.Tools.hud.GameHud;
import com.aqwsxlostfly.packandgo.Tools.hud.Joystick;
import com.aqwsxlostfly.packandgo.Tools.maptools.TileMapHelper;
import com.aqwsxlostfly.packandgo.session.InputState;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
Expand All @@ -31,9 +33,10 @@ public class PlayScreen implements Screen {
Joystick joy;
private final TileMapHelper tileMapHelper;

private static final float frameRateRender = 1/60f;
public GameHud gameHud;
private static final float frameRateRender = 1 / 60f;

private static final float frameRateTimer = 1/50f;
private static final float frameRateTimer = 1 / 50f;

private final int mapPixelWidth;
private final int mapPixelHeight;
Expand All @@ -52,12 +55,19 @@ public PlayScreen() {
hudCamera.position.set((float) screenWidth / 2, (float) screenHeight / 2, 0);
hudCamera.update();

loadHeroes();

this.tileMapHelper = new TileMapHelper();
orthogonalTiledMapRenderer = tileMapHelper.setupMap();

updatePlayerArray(meId, 0,0);
updatePlayerArray(meId, 0, 0);
InputMultiplexer inputMultiplexer = new InputMultiplexer();

gameHud = new GameHud(players.get(meId));

inputMultiplexer.addProcessor(gameHud.stage); // Первый обработчик, чтобы убедиться, что UI имеет приоритет
inputMultiplexer.addProcessor(new InputAdapter() { // Ваш текущий обработчик событий в PlayScreen

Gdx.input.setInputProcessor(new InputProcessor() {
@Override
public boolean keyDown(int keycode) {
return false;
Expand Down Expand Up @@ -108,6 +118,8 @@ public boolean scrolled(float amountX, float amountY) {
}
});

Gdx.input.setInputProcessor(inputMultiplexer);


MapProperties properties = tileMapHelper.tiledMap.getProperties();
int mapWidth = properties.get("width", Integer.class);
Expand All @@ -117,7 +129,8 @@ public boolean scrolled(float amountX, float amountY) {
mapPixelWidth = mapWidth * tilePixelWidth;
mapPixelHeight = mapHeight * tilePixelHeight;

loadHeroes();
startSendingState();

}

public void updatePlayerArray(String id, float x_, float y_) {
Expand All @@ -131,9 +144,9 @@ public void updatePlayerArray(String id, float x_, float y_) {

if (players.get(id) != null) {
players.get(id).serverUpdate(x_, y_);
}else{
} else {
Gdx.app.log("ADD NEW PLAYER", "id " + id + " x " + x_ + " y " + y_);
players.put(id, tileMapHelper.getNewPlayer());
players.put(id, tileMapHelper.getPlayer());
}

}
Expand Down Expand Up @@ -167,29 +180,31 @@ 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));
// box2DDebugRenderer.render(world, camera.combined.scl(1));

}

public void updatePlayers(){
public void updatePlayers() {
players.get(meId).setDirection(joy.getDir());
}



@Override
public void dispose() {

gameHud.dispose();
}

public void loadHeroes() {

joy = new Joystick(new Texture("circle.png"),
new Texture("circle.png"),
new Point2D(((screenHeight / 3) / 2 + (screenHeight / 3) / 4),
(screenHeight / 3) / 2 + (screenHeight / 3) / 4), screenHeight / 3);
new Point2D(((float) (screenHeight / 3) / 2 + (float) (screenHeight / 3) / 4),
(float) (screenHeight / 3) / 2 + (float) (screenHeight / 3) / 4), (float) screenHeight / 3);
}

private void startSendingState(){
Timer timer = new Timer();
timer.scheduleTask(new Timer.Task() {
@Override
Expand All @@ -200,7 +215,6 @@ public void run() {
}



private void cameraUpdate(OrthographicCamera camera) {
// Устанавливаем позицию камеры на игрока
camera.position.set(players.get(meId).getBody().getPosition().x, players.get(meId).getBody().getPosition().y, 0);
Expand All @@ -222,6 +236,7 @@ private void cameraUpdate(OrthographicCamera camera) {
private float clamp(float value, float min, float max) {
return Math.max(min, Math.min(max, value));
}

public void handleTimer() {
if (!players.isEmpty()) {
Player me = players.get(meId);
Expand All @@ -237,8 +252,6 @@ 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;
}
Expand Down
Loading

0 comments on commit 8e5c8a6

Please sign in to comment.