Skip to content

Commit

Permalink
Merge server-side | new GameHud
Browse files Browse the repository at this point in the history
  • Loading branch information
Lost-Fly committed May 6, 2024
2 parents a94db36 + 04e0354 commit b0593a5
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 8 deletions.
Binary file added assets/AlotOfPerson.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/AlotOfPerson.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.2" name="AlotOfPerson" tilewidth="16" tileheight="16" tilecount="12" columns="4">
<image source="AlotOfPerson.png" width="64" height="51"/>
</tileset>
20 changes: 16 additions & 4 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 All @@ -25,12 +25,10 @@
<tileset firstgid="11991" source="hero.tsx"/>
<layer id="1" name="background" width="48" height="48">
<data encoding="base64" compression="zlib">
eJztmVlsVFUYxz+S0lJpCy6Jxg4z05Z2KLglaiguD+IuSNIWWXyagi8u4BYB8cm6RMFXoLhO4gJlirGFoPiksmgMLl1mphSNCyq4vKiJ+4O/6703cz1zOnPPnUtsEx9++b77nTPn+8+535x7v3Zoqrw1CMMwNIl811ocqZbk1diFcBVMBh/N4nyPFLHUH5UiYZCbKkk19if8pfgjTk7dmB+f75IctEnhpzZViehoj4t0QCcsjevne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rozllabcYdhj0XIflu6j6h0PKO79CpK3CzJrQNs46D/A8WgcP8l6wEfp5fgzAHtjbmo+X0vMuvGdog+hX18mgPQtH0TgGp+OfAWfCWZ54KT1B9n8i2SD7P5Hsf71/fm17s0hH8+Td/360DzRP3v3/v/4npu2qDM4qWK34h+tFLq4VuQQurTX33683y/9jGfwEPyu+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">
Expand All @@ -53,6 +51,20 @@
<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">
</data>
</layer>
<objectgroup id="3" name="lightObject">
<object id="102" name="flowers2" type="flowers" gid="11721" x="337.995" y="544.009" width="32" height="32"/>
<object id="103" name="flowers1" 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="wall">
<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 @@ -68,7 +80,7 @@
<object id="128" name="wall" type="wall" x="318.667" y="158.667" width="21.3333" height="144.667"/>
<object id="129" name="wall" type="wall" x="479.333" y="31.3333" width="18" height="160.667"/>
<object id="130" name="wall" type="wall" x="478.667" y="255.333" width="18.6667" height="50"/>
<object id="131" name="wall" type="wall" x="1" y="478" width="2" height="292"/>
<object id="131" name="wall" type="wall" x="0.0909091" y="478.364" width="2" height="289.545"/>
<object id="133" name="wall" type="wall" x="764.5" y="481" width="3.5" height="286.5"/>
<object id="134" name="wall" type="wall" x="590" y="655" width="176" height="49"/>
<object id="135" name="wall" type="wall" x="0" y="655" width="321" height="52"/>
Expand Down
Binary file added assets/tile_0455.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tile_0457.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tile_0458.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 15 additions & 4 deletions core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
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;
Expand All @@ -33,6 +36,8 @@ 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;
Expand All @@ -57,8 +62,11 @@ public PlayScreen() {
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;
Expand Down Expand Up @@ -108,6 +116,7 @@ public boolean scrolled(float amountX, float amountY) {
return false;
}
});
Gdx.input.setInputProcessor(inputMultiplexer);


MapProperties properties = tileMapHelper.tiledMap.getProperties();
Expand All @@ -119,6 +128,8 @@ public boolean scrolled(float amountX, float amountY) {
mapPixelHeight = mapHeight * tilePixelHeight;

loadHeroes();


}

public void updatePlayerArray(String id, float x_, float y_) {
Expand Down Expand Up @@ -168,6 +179,8 @@ 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));

Expand All @@ -181,7 +194,7 @@ public void updatePlayers(){

@Override
public void dispose() {

gameHud.dispose();
}

public void loadHeroes() {
Expand Down Expand Up @@ -238,8 +251,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
95 changes: 95 additions & 0 deletions core/src/com/aqwsxlostfly/packandgo/Tools/GameHud.java
Original file line number Diff line number Diff line change
@@ -0,0 +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();
}
}

0 comments on commit b0593a5

Please sign in to comment.