Skip to content

Commit

Permalink
Fix feedback after testing (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
beverly-hills-money-gangster authored Aug 22, 2024
1 parent f5310f8 commit bc67454
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 11 deletions.
22 changes: 22 additions & 0 deletions core/src/com/beverly/hills/money/gang/entities/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Vector2;
Expand All @@ -21,6 +22,7 @@
import com.beverly.hills.money.gang.screens.ui.weapon.Weapon;
import com.beverly.hills.money.gang.screens.ui.weapon.WeaponRenderData;
import com.beverly.hills.money.gang.screens.ui.weapon.WeaponStats;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
Expand Down Expand Up @@ -102,6 +104,21 @@ public Player(final GameScreen screen,
createRect(spawnPosition.cpy()
.set(spawnPosition.x - Constants.HALF_UNIT + Constants.PLAYER_RECT_SIZE / 2f,
spawnPosition.y - Constants.HALF_UNIT + Constants.PLAYER_RECT_SIZE / 2f));

Gdx.input.setInputProcessor(new InputAdapter() {
@Override
public boolean scrolled(float amountX, float amountY) {
if (isDead.get()) {
return true;
}
if (amountY > 0) {
screenWeapon.changeToPrevWeapon();
} else if (amountY < 0) {
screenWeapon.changeToNextWeapon();
}
return true;
}
});
}

public Vector2 getCurrent2DDirection() {
Expand Down Expand Up @@ -196,6 +213,11 @@ public void handleInput(final float delta) {
} else if (Gdx.input.isKeyJustPressed(Keys.Q)) {
screenWeapon.changeToPrevWeapon();
}
Arrays.stream(Weapon.values()).forEach(weapon -> {
if (Gdx.input.isKeyJustPressed(weapon.getSelectKeyCode())) {
screenWeapon.changeWeapon(weapon);
}
});

// otherwise the screen goes 180 degrees on startup if you don't move the mouse on main menu screens
if (Math.abs(Gdx.input.getDeltaX()) < 500) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.beverly.hills.money.gang.Constants;
import com.beverly.hills.money.gang.DaiKombatGame;
import com.beverly.hills.money.gang.assets.managers.registry.FontRegistry;
import com.beverly.hills.money.gang.screens.ui.weapon.Weapon;
import java.util.Arrays;
import java.util.stream.Collectors;

public class ControlsScreen extends AbstractMainMenuScreen {

Expand All @@ -17,7 +21,11 @@ public class ControlsScreen extends AbstractMainMenuScreen {
"SHOOT - LMC/RIGHT ALT",
"CHAT - TILDA",
"LEADERBOARD - TAB",
"Q,E - CHANGE WEAPON"};
"Q, E, MOUSE SCROLL - NEXT/PREV WEAPON",
Arrays.stream(Weapon.values())
.map(weapon -> Keys.toString(weapon.getSelectKeyCode()))
.collect(Collectors.joining(", "))
+ " - SELECT WEAPON"};
private final BitmapFont guiFont64;

public ControlsScreen(final DaiKombatGame game) {
Expand Down
6 changes: 4 additions & 2 deletions core/src/com/beverly/hills/money/gang/screens/PlayScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ public PlayScreen(final DaiKombatGame game,
() -> getGame().getAssMan()
.getUserSettingSound(SoundRegistry.TYPING_SOUND_SEQ.getNextSound())
.play(Constants.DEFAULT_SFX_TYPING_VOLUME));
texRegBloodOverlay = getGame().getAssMan().getTextureRegion(TexturesRegistry.ATLAS, 0, 0, 2, 2);
texRegBlackOverlay = getGame().getAssMan().getTextureRegion(TexturesRegistry.ATLAS, 3, 0, 2, 2);
texRegBloodOverlay = getGame().getAssMan().getTextureRegion(
TexturesRegistry.ATLAS, 0, 0, 2, 2);
texRegBlackOverlay = getGame().getAssMan().getTextureRegion(
TexturesRegistry.ATLAS, 3, 0, 2, 2);

guiFont64 = getGame().getAssMan().getFont(FontRegistry.FONT_64);
guiFont32 = getGame().getAssMan().getFont(FontRegistry.FONT_32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class ScreenWeapon {

private final Map<Weapon, Long> animationStart = new HashMap<>();

protected static final int CHANGE_WEAPON_DELAY_MLS = 75;

private static final int GUNSHOT_ANIMATION_MLS = 150;

private static final int RAILGUN_ANIMATION_MLS = 200;
Expand All @@ -28,6 +30,8 @@ public class ScreenWeapon {

private final UserSettingSound weaponChangeSound;

private long weaponChangedLastTimeMls;

final Map<Weapon, WeaponState> weaponStates = new EnumMap<>(Weapon.class);

@Getter
Expand Down Expand Up @@ -94,9 +98,11 @@ private static int getBackoffDelay(WeaponStats weaponStats, int animationMls) {
}

public void changeWeapon(Weapon weapon) {
if (weaponBeingUsed == weapon) {
if (weaponBeingUsed == weapon
|| System.currentTimeMillis() < weaponChangedLastTimeMls + CHANGE_WEAPON_DELAY_MLS) {
return;
}
weaponChangedLastTimeMls = System.currentTimeMillis();
setWeaponBeingUsed(weapon);
weaponChangeSound.play(Constants.DEFAULT_SFX_VOLUME);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package com.beverly.hills.money.gang.screens.ui.weapon;

import com.badlogic.gdx.Input.Keys;
import java.util.Arrays;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum Weapon {
GAUNTLET, SHOTGUN, RAILGUN;
GAUNTLET(Keys.NUM_1), SHOTGUN(Keys.NUM_2), RAILGUN(Keys.NUM_3);

static {
int keys = Arrays.stream(Weapon.values()).map(weapon -> weapon.selectKeyCode)
.collect(Collectors.toSet()).size();
if (keys != Weapon.values().length) {
throw new IllegalStateException("Not all weapons have unique select key mapping");
}
}

@Getter
private final int selectKeyCode;

public Weapon nextWeapon() {
return Weapon.values()[(getCurrentIdx() + 1) % Weapon.values().length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,18 @@ public void testChangeWeapon() {
verify(weaponChangeSound).play(anyFloat());
}

@Test
public void testChangeWeaponNoDelay() {
screenWeapon.changeWeapon(Weapon.RAILGUN);
assertEquals(Weapon.RAILGUN, screenWeapon.getWeaponBeingUsed());
screenWeapon.changeWeapon(Weapon.SHOTGUN);
assertEquals(Weapon.RAILGUN, screenWeapon.getWeaponBeingUsed(),
"Weapon should still be the same, because we can't change weapons so fast");
verify(weaponChangeSound).play(anyFloat());

}


@Test
public void testChangeWeaponSame() {
screenWeapon.changeWeapon(Weapon.RAILGUN);
Expand All @@ -290,10 +302,11 @@ public void testChangeWeaponSame() {
}

@Test
public void testChangeWeaponAndShoot() {
public void testChangeWeaponAndShoot() throws InterruptedException {
screenWeapon.changeWeapon(Weapon.RAILGUN);
assertTrue(screenWeapon.canAttack());
screenWeapon.attack(player);
Thread.sleep(ScreenWeapon.CHANGE_WEAPON_DELAY_MLS);
screenWeapon.changeWeapon(Weapon.SHOTGUN);
assertTrue(screenWeapon.canAttack());
screenWeapon.attack(player);
Expand All @@ -303,13 +316,15 @@ public void testChangeWeaponAndShoot() {
}

@Test
public void testChangeWeaponShotChangeShootChangeShoot() {
public void testChangeWeaponShotChangeShootChangeShoot() throws InterruptedException {
screenWeapon.changeWeapon(Weapon.RAILGUN);
assertTrue(screenWeapon.canAttack());
screenWeapon.attack(player);
Thread.sleep(ScreenWeapon.CHANGE_WEAPON_DELAY_MLS);
screenWeapon.changeWeapon(Weapon.SHOTGUN);
assertTrue(screenWeapon.canAttack());
screenWeapon.attack(player);
Thread.sleep(ScreenWeapon.CHANGE_WEAPON_DELAY_MLS);
screenWeapon.changeWeapon(Weapon.RAILGUN);
assertFalse(screenWeapon.canAttack(),
"Can't attack because the animation hasn't finished yet");
Expand All @@ -323,6 +338,7 @@ public void testChangeWeaponShotChangeShootChangeWaitShoot() throws InterruptedE
screenWeapon.changeWeapon(Weapon.RAILGUN);
assertTrue(screenWeapon.canAttack());
screenWeapon.attack(player);
Thread.sleep(ScreenWeapon.CHANGE_WEAPON_DELAY_MLS);
screenWeapon.changeWeapon(Weapon.SHOTGUN);
assertTrue(screenWeapon.canAttack());
screenWeapon.attack(player);
Expand All @@ -340,16 +356,18 @@ public void testChangeWeaponShotChangeShootChangeWaitShoot() throws InterruptedE
}

@Test
public void testChangeWeaponAllWeapons() {
public void testChangeWeaponAllWeapons() throws InterruptedException {
for (Weapon weapon : Weapon.values()) {
screenWeapon.changeWeapon(weapon);
assertEquals(weapon, screenWeapon.getWeaponBeingUsed());
Thread.sleep(ScreenWeapon.CHANGE_WEAPON_DELAY_MLS);
}
}

@Test
public void testChangeToNextWeapon() {
public void testChangeToNextWeapon() throws InterruptedException {
screenWeapon.changeWeapon(Weapon.GAUNTLET);
Thread.sleep(ScreenWeapon.CHANGE_WEAPON_DELAY_MLS);
screenWeapon.changeToNextWeapon();
assertEquals(Weapon.SHOTGUN, screenWeapon.getWeaponBeingUsed());
}
Expand All @@ -365,8 +383,9 @@ public void testChangeToNextWeaponFullCircle() {
}

@Test
public void testChangeToPrevWeapon() {
public void testChangeToPrevWeapon() throws InterruptedException {
screenWeapon.changeWeapon(Weapon.GAUNTLET);
Thread.sleep(ScreenWeapon.CHANGE_WEAPON_DELAY_MLS);
screenWeapon.changeToPrevWeapon();
assertEquals(Weapon.RAILGUN, screenWeapon.getWeaponBeingUsed());
}
Expand Down
2 changes: 1 addition & 1 deletion manual-testing-cases.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ <h3>All tests must be performed against a remote gamer server</h3>
can observe the
game scene, get leaderboard updated and push chat messages. Dead player doesn't get
disconnected. Sound is
consistent while seeing death screen.
consistent while seeing death screen. You can't change weapon while dead.
</td>
<td><input type="checkbox"></td>
</tr>
Expand Down

0 comments on commit bc67454

Please sign in to comment.