Skip to content

Commit

Permalink
UX improve (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
beverly-hills-money-gangster authored Oct 15, 2024
1 parent 34bf978 commit cf89ef9
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 68 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ project(":core") {
implementation 'commons-io:commons-io:2.8.0'
api 'org.apache.commons:commons-lang3:3.13.0'
api 'ch.qos.logback:logback-classic:1.4.12'
api "com.github.beverly-hills-money-gangster.Daikombat-server:net-client:15.0.0"
api "com.github.beverly-hills-money-gangster.Daikombat-server:net-client:16.0.0"
api 'commons-validator:commons-validator:1.7'
api 'org.apache.commons:commons-math3:3.6.1'
compileOnly 'org.projectlombok:lombok:1.18.30'
Expand Down
2 changes: 2 additions & 0 deletions core/src/com/beverly/hills/money/gang/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface Configs {
int MAX_RECONNECTIONS = NumberUtils.toInt(
System.getenv("DESKTOP_MAX_RECONNECTIONS"), 5);

int SPEED_BOOST = NumberUtils.toInt(System.getenv("DESKTOP_SPEED_BOOST"), 1);

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public class EnemyPlayer extends Enemy {
@Getter
private final String name;

@Getter
private final String enemyClass;

@Getter
@Setter
private int hp;

private long movingAnimationUntil;

private long shootingAnimationUntil;
Expand All @@ -66,9 +73,13 @@ public EnemyPlayer(final Player player,
final String name,
final TexturesRegistry enemyTextureRegistry,
final EnemyListeners enemyListeners,
final int speed) {
final int speed,
final int hp,
final String enemyClass) {

super(position, screen, player, enemyListeners);
this.hp = hp;
this.enemyClass = enemyClass;
this.enemyPlayerId = enemyPlayerId;
lastDirection = direction;
enemyTextures = new EnemyTextures(screen.getGame().getAssMan(), enemyTextureRegistry);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.beverly.hills.money.gang.entities.player;

import static com.beverly.hills.money.gang.Configs.SPEED_BOOST;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Buttons;
Expand Down Expand Up @@ -90,7 +92,7 @@ public Player(final GameScreen screen,
final int speed,
final Map<Weapon, WeaponStats> weaponStats) {
super(screen);
this.speed = speed;
this.speed = speed * SPEED_BOOST;
screenWeapon = new ScreenWeapon(screen.getGame().getAssMan(), weaponStats);
this.onMovementListener = onMovementListener;
this.onAttackListener = onAttackListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.beverly.hills.money.gang.network.LoadBalancedGameConnection;
import com.beverly.hills.money.gang.proto.PushGameEventCommand;
import com.beverly.hills.money.gang.proto.PushGameEventCommand.GameEventType;
import com.beverly.hills.money.gang.proto.PushGameEventCommand.WeaponType;
import com.beverly.hills.money.gang.proto.Vector;
import com.beverly.hills.money.gang.proto.WeaponType;
import com.beverly.hills.money.gang.screens.PlayScreen;
import com.beverly.hills.money.gang.screens.data.PlayerConnectionContextData;
import com.beverly.hills.money.gang.screens.ui.EnemyAim;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,8 +29,8 @@ public static Player create(
LOG.warn("Can't shoot while being teleported");
return;
}
PushGameEventCommand.WeaponType weaponType = switch (playerWeapon.getWeapon()) {
case GAUNTLET -> PushGameEventCommand.WeaponType.PUNCH;
WeaponType weaponType = switch (playerWeapon.getWeapon()) {
case GAUNTLET -> WeaponType.PUNCH;
case SHOTGUN -> WeaponType.SHOTGUN;
case RAILGUN -> WeaponType.RAILGUN;
case MINIGUN -> WeaponType.MINIGUN;
Expand All @@ -46,10 +48,10 @@ public static Player create(
.setPlayerId(playerConnectionContextData.getPlayerId())
.setSequence(screen.getActionSequence().incrementAndGet())
.setDirection(
PushGameEventCommand.Vector.newBuilder().setX(direction.x).setY(direction.y)
Vector.newBuilder().setX(direction.x).setY(direction.y)
.build())
.setPosition(
PushGameEventCommand.Vector.newBuilder().setX(position.x).setY(position.y)
Vector.newBuilder().setX(position.x).setY(position.y)
.build())
.setAffectedPlayerId(enemy.getEnemyPlayerId())
.setEventType(GameEventType.ATTACK)
Expand All @@ -66,10 +68,10 @@ public static Player create(
.orElse(0))
.setPlayerId(playerConnectionContextData.getPlayerId())
.setDirection(
PushGameEventCommand.Vector.newBuilder().setX(direction.x).setY(direction.y)
Vector.newBuilder().setX(direction.x).setY(direction.y)
.build())
.setPosition(
PushGameEventCommand.Vector.newBuilder().setX(position.x).setY(position.y)
Vector.newBuilder().setX(position.x).setY(position.y)
.build())
.setWeaponType(weaponType)
.setEventType(GameEventType.ATTACK)
Expand All @@ -78,7 +80,10 @@ public static Player create(
},
enemy -> {
if (!enemy.getEnemyEffects().isPowerUpActive(PowerUpType.INVISIBILITY)) {
screen.setEnemyAimName(enemy.getName());
screen.setEnemyAim(
EnemyAim.builder().name(enemy.getName()).hp(enemy.getHp())
.playerClass(enemy.getEnemyClass())
.build());
}
},
player -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.beverly.hills.money.gang.handler;

import static com.beverly.hills.money.gang.Constants.DEFAULT_ENEMY_Y;
import static com.beverly.hills.money.gang.proto.WeaponType.PUNCH;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
Expand All @@ -17,13 +18,16 @@
import com.beverly.hills.money.gang.entities.enemies.EnemyPlayerActionType;
import com.beverly.hills.money.gang.entities.item.PowerUpType;
import com.beverly.hills.money.gang.entities.ui.UILeaderBoard;
import com.beverly.hills.money.gang.proto.PlayerClass;
import com.beverly.hills.money.gang.proto.PlayerSkinColor;
import com.beverly.hills.money.gang.proto.ServerResponse;
import com.beverly.hills.money.gang.proto.ServerResponse.GameEvent.GameEventType;
import com.beverly.hills.money.gang.proto.ServerResponse.GameEvent.WeaponType;
import com.beverly.hills.money.gang.proto.ServerResponse.GamePowerUp;
import com.beverly.hills.money.gang.proto.ServerResponse.GamePowerUpType;
import com.beverly.hills.money.gang.proto.Vector;
import com.beverly.hills.money.gang.registry.EnemiesRegistry;
import com.beverly.hills.money.gang.screens.PlayScreen;
import com.beverly.hills.money.gang.screens.ui.selection.PlayerClassUISelection;
import com.beverly.hills.money.gang.screens.ui.weapon.WeaponMapper;
import com.beverly.hills.money.gang.utils.Converter;
import java.util.Optional;
Expand Down Expand Up @@ -157,7 +161,9 @@ private void handleSpawn(ServerResponse.GameEvent gameEvent) {
createVector(gameEvent.getPlayer().getDirection()),
playScreen, gameEvent.getPlayer().getPlayerName(),
getEnemyTexture(gameEvent.getPlayer().getSkinColor()), createEnemyListeners(),
playScreen.getPlayerConnectionContextData().getSpeed());
playScreen.getPlayerConnectionContextData().getSpeed(),
gameEvent.getPlayer().getHealth(),
createPlayerClass(gameEvent.getPlayer().getPlayerClass()).toString());
gameEvent.getPlayer().getActivePowerUpsList().forEach(
gamePowerUp -> activateEnemyPowerUpOnSpawn(
enemyPlayer, getPowerUpType(gamePowerUp.getType()), gamePowerUp.getLastsForMls()));
Expand Down Expand Up @@ -188,13 +194,23 @@ private void handleSpawn(ServerResponse.GameEvent gameEvent) {
}
}

private PlayerClassUISelection createPlayerClass(PlayerClass playerClass) {
return switch (playerClass) {
case COMMONER -> PlayerClassUISelection.COMMONER;
case DRACULA_BERSERK -> PlayerClassUISelection.DRACULA_BERSERK;
case DEMON_TANK -> PlayerClassUISelection.DEMON_TANK;
case BEAST_WARRIOR -> PlayerClassUISelection.BEAST_WARRIOR;
default -> throw new IllegalArgumentException("Not supported class " + playerClass.name());
};
}

private void activateEnemyPowerUpOnSpawn(EnemyPlayer enemyPlayer, PowerUpType powerUpType,
int lastsForMls) {
enemyPlayer.getEnemyEffects().activatePowerUp(powerUpType, lastsForMls);
playScreen.removePowerUp(powerUpType);
}

private TexturesRegistry getEnemyTexture(ServerResponse.PlayerSkinColor playerSkinColor) {
private TexturesRegistry getEnemyTexture(PlayerSkinColor playerSkinColor) {
return switch (playerSkinColor) {
case BLUE -> TexturesRegistry.ENEMY_PLAYER_SPRITES_BLUE;
case PURPLE -> TexturesRegistry.ENEMY_PLAYER_SPRITES_PURPLE;
Expand Down Expand Up @@ -300,7 +316,7 @@ private void handleAttackMiss(ServerResponse.GameEvent gameEvent) {
.enemyPlayerActionType(enemyPlayerActionType)
.direction(Converter.convertToVector2(gameEvent.getPlayer().getDirection()))
.onComplete(() -> {
if (gameEvent.getWeaponType() == WeaponType.PUNCH) {
if (gameEvent.getWeaponType() == PUNCH) {
new TimeLimitedSound(
playScreen.getGame().getAssMan()
.getUserSettingSound(SoundRegistry.ENEMY_PUNCH_THROWN))
Expand All @@ -315,14 +331,17 @@ private void handleAttackMiss(ServerResponse.GameEvent gameEvent) {
private void handleGetHit(ServerResponse.GameEvent gameEvent) {
EnemyPlayerActionType enemyPlayerActionType = EnemyPlayerActionType.ATTACK;

// if I hit somebody, then do nothing. the animation is played one client immediately

// if I get hit
if (gameEvent.getAffectedPlayer().getPlayerId() == playScreen.getPlayerConnectionContextData()
// if I hit somebody
if (gameEvent.getPlayer().getPlayerId() == playScreen.getPlayerConnectionContextData()
.getPlayerId()) {

enemiesRegistry.getEnemy(gameEvent.getAffectedPlayer().getPlayerId())
.ifPresent(enemyPlayer -> enemyPlayer.setHp(gameEvent.getAffectedPlayer().getHealth()));
} else if (gameEvent.getAffectedPlayer().getPlayerId()
== playScreen.getPlayerConnectionContextData().getPlayerId()) {
// if I get hit
enemiesRegistry.getEnemy(gameEvent.getPlayer().getPlayerId())
.ifPresent(enemyPlayer -> {
enemyPlayer.setHp(gameEvent.getPlayer().getHealth());
enemyPlayer.queueAction(EnemyPlayerAction.builder()
.eventSequenceId(gameEvent.getSequence())
.enemyPlayerActionType(enemyPlayerActionType)
Expand All @@ -338,23 +357,26 @@ private void handleGetHit(ServerResponse.GameEvent gameEvent) {
})
.build());
});
} else if (gameEvent.getPlayer().getPlayerId() != playScreen.getPlayerConnectionContextData()
.getPlayerId()) {

} else {
// enemies hitting each other
enemiesRegistry.getEnemy(gameEvent.getPlayer().getPlayerId())
.ifPresent(enemyPlayer -> enemyPlayer.queueAction(EnemyPlayerAction.builder()
.eventSequenceId(gameEvent.getSequence())
.enemyPlayerActionType(enemyPlayerActionType)
.direction(Converter.convertToVector2(gameEvent.getPlayer().getDirection()))
.route(Converter.convertToVector2(gameEvent.getPlayer().getPosition()))
.onComplete(
() -> {
enemyPlayer.attack(WeaponMapper.getWeapon(gameEvent.getWeaponType()), false);
enemiesRegistry.getEnemy(gameEvent.getAffectedPlayer().getPlayerId())
.ifPresent(EnemyPlayer::getHit);
})
.build()));
.ifPresent(enemyPlayer -> {
enemyPlayer.setHp(gameEvent.getPlayer().getHealth());
enemyPlayer.queueAction(EnemyPlayerAction.builder()
.eventSequenceId(gameEvent.getSequence())
.enemyPlayerActionType(enemyPlayerActionType)
.direction(Converter.convertToVector2(gameEvent.getPlayer().getDirection()))
.route(Converter.convertToVector2(gameEvent.getPlayer().getPosition()))
.onComplete(
() -> {
enemyPlayer.attack(WeaponMapper.getWeapon(gameEvent.getWeaponType()), false);
enemiesRegistry.getEnemy(gameEvent.getAffectedPlayer().getPlayerId())
.ifPresent(EnemyPlayer::getHit);
})
.build());
});
enemiesRegistry.getEnemy(gameEvent.getAffectedPlayer().getPlayerId())
.ifPresent(enemyPlayer -> enemyPlayer.setHp(gameEvent.getAffectedPlayer().getHealth()));

}
}
Expand Down Expand Up @@ -474,7 +496,7 @@ private Enemy.EnemyListeners createEnemyListeners() {
).build();
}

private static Vector2 createVector(ServerResponse.Vector serverVector) {
private static Vector2 createVector(Vector serverVector) {
return new Vector2(serverVector.getX(), serverVector.getY());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.beverly.hills.money.gang.proto.JoinGameCommand;
import com.beverly.hills.money.gang.proto.MergeConnectionCommand;
import com.beverly.hills.money.gang.proto.PlayerClass;
import com.beverly.hills.money.gang.proto.PlayerSkinColor;
import com.beverly.hills.money.gang.proto.ServerResponse;
import com.beverly.hills.money.gang.proto.SkinColorSelection;
import com.beverly.hills.money.gang.screens.data.ConnectGameData;
import com.beverly.hills.money.gang.screens.data.PlayerConnectionContextData;
import com.beverly.hills.money.gang.screens.ui.selection.PlayerClassUISelection;
Expand Down Expand Up @@ -52,7 +52,7 @@ public void show() {
var joinGameRequestBuilder = JoinGameCommand.newBuilder()
.setVersion(ClientConfig.VERSION)
.setGameId(Configs.GAME_ID)
.setSkin(creatSkinColorSelection(connectGameData.getSkinUISelection()))
.setSkin(createSkinColorSelection(connectGameData.getSkinUISelection()))
.setPlayerClass(createPlayerClass(connectGameData.getPlayerClassUISelection()))
.setPlayerName(connectGameData.getPlayerName());
Optional.ofNullable(connectGameData.getPlayerIdToRecover())
Expand All @@ -62,14 +62,14 @@ public void show() {

}

private SkinColorSelection creatSkinColorSelection(SkinUISelection skinUISelection) {
private PlayerSkinColor createSkinColorSelection(SkinUISelection skinUISelection) {
return switch (skinUISelection) {
case BLUE -> SkinColorSelection.BLUE;
case YELLOW -> SkinColorSelection.YELLOW;
case ORANGE -> SkinColorSelection.ORANGE;
case GREEN -> SkinColorSelection.GREEN;
case PINK -> SkinColorSelection.PINK;
case PURPLE -> SkinColorSelection.PURPLE;
case BLUE -> PlayerSkinColor.BLUE;
case YELLOW -> PlayerSkinColor.YELLOW;
case ORANGE -> PlayerSkinColor.ORANGE;
case GREEN -> PlayerSkinColor.GREEN;
case PINK -> PlayerSkinColor.PINK;
case PURPLE -> PlayerSkinColor.PURPLE;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void handleInput(final float delta) {

}
} else if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) {
Gdx.app.exit();
removeAllEntities();
getGame().setScreen(new SureExitScreen(getGame()));
} else if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) {
menuSelection.next();
dingSound1.play(Constants.DEFAULT_SFX_VOLUME);
Expand Down
Loading

0 comments on commit cf89ef9

Please sign in to comment.