extend moveset with attack, halt, stop
This commit is contained in:
+42
-5
@@ -271,10 +271,33 @@ function connectWebSocket() {
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown`).style.clipPath = `polygon(0 ${cssPercentage}, 100% ${cssPercentage}, 100% 100%, 0 100%)`
|
||||
if (player.casting?.ability?.id == ability.id) {
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown`).style.clipPath = `polygon(50% 0%, 0% 100%, 100% 100%)` // triangle
|
||||
}
|
||||
else {
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown`).style.clipPath = `polygon(0 ${cssPercentage}, 100% ${cssPercentage}, 100% 100%, 0 100%)`
|
||||
}
|
||||
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown-text`).innerHTML = text
|
||||
}
|
||||
}
|
||||
|
||||
let castIndicatorDisplay = 'none'
|
||||
if (player.casting != null) {
|
||||
castIndicatorDisplay = 'block'
|
||||
const castDuration = (player.casting.ability.castTime * state.tickRate) ?? 0
|
||||
const remainingCastTime = (player.casting.timestamp + castDuration) - state.currentTick
|
||||
let cssPercentage = '100%'
|
||||
if (remainingCastTime > 0) {
|
||||
const castPercentage = 1 - (remainingCastTime / castDuration)
|
||||
cssPercentage = `${Math.round(100 * castPercentage)}%`
|
||||
}
|
||||
|
||||
document.getElementById('cast_indicator_progress').style.clipPath = `polygon(0 0, ${cssPercentage} 0, ${cssPercentage} 100%, 0% 100%)`
|
||||
document.getElementById('cast_indicator_name').innerHTML = player.casting.ability?.name ?? ''
|
||||
}
|
||||
|
||||
document.getElementById('cast_indicator').style.display = castIndicatorDisplay
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,12 +317,12 @@ window.addEventListener('load', () => {
|
||||
const canvas = renderer.domElement
|
||||
canvas.classList.add('canvas')
|
||||
|
||||
canvas.addEventListener('mousedown', (event) => {
|
||||
window.addEventListener('mousedown', (event) => {
|
||||
const intersect = raycastToGround()
|
||||
if (intersect != null) {
|
||||
const { x, y } = intersect
|
||||
if (event.button == 0) {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 0, id: playerId, x, y }))
|
||||
websocket.send(JSON.stringify({ action: 'attack', id: playerId, x, y }))
|
||||
}
|
||||
|
||||
if (event.button == 2) {
|
||||
@@ -311,6 +334,20 @@ window.addEventListener('load', () => {
|
||||
const intersect = raycastToGround()
|
||||
if (intersect != null) {
|
||||
const { x, y } = intersect
|
||||
if (event.code == 'KeyA') {
|
||||
websocket.send(JSON.stringify({ action: 'attack', id: playerId, x, y }))
|
||||
}
|
||||
if (event.code == 'KeyX') {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 0, id: playerId, x, y }))
|
||||
}
|
||||
|
||||
if (event.code == 'KeyS') {
|
||||
websocket.send(JSON.stringify({ action: 'stop', id: playerId }))
|
||||
}
|
||||
if (event.code == 'KeyH') {
|
||||
websocket.send(JSON.stringify({ action: 'halt', id: playerId }))
|
||||
}
|
||||
|
||||
if (event.code == 'KeyQ') {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 1, id: playerId, x, y }))
|
||||
}
|
||||
@@ -330,7 +367,7 @@ window.addEventListener('load', () => {
|
||||
}
|
||||
})
|
||||
|
||||
document.addEventListener('wheel', (event) => {
|
||||
window.addEventListener('wheel', (event) => {
|
||||
if (event.deltaY < 0) {
|
||||
camera.zoom += 0.2
|
||||
if (camera.zoom > 3) {
|
||||
@@ -353,7 +390,7 @@ window.addEventListener('load', () => {
|
||||
renderer.setSize(window.innerWidth, window.innerHeight)
|
||||
})
|
||||
|
||||
document.addEventListener('contextmenu', (event) => event.preventDefault())
|
||||
window.addEventListener('contextmenu', (event) => event.preventDefault())
|
||||
window.addEventListener('keydown', (event) => keysDown[event.code] = true)
|
||||
window.addEventListener('keyup', (event) => keysDown[event.code] = false)
|
||||
window.addEventListener('keydown', (event) => {
|
||||
|
||||
@@ -103,6 +103,35 @@
|
||||
color: white;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.cast-indicator-wrapper {
|
||||
display: none;
|
||||
position: fixed;
|
||||
inset: auto 0 30%;
|
||||
width: 400px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.cast-indicator-progress {
|
||||
position: absolute;
|
||||
background-color: #edd9ff;
|
||||
width: calc(100% - 4px);
|
||||
height: calc(100% - 4px);
|
||||
}
|
||||
|
||||
.cast-indicator-name {
|
||||
text-align: center;
|
||||
color: white;
|
||||
text-shadow: 1px 1px 2px black, 0 0 1em dimgray, 0 0 0.2em dimgray;
|
||||
}
|
||||
|
||||
.cast-indicator-bar {
|
||||
position: relative;
|
||||
background-color: dimgray;
|
||||
width: 100%;
|
||||
height: 20px;
|
||||
padding: 2px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -110,6 +139,12 @@
|
||||
<p>Connection: <span id="connection"></span></p>
|
||||
<pre id="state"></pre>
|
||||
</div>
|
||||
<div id="cast_indicator" class="cast-indicator-wrapper">
|
||||
<div id="cast_indicator_name" class="cast-indicator-name"></div>
|
||||
<div class="cast-indicator-bar">
|
||||
<div id="cast_indicator_progress" class="cast-indicator-progress"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hud">
|
||||
<div id="ability-0" class="ability">
|
||||
A
|
||||
|
||||
Reference in New Issue
Block a user