aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-02-18 12:34:26 +0100
committerTom Smeding <tom@tomsmeding.com>2024-02-18 12:34:26 +0100
commit76f9e9d173c61c41e3072934aafe20612838c4df (patch)
tree2341e0b234f34284d2a30024aeee0aaeebbfac57
parent391361ec46751a0cc91020505c39211aa34aa179 (diff)
let/const
-rw-r--r--game.js58
1 files changed, 29 insertions, 29 deletions
diff --git a/game.js b/game.js
index e34f4c2..08baa51 100644
--- a/game.js
+++ b/game.js
@@ -1,15 +1,15 @@
"use strict";
-var boardRatio = 1.5;
-var ballRadius = 0.01, padWidth = 0.01, padHeight = 0.15, padX = 0.01;
-var padBaseSpeed = 0.8;
+const boardRatio = 1.5;
+const ballRadius = 0.01, padWidth = 0.01, padHeight = 0.15, padX = 0.01;
+const padBaseSpeed = 0.8;
-var gameId;
-var cvs, ctx, cvsW, cvsH, bdW, bdH, bdltX, bdltY;
-var socket;
-var playing = false, flip = false;
-var ballX, ballY, ballVX, ballVY;
-var padPos, padVel, pad2Pos, pad2Vel;
+let gameId;
+let cvs, ctx, cvsW, cvsH, bdW, bdH, bdltX, bdltY;
+let socket;
+let playing = false, flip = false;
+let ballX, ballY, ballVX, ballVY;
+let padPos, padVel, pad2Pos, pad2Vel;
function redraw() {
ctx.fillStyle = "#000000";
@@ -60,7 +60,7 @@ function undrawElements() {
}
function resizeHandler() {
- var rect = cvs.getBoundingClientRect();
+ const rect = cvs.getBoundingClientRect();
cvsW = cvs.width = rect.width;
cvsH = cvs.height = rect.height;
// I believe this stuff is correct.
@@ -172,7 +172,7 @@ function openGame() {
socket.emit("open", gameId);
}
-var graphicsLoopId = null, loopPhysics = false;
+let graphicsLoopId = null, loopPhysics = false;
function startGraphicsLoop() {
// undrawElements();
@@ -196,7 +196,7 @@ function startPhysicsLoop() {
}
const now = performance.now();
- var info = advancePhysics((now - prev) / 1e3);
+ const info = advancePhysics((now - prev) / 1e3);
prev = now;
if (info.bounce || info.otherBounce) {
@@ -233,14 +233,14 @@ function initPhysics() {
// Returns {bounce, otherBounce, ourSide : Bool}
function advancePhysics(deltaT) {
- var ret = {bounce: false, otherBounce: false, ourSide: false};
+ const ret = {bounce: false, otherBounce: false, ourSide: false};
- var newballX = ballX + ballVX * deltaT;
- var newballY = ballY + ballVY * deltaT;
- var newpadPos = padPos + padVel * deltaT;
- var newpad2Pos = pad2Pos + pad2Vel * deltaT;
+ let newballX = ballX + ballVX * deltaT;
+ let newballY = ballY + ballVY * deltaT;
+ const newpadPos = padPos + padVel * deltaT;
+ const newpad2Pos = pad2Pos + pad2Vel * deltaT;
- var t;
+ let t;
if (newballY <= ballRadius) {
t = (ballRadius - ballY) / ballVY;
} else if (newballY >= 1 - ballRadius) {
@@ -282,15 +282,15 @@ function advancePhysics(deltaT) {
return ret;
}
-var soundMap = {};
+const soundMap = {};
function preloadSounds() {
- var names = ["bounce", "leave", "ready", "start", "join", "miss", "score"];
- var types = [["audio/ogg", "ogg"], ["audio/mpeg", "mp3"], ["audio/wav", "wav"]];
- for (var i = 0; i < names.length; i++) {
- var audio = new Audio();
- for (var j = 0; j < types.length; j++) {
- var source = document.createElement("source");
+ const names = ["bounce", "leave", "ready", "start", "join", "miss", "score"];
+ const types = [["audio/ogg", "ogg"], ["audio/mpeg", "mp3"], ["audio/wav", "wav"]];
+ for (let i = 0; i < names.length; i++) {
+ const audio = new Audio();
+ for (let j = 0; j < types.length; j++) {
+ const source = document.createElement("source");
source.type = types[j][0];
source.src = "/snd/" + names[i] + "." + types[j][1];
audio.appendChild(source);
@@ -300,10 +300,10 @@ function preloadSounds() {
}
}
-var lastSoundStampMap = {};
+const lastSoundStampMap = {};
function playSound(name) {
- var now = performance.now();
+ const now = performance.now();
console.log("playSound(\"" + name + "\")");
if (lastSoundStampMap[name] == null || now - lastSoundStampMap[name] >= 500) {
soundMap[name].play();
@@ -312,7 +312,7 @@ function playSound(name) {
}
function setupBindings() {
- var up = false, down = false;
+ let up = false, down = false;
function padUpdate() {
padVel = (down - up) * padBaseSpeed;
@@ -347,7 +347,7 @@ window.addEventListener("load", function() {
openGame();
});
-var resizeDebounceTimeout = null;
+let resizeDebounceTimeout = null;
window.addEventListener("resize", function() {
if (resizeDebounceTimeout != null) return;
resizeDebounceTimeout = setTimeout(function() {