Skip to content

Commit

Permalink
Button on PlayScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
LizaVeprova301 committed May 4, 2024
1 parent e860012 commit 087412f
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 51 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>
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/KtI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MuvGdog+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">
<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" visible="0">
<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="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 +70,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 All @@ -77,5 +79,5 @@
<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" visible="0"/>
<objectgroup id="4" name="heavyObjects"/>
</map>
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.
22 changes: 16 additions & 6 deletions core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,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 @@ -34,6 +37,7 @@ public class PlayScreen implements Screen {
private final TileMapHelper tileMapHelper;

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

// public final Player player;
private Player line;
Expand All @@ -54,16 +58,17 @@ public PlayScreen() {
hudCamera.position.set(screenWidth / 2, 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
// Здесь ваш обработчик событий...

// this.player = tileMapHelper.getPlayer();

// this.line = tileMapHelper.getLine();

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

loadHeroes();


}

public void updatePlayerArray(String id, float x_, float y_) {
Expand Down Expand Up @@ -179,6 +187,8 @@ public void render(SpriteBatch batch, OrthographicCamera camera) {
batch.setProjectionMatrix(hudCamera.combined);

joy.draw(batch); // Рисуем джойстик с использованием камеры HUD
gameHud.update(Math.min(1 / 30F, 1 / 30f));
gameHud.draw();
}

public void updatePlayers(){
Expand All @@ -190,7 +200,7 @@ public void updatePlayers(){

@Override
public void dispose() {

gameHud.dispose();
}

public void loadHeroes() {
Expand Down
123 changes: 95 additions & 28 deletions core/src/com/aqwsxlostfly/packandgo/Tools/GameHud.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,95 @@
//package com.aqwsxlostfly.packandgo.Tools;
//
//import com.aqwsxlostfly.packandgo.Main;
//import com.aqwsxlostfly.packandgo.Screens.GameSc;
//import com.badlogic.gdx.Gdx;
//import com.badlogic.gdx.graphics.Color;
//import com.badlogic.gdx.graphics.g2d.BitmapFont;
//import com.badlogic.gdx.graphics.g2d.GlyphLayout;
//import com.badlogic.gdx.graphics.g2d.SpriteBatch;
//import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
//
//public class GameHud {
// BitmapFont font;
// public GameHud(){
// FreeTypeFontGenerator gen = new FreeTypeFontGenerator((Gdx.files.internal(("font.ttf"))));
// FreeTypeFontGenerator.FreeTypeFontParameter p =new FreeTypeFontGenerator.FreeTypeFontParameter();
// p.size= Main.screenWidth/10;
// p.color = new Color(Color.RED);
// font = gen.generateFont(p);
// }
// public void draw(SpriteBatch batch){
// GlyphLayout gl = new GlyphLayout();
// gl.setText(font, GameSc.player.getHealth()+"");
// font.draw(batch,gl,0,Main.screenHeight);
// gl.setText(font,GameSc.player.getScore()+"");
// font.draw(batch,gl,Main.screenWidth- gl.width,Main.screenHeight);
// }
//}
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 087412f

Please sign in to comment.