From 5668d338b6b7ce36bd325e7b0623c87c68e65d4d Mon Sep 17 00:00:00 2001 From: Kum1ta Date: Tue, 17 Sep 2024 15:16:42 +0200 Subject: [PATCH] Site - Add function for move ball - add function for quit when opponent disconnect --- .../static/javascript/multiLocalGame/Map.js | 3 +- .../static/javascript/multiOnlineGame/Ball.js | 30 ++++++++++++++- .../static/javascript/multiOnlineGame/Map.js | 38 ++++++++++--------- .../multiOnlineGame/multiOnlineGamePage.js | 25 ++++++++++-- .../javascript/typeResponse/typeGame.js | 23 ++++++----- .../nginx/static/javascript/websocket.js | 2 +- 6 files changed, 84 insertions(+), 37 deletions(-) diff --git a/docker-compose/requirements/nginx/static/javascript/multiLocalGame/Map.js b/docker-compose/requirements/nginx/static/javascript/multiLocalGame/Map.js index 55f4fd0..192662e 100644 --- a/docker-compose/requirements/nginx/static/javascript/multiLocalGame/Map.js +++ b/docker-compose/requirements/nginx/static/javascript/multiLocalGame/Map.js @@ -6,12 +6,11 @@ /* By: edbernar { + fetch(elem.src) + .then(response => response.blob()) + .then(blob => { + elem.blob = URL.createObjectURL(blob); + }); +}); + let spacingImages = [ 100 * 2.33 * 10 - (100 * 2.33), // 2 images 100 * 2.33 * 5 - (100 * 2.33), // 4 images @@ -63,14 +72,9 @@ class Map dispose() { - videoList.forEach(elem => { - elem.video.pause(); - elem.video.src = ''; - elem.video.removeAttribute('src'); - elem.video.load(); - }) videoList = null; - videoCanvas.remove(); + if (videoCanvas) + videoCanvas.remove(); if (videoCanvasTexture) videoCanvasTexture.dispose(); if (materialCanvas) @@ -374,10 +378,8 @@ class Map continue ; } let videoTmp = null; - if (Math.random() < 0.99) - videoTmp = new Video(path[i].src).video; - else - videoTmp = new Video(path[getIndex('easteregg')].src).video; + videoTmp = new Video(path[i].blob).video; + console.log(videoTmp.src); videoTmp.addEventListener('loadeddata', () => { videoTmp.play(); drawVideoOnCanvas(); diff --git a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js index d86294e..79e6391 100644 --- a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js +++ b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js @@ -6,15 +6,17 @@ /* By: edbernar { - sendRequest('game', {action: 3, pos: player.object.position.x, up: player.isUp}); + if (player && player.object.position.x != lastPosition) + { + lastPosition = player.object.position.x; + sendRequest('game', {action: 3, pos: player.object.position.x, up: player.isUp}); + } }, 1000 / 20); } static dispose() { + if (interval) + clearInterval(interval); + interval = null; if (renderer) renderer.dispose(); renderer = null; @@ -146,6 +156,14 @@ class MultiOnlineGamePage } scene = null; } + + static opponentDisconnect() + { + pageRenderer.changePage('lobbyPage'); + setTimeout(() => { + CN.new("Game", "Opponent disconnect", CN.defaultIcon.error); + }, 1000); + } } function createBarPlayer(color) @@ -167,8 +185,9 @@ function loop() { player.update(); opponent.update(); + ball.update(); map.update(ball); renderer.render(scene, player.camera); } -export { MultiOnlineGamePage, opponent }; +export { MultiOnlineGamePage, opponent, ball }; diff --git a/docker-compose/requirements/nginx/static/javascript/typeResponse/typeGame.js b/docker-compose/requirements/nginx/static/javascript/typeResponse/typeGame.js index 94c879e..d823403 100644 --- a/docker-compose/requirements/nginx/static/javascript/typeResponse/typeGame.js +++ b/docker-compose/requirements/nginx/static/javascript/typeResponse/typeGame.js @@ -6,29 +6,28 @@ /* By: edbernar