Skip to content

Commit

Permalink
Tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
solcloud committed Oct 23, 2022
1 parent 5cb05db commit c6d6829
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 61 deletions.
4 changes: 2 additions & 2 deletions server/src/Core/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ final class Setting
/** @var array<string,int|float> */
public const defaultConstant = [
'moveOneMs' => 0.9,
'moveWalkOneMs' => 0.7,
'moveCrouchOneMs' => 0.5,
'moveWalkOneMs' => 0.6,
'moveCrouchOneMs' => 0.4,
'fallAmountOneMs' => 2,
'crouchDurationMs' => 250,
'jumpDurationMs' => 380,
Expand Down
42 changes: 26 additions & 16 deletions www/assets/js/Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ export class Control {
action.attack(game.getPlayerMeRotation())
})
document.addEventListener('wheel', (event) => {
event.preventDefault()

if (!(game.isPlaying() && game.meIsAlive())) {
if (!game.isPlaying() || !game.meIsAlive()) {
return
}

if (event.deltaY > 0) {
action.equip(InventorySlot.SLOT_SECONDARY)
} else {
action.equip(InventorySlot.SLOT_PRIMARY)
if (event.deltaY > 0) { // wheel down
if (game.playerMe.data.slots[InventorySlot.SLOT_SECONDARY]) {
action.equip(InventorySlot.SLOT_SECONDARY)
} else {
action.equip(InventorySlot.SLOT_KNIFE)
}
} else { // wheel up
if (game.playerMe.data.slots[InventorySlot.SLOT_PRIMARY]) {
action.equip(InventorySlot.SLOT_PRIMARY)
} else {
action.equip(InventorySlot.SLOT_KNIFE)
}
}
})
document.addEventListener('keydown', function (event) {
Expand All @@ -58,10 +64,7 @@ export class Control {
return
}

const actionIndex = self.#setting.getBinds()[event.key]
if (actionIndex !== undefined) {
self.#action.actionCallback[actionIndex](true)
}
self.#processKeyboardEvent(event, true)
});
document.addEventListener('keyup', function (event) {
event.preventDefault()
Expand All @@ -70,14 +73,21 @@ export class Control {
return
}

const actionIndex = self.#setting.getBinds()[event.key]
if (actionIndex !== undefined) {
self.#action.actionCallback[actionIndex](false)
}
self.#processKeyboardEvent(event, false)
});
}

#processKeyboardEvent(event, isKeyDown) {
const actionIndex = this.#setting.getBinds()[event.code]
if (actionIndex !== undefined) {
this.#action.actionCallback[actionIndex](isKeyDown)
}
}

getTickAction() {
return this.#action.getPlayerAction(this.#setting.getSprayTriggerDeltaMs())
if (this.#game.isPlaying() && this.#game.meIsAlive()) {
return this.#action.getPlayerAction(this.#setting.getSprayTriggerDeltaMs())
}
return ''
}
}
1 change: 1 addition & 0 deletions www/assets/js/Enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ const Action = {
EQUIP_BOMB: 12,
BUY_MENU: 13,
SCORE_BOARD: 14,
DROP: 15,
}
16 changes: 8 additions & 8 deletions www/assets/js/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,6 @@ export class Game {
}

updatePlayerData(player, serverState) {
if (this.playerMe.getId() === serverState.id) { // if me
if (this.playerMe.getEquippedSlotId() !== serverState.item.slot) {
this.equip(serverState.item.slot)
}
} else {
this.updateOtherPlayersModels(player.get3DObject(), serverState)
}

if (player.data.isAttacker === this.playerMe.data.isAttacker) { // if player on my team
if (player.data.money !== serverState.money) {
this.#hud.updateMyTeamPlayerMoney(player.data, serverState.money)
Expand All @@ -216,6 +208,14 @@ export class Game {
player.data.item = serverState.item
player.data.isAttacker = serverState.isAttacker
}

if (this.playerMe.getId() === serverState.id) { // if me
if (this.playerMe.getEquippedSlotId() !== serverState.item.slot) {
this.equip(serverState.item.slot)
}
} else {
this.updateOtherPlayersModels(player.get3DObject(), serverState)
}
}

updateOtherPlayersModels(playerObject, data) {
Expand Down
31 changes: 22 additions & 9 deletions www/assets/js/PlayerAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ export class PlayerAction {
this.actionCallback[Action.MOVE_LEFT] = (enabled) => this.moveLeft(enabled)
this.actionCallback[Action.MOVE_BACK] = (enabled) => this.moveBackward(enabled)
this.actionCallback[Action.MOVE_RIGHT] = (enabled) => this.moveRight(enabled)
this.actionCallback[Action.JUMP] = (enabled) => this.jump(enabled)
this.actionCallback[Action.CROUCH] = (enabled) => this.crouch(enabled)
this.actionCallback[Action.WALK] = (enabled) => this.shift(enabled)
this.actionCallback[Action.JUMP] = (enabled) => enabled && this.jump()
this.actionCallback[Action.CROUCH] = (enabled) => enabled ? this.crouch() : this.stand()
this.actionCallback[Action.WALK] = (enabled) => enabled ? this.shift() : this.run()
this.actionCallback[Action.RELOAD] = (enabled) => enabled && this.reload()
this.actionCallback[Action.EQUIP_KNIFE] = (enabled) => enabled && this.equip(InventorySlot.SLOT_KNIFE)
this.actionCallback[Action.EQUIP_PRIMARY] = (enabled) => enabled && this.equip(InventorySlot.SLOT_PRIMARY)
this.actionCallback[Action.EQUIP_SECONDARY] = (enabled) => enabled && this.equip(InventorySlot.SLOT_SECONDARY)
this.actionCallback[Action.EQUIP_BOMB] = (enabled) => enabled && this.equip(InventorySlot.SLOT_BOMB)
this.actionCallback[Action.BUY_MENU] = (enabled) => enabled && this.#hud.toggleBuyMenu()
this.actionCallback[Action.SCORE_BOARD] = (enabled) => this.#hud.toggleScore(enabled)
this.actionCallback[Action.DROP] = (enabled) => enabled && this.drop()
}

attack([x, y]) {
Expand All @@ -58,6 +59,10 @@ export class PlayerAction {
this.#states.equip = slotId
}

drop() {
this.#states.drop = true
}

moveForward(enabled) {
this.#states.moveForward = enabled
}
Expand All @@ -74,16 +79,24 @@ export class PlayerAction {
this.#states.moveRight = enabled
}

jump(enabled) {
this.#states.jumping = enabled
jump() {
this.#states.jumping = true
}

stand() {
this.#states.standing = true
}

crouch() {
this.#states.crouching = true
}

crouch(enabled) {
this.#states.crouching = enabled
run() {
this.#states.running = true
}

shift(enabled) {
this.#states.shifting = enabled
shift() {
this.#states.shifting = true
}

reload() {
Expand Down
27 changes: 14 additions & 13 deletions www/assets/js/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ export class Setting {
sprayTriggerDeltaMs: 80,
preferPerformance: false,
bind: {
'w': Action.MOVE_FORWARD,
'a': Action.MOVE_LEFT,
's': Action.MOVE_BACK,
'd': Action.MOVE_RIGHT,
' ': Action.JUMP,
'Control': Action.CROUCH,
'Shift': Action.WALK,
'r': Action.RELOAD,
'q': Action.EQUIP_KNIFE,
'1': Action.EQUIP_PRIMARY,
'2': Action.EQUIP_SECONDARY,
'5': Action.EQUIP_BOMB,
'b': Action.BUY_MENU,
'KeyW': Action.MOVE_FORWARD,
'KeyA': Action.MOVE_LEFT,
'KeyS': Action.MOVE_BACK,
'KeyD': Action.MOVE_RIGHT,
'Space': Action.JUMP,
'ControlLeft': Action.CROUCH,
'ShiftLeft': Action.WALK,
'KeyR': Action.RELOAD,
'KeyG': Action.DROP,
'KeyQ': Action.EQUIP_KNIFE,
'Digit1': Action.EQUIP_PRIMARY,
'Digit2': Action.EQUIP_SECONDARY,
'Digit5': Action.EQUIP_BOMB,
'KeyB': Action.BUY_MENU,
'Tab': Action.SCORE_BOARD,
},
}
Expand Down
5 changes: 0 additions & 5 deletions www/assets/js/UdpSocketConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,9 @@ export class UdpSocketConnector {
}

startLoop(control, tickMs) {
const game = this.#game
const socket = this.#socket

this.#sendIntervalId = setInterval(function () {
if (!game.isPlaying() || !game.meIsAlive()) {
return;
}

let data = control.getTickAction()
if (data !== '') {
socket.send(data)
Expand Down
9 changes: 1 addition & 8 deletions www/assets/js/WebSocketConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,10 @@ export class WebSocketConnector {
}

startLoop(control, tickMs) {
const game = this.#game
const socket = this.#socket

this.#sendIntervalId = setInterval(function () {
if (game.isPlaying() && game.meIsAlive()) {
socket.send(control.getTickAction())
return
}


socket.send('') // ping
socket.send(control.getTickAction())
}, tickMs)
}
}

0 comments on commit c6d6829

Please sign in to comment.