Skip to content

Commit

Permalink
ADD Hit sound | EXIT Button
Browse files Browse the repository at this point in the history
  • Loading branch information
Lost-Fly committed May 22, 2024
1 parent c3f781e commit 61730a2
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 13 deletions.
Binary file added assets/hit_sound.mp3
Binary file not shown.
Binary file added assets/scream.mp3
Binary file not shown.
Binary file added assets/take_sound.mp3
Binary file not shown.
24 changes: 22 additions & 2 deletions core/src/com/aqwsxlostfly/packandgo/Screens/GameOverScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,24 @@
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

public class GameOverScreen implements Screen {
private BitmapFont gameOverFont;
private TextButton playAgainButton;

private TextButton backHomeButton;

ImageButton exitButton;
private String score;
private float timeTaken;
private float maxTime;

private String maxItems;

private Stage stage;
private Skin skin;

Expand Down Expand Up @@ -131,6 +132,25 @@ public void clicked(InputEvent event, float x, float y) {
winBackgroundTexture = new Texture(Gdx.files.internal("winbackground.png"));

shapeRenderer = new ShapeRenderer();

Drawable exitDrawable = skin.getDrawable("button_cross");
exitButton = new ImageButton(exitDrawable);
exitButton.setPosition(10, Gdx.graphics.getHeight() - exitButton.getHeight() - 70);
stage.addActor(exitButton);
addExitButtonListener();
}

private void addExitButtonListener() {
exitButton.setSize(100, 100);
exitButton.getImage().getDrawable().setMinWidth(100);
exitButton.getImage().getDrawable().setMinHeight(100);
exitButton.getImage().setSize(100, 100);
exitButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.exit();
}
});
}

@Override
Expand Down
8 changes: 2 additions & 6 deletions core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@
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.changeToPlayScreen;
import static com.aqwsxlostfly.packandgo.render.Renderer.gameScreen;
import static com.aqwsxlostfly.packandgo.render.Renderer.setCurrentScreen;
import static com.aqwsxlostfly.packandgo.render.Renderer.setGameScreen;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;

import com.aqwsxlostfly.packandgo.Heroes.Player;
import com.aqwsxlostfly.packandgo.Main;
Expand All @@ -42,13 +37,14 @@
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

Expand Down
41 changes: 39 additions & 2 deletions core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
Expand All @@ -39,16 +40,26 @@
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

import java.util.Objects;

public class PlayScreen implements Screen {


private static final float TOTAL_GAME_TIME_LVL_1 = 6f * 60f;
// private static final float TOTAL_GAME_TIME_LVL_1 = 6f * 60f;
private static final float TOTAL_GAME_TIME_LVL_1 = 1f;

private int playersAmount = 1;
private boolean isWaitingForPlayers;
private boolean isGameCountdownRunning;
private boolean isGameStarted;
Expand All @@ -69,6 +80,8 @@ public class PlayScreen implements Screen {

private BitmapFont font;

private boolean isScreamPlaying = false;

Joystick joy;
private TileMapHelper tileMapHelper;

Expand All @@ -80,6 +93,8 @@ public class PlayScreen implements Screen {
private final int mapPixelWidth;
private final int mapPixelHeight;



public static ObjectMap<String, Player> players = new ObjectMap<>();
public static ObjectMap<String, Furniture> furnitures = new ObjectMap<>();

Expand All @@ -89,13 +104,15 @@ public class PlayScreen implements Screen {

private InputMultiplexer inputMultiplexer = new InputMultiplexer();

private Sound screamSound;

private final String HOW_TO_PLAY_INFO = "YOU HAVE TO MOVE ALL FURNITURE INTO TRUCK" + "\n"
+ " UNTILE TIME IS GONE!" + "\n" + "CONTACT FURNITURE AND PRESS TAKE TO MOVE IT" + "\n" +
"PRESS KICK TO BYE BYE YOUR TEAMMATE";


public PlayScreen() {

isWaitingForPlayers = true;
isGameCountdownRunning = false;
isGameStarted = false;
Expand All @@ -113,6 +130,8 @@ public PlayScreen() {
musicTools = new MusicTools(PLAYSCREENMUSIC);
musicTools.startMusic();

screamSound = Gdx.audio.newSound(Gdx.files.internal("scream.mp3"));

loadHeroes();

this.tileMapHelper = new TileMapHelper();
Expand Down Expand Up @@ -188,8 +207,12 @@ public boolean scrolled(float amountX, float amountY) {

startSendingState();



}



public void updatePlayerArray(String id, float x_, float y_, boolean isHolding) {

if (Objects.equals(id, meId)) {
Expand Down Expand Up @@ -358,12 +381,19 @@ public void render(SpriteBatch batch, OrthographicCamera camera) {
}
if (players.get(meId).isImpulsed) {
drawTextCenteredPlayer(batch, "AAAaaa", players.get(meId).getX(), players.get(meId).getY(), font);
if (!isScreamPlaying) {
screamSound.play();
isScreamPlaying = true;
}
} else {
isScreamPlaying = false;
}

joy.draw(batch); // Рисуем джойстик с использованием камеры HUD
gameHud.update(frameRateRender);
gameHud.draw();


//box2DDebugRenderer.render(world, camera.combined.scl(1));

}
Expand Down Expand Up @@ -466,7 +496,8 @@ public void updateGameTimers(float delta) {
}

// Проверяем, подключился ли второй игрок и обновляем состояния
if (isWaitingForPlayers && players.size >= 2) {

if (isWaitingForPlayers && players.size >= playersAmount) {
if (Main.isHost) {
timer.scheduleTask(new Timer.Task() {
@Override
Expand Down Expand Up @@ -550,6 +581,7 @@ public void updatePlayers() {
public void dispose() {
orthogonalTiledMapRenderer.dispose();
gameHud.dispose();
screamSound.dispose();
}

public void loadHeroes() {
Expand Down Expand Up @@ -648,6 +680,11 @@ public static void updateAndGetFurnitureInputState(Furniture furniture, String f

public void restart() {

if (screamSound != null) {
screamSound.dispose();
}
screamSound = Gdx.audio.newSound(Gdx.files.internal("scream.mp3"));

Gdx.input.setInputProcessor(inputMultiplexer);

musicTools = new MusicTools(PLAYSCREENMUSIC);
Expand Down
40 changes: 37 additions & 3 deletions core/src/com/aqwsxlostfly/packandgo/Tools/hud/GameHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import static com.aqwsxlostfly.packandgo.Screens.PlayScreen.players;
import static com.aqwsxlostfly.packandgo.Screens.PlayScreen.updateAndGetFurnitureInputState;


import com.aqwsxlostfly.packandgo.Main;
import com.aqwsxlostfly.packandgo.objectsdto.InteractionPlayerImpl;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

import java.util.Objects;
Expand All @@ -29,6 +29,11 @@ public class GameHud {
public TextButton takeBtn;
public TextButton fightBtn;

ImageButton exitButton;

private Sound hitSound;
private Sound takeSound;

public GameHud() {
// Инициализация скина и сцены
skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
Expand All @@ -49,6 +54,28 @@ public GameHud() {
// Добавление обработчика событий для кнопки
addListeners();

hitSound = Gdx.audio.newSound(Gdx.files.internal("hit_sound.mp3"));
takeSound = Gdx.audio.newSound(Gdx.files.internal("take_sound.mp3"));

Drawable exitDrawable = skin.getDrawable("button_cross");
exitButton = new ImageButton(exitDrawable);
exitButton.setPosition(10, Gdx.graphics.getHeight() - exitButton.getHeight() - 70);
stage.addActor(exitButton);
addExitButtonListener();

}

private void addExitButtonListener() {
exitButton.setSize(100, 100);
exitButton.getImage().getDrawable().setMinWidth(100);
exitButton.getImage().getDrawable().setMinHeight(100);
exitButton.getImage().setSize(100, 100);
exitButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.exit();
}
});
}

public void draw() {
Expand All @@ -67,6 +94,8 @@ public void clicked(InputEvent event, float x, float y) {
// Обработка нажатия на кнопку
Gdx.app.log("Button Clicked", "Take button was pressed");

takeSound.play();

if (players.get(meId).isStatusContact()) {
String currFurnitureKey = players.get(meId).getContactFurnitureKey();

Expand Down Expand Up @@ -135,6 +164,10 @@ public void clicked(InputEvent event, float x, float y) {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("Button Clicked", "Kick button was pressed");

hitSound.play();


players.get(meId).resetImpulse();
String nearestPlayerId = findNearestPlayer();
if (nearestPlayerId != null) {
Expand Down Expand Up @@ -188,5 +221,6 @@ public void resize(int width, int height) {
public void dispose() {
stage.dispose();
skin.dispose();
hitSound.dispose();
}
}

0 comments on commit 61730a2

Please sign in to comment.