+ client prediction
This commit is contained in:
LuckyLaszlo
2022-11-22 00:06:07 +01:00
parent 04203f4f9d
commit 2b9058ad49
43 changed files with 53 additions and 15 deletions

View File

@@ -5,6 +5,8 @@ import {matchmaking, matchmakingComplete, startGame} from "./pong.js";
import * as en from "../shared_js/enums.js"
import { Racket } from "../shared_js/class/Rectangle.js";
import { sleep } from "./utils.js";
import * as c from "./constants.js"
import {soundRoblox} from "./audio.js"
const wsPort = 8042;
const wsUrl = "ws://" + document.location.hostname + ":" + wsPort + "/pong";
@@ -88,6 +90,12 @@ async function gameUpdate(data: ev.EventGameUpdate)
function scoreUpdate(data: ev.EventScoreUpdate)
{
if (clientInfo.side === en.PlayerSide.left && data.scoreRight > gc.scoreRight.value) {
soundRoblox.play();
}
else if (clientInfo.side === en.PlayerSide.right && data.scoreLeft > gc.scoreLeft.value) {
soundRoblox.play();
}
gc.scoreLeft.value = data.scoreLeft;
gc.scoreRight.value = data.scoreRight;
}