Django
- fix request game 10 Game - add screen and redirect when game is finish - fix bug with upper char - add own fps counter and latency counter
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
|
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
|
||||||
# Updated: 2024/09/28 19:34:44 by tomoron ### ########.fr #
|
# Updated: 2024/09/29 02:03:40 by edbernar ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -180,8 +180,8 @@ class Game:
|
|||||||
def endGame(self, winner):
|
def endGame(self, winner):
|
||||||
if(self.end):
|
if(self.end):
|
||||||
return
|
return
|
||||||
self.p1.sync_send({"action":"game","content":{"action":10,"won":winner==1}})
|
self.p1.sync_send({"type":"game","content":{"action":10,"won":winner==1}})
|
||||||
self.p2.sync_send({"action":"game","content":{"action":10,"won":winner==2}})
|
self.p2.sync_send({"type":"game","content":{"action":10,"won":winner==2}})
|
||||||
self.winner = winner
|
self.winner = winner
|
||||||
self.end = True
|
self.end = True
|
||||||
|
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
<div class="pingDiv">
|
<div class="pingDiv">
|
||||||
|
<p id="fps">0 fps</p>
|
||||||
<p id="ping">0 ms</p>
|
<p id="ping">0 ms</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="endGameDiv">
|
||||||
|
<p id="endGameText">You lose...</p>
|
||||||
|
<p id="endGameScore">0 - 0</p>
|
||||||
|
<p id="endGameSimpleText">You will be redirected to the lobby in 5 seconds</p>
|
||||||
|
</div>
|
||||||
<div class="gamePad">
|
<div class="gamePad">
|
||||||
<div id="fullscreen" style="background-image: url('/static/img/multiOnlineGamePage/fullscreen.png');"></div>
|
<div id="fullscreen" style="background-image: url('/static/img/multiOnlineGamePage/fullscreen.png');"></div>
|
||||||
<div class="gamePadLeft">
|
<div class="gamePadLeft">
|
||||||
@ -13,4 +19,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- <img src="/static/img/multiOnlineGamePage/left-arrow.png"> -->
|
<!-- <img src="/static/img/multiOnlineGamePage/left-arrow.png"> -->
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/22 17:08:46 by madegryc #+# #+# */
|
/* Created: 2024/08/22 17:08:46 by madegryc #+# #+# */
|
||||||
/* Updated: 2024/09/28 16:58:08 by edbernar ### ########.fr */
|
/* Updated: 2024/09/29 01:34:41 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ class LobbyPage
|
|||||||
const inputUser = document.getElementById('searchInputUser');
|
const inputUser = document.getElementById('searchInputUser');
|
||||||
const func = [selectGameModeOne, selectGameModeTwo, selectGameModeThree, selectGameModeFour];
|
const func = [selectGameModeOne, selectGameModeTwo, selectGameModeThree, selectGameModeFour];
|
||||||
|
|
||||||
|
document.body.style.opacity = 1;
|
||||||
if (userMeInfo.id == -1)
|
if (userMeInfo.id == -1)
|
||||||
waitForLogin().then(() => usernameP.innerHTML = userMeInfo.username);
|
waitForLogin().then(() => usernameP.innerHTML = userMeInfo.username);
|
||||||
else
|
else
|
||||||
@ -145,7 +146,6 @@ function startMode()
|
|||||||
function startMultiLocal()
|
function startMultiLocal()
|
||||||
{
|
{
|
||||||
document.body.style.animation = "none";
|
document.body.style.animation = "none";
|
||||||
document.body.offsetHeight;
|
|
||||||
document.body.style.animation = "startGameAnim 0.5s";
|
document.body.style.animation = "startGameAnim 0.5s";
|
||||||
document.body.style.opacity = 0;
|
document.body.style.opacity = 0;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -156,7 +156,6 @@ function startMultiLocal()
|
|||||||
function startMatchmaking()
|
function startMatchmaking()
|
||||||
{
|
{
|
||||||
document.body.style.animation = "none";
|
document.body.style.animation = "none";
|
||||||
document.body.offsetHeight;
|
|
||||||
document.body.style.animation = "startGameAnim 0.5s";
|
document.body.style.animation = "startGameAnim 0.5s";
|
||||||
document.body.style.opacity = 0;
|
document.body.style.opacity = 0;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
|
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
|
||||||
/* Updated: 2024/09/27 23:59:18 by edbernar ### ########.fr */
|
/* Updated: 2024/09/29 01:18:23 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,7 +27,6 @@ let materialCanvas = null;
|
|||||||
let textureLoaderPlane = null;
|
let textureLoaderPlane = null;
|
||||||
let texturePlane = null;
|
let texturePlane = null;
|
||||||
let ctx = null;
|
let ctx = null;
|
||||||
let fireworkMixer = null;
|
|
||||||
let canvasTextScore = null;
|
let canvasTextScore = null;
|
||||||
let contextTextScore = null;
|
let contextTextScore = null;
|
||||||
let textureTextScore = null;
|
let textureTextScore = null;
|
||||||
@ -614,7 +613,6 @@ class Map
|
|||||||
}
|
}
|
||||||
let videoTmp = null;
|
let videoTmp = null;
|
||||||
videoTmp = new Video(path[i].blob).video;
|
videoTmp = new Video(path[i].blob).video;
|
||||||
console.log(videoTmp.src);
|
|
||||||
videoTmp.addEventListener('loadeddata', () => {
|
videoTmp.addEventListener('loadeddata', () => {
|
||||||
videoTmp.play();
|
videoTmp.play();
|
||||||
drawVideoOnCanvas();
|
drawVideoOnCanvas();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
|
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/28 03:13:14 by edbernar ### ########.fr */
|
/* Updated: 2024/09/29 01:37:45 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ class Player
|
|||||||
document.removeEventListener('keypress', simplePressKey);
|
document.removeEventListener('keypress', simplePressKey);
|
||||||
pressedButton = [];
|
pressedButton = [];
|
||||||
if (this.interval)
|
if (this.interval)
|
||||||
clearInterval(interval);
|
clearInterval(this.interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
resetPosPlayer()
|
resetPosPlayer()
|
||||||
@ -333,21 +333,23 @@ class Player
|
|||||||
|
|
||||||
function addKeyInArr(e)
|
function addKeyInArr(e)
|
||||||
{
|
{
|
||||||
|
const key = e.key.toLowerCase();
|
||||||
let i;
|
let i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < pressedButton.length && e.key != pressedButton[i])
|
while (i < pressedButton.length && key != pressedButton[i])
|
||||||
i++;
|
i++;
|
||||||
if (i == pressedButton.length)
|
if (i == pressedButton.length)
|
||||||
pressedButton.push(e.key);
|
pressedButton.push(e.key.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
function remKeyInArr(e)
|
function remKeyInArr(e)
|
||||||
{
|
{
|
||||||
|
const key = e.key.toLowerCase();
|
||||||
let i;
|
let i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < pressedButton.length && e.key != pressedButton[i])
|
while (i < pressedButton.length && key != pressedButton[i])
|
||||||
i++;
|
i++;
|
||||||
if (i != pressedButton.length)
|
if (i != pressedButton.length)
|
||||||
pressedButton.splice(i, 1);
|
pressedButton.splice(i, 1);
|
||||||
|
@ -6,14 +6,12 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
|
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/28 21:46:40 by edbernar ### ########.fr */
|
/* Updated: 2024/09/29 01:35:50 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
import { createNotification as CN } from "/static/javascript/notification/main.js";
|
|
||||||
import { availableSkins } from '/static/javascript/lobbyPage/3d.js';
|
import { availableSkins } from '/static/javascript/lobbyPage/3d.js';
|
||||||
import * as THREE from '/static/javascript/three/build/three.module.js'
|
import * as THREE from '/static/javascript/three/build/three.module.js'
|
||||||
import Stats from '/static/javascript/three/examples/jsm/libs/stats.module.js'
|
|
||||||
import { OrbitControls } from '/static/javascript/three/examples/jsm/Addons.js';
|
import { OrbitControls } from '/static/javascript/three/examples/jsm/Addons.js';
|
||||||
import { sendRequest } from "/static/javascript/websocket.js";
|
import { sendRequest } from "/static/javascript/websocket.js";
|
||||||
import { Player } from '/static/javascript/multiOnlineGame/Player.js'
|
import { Player } from '/static/javascript/multiOnlineGame/Player.js'
|
||||||
@ -65,11 +63,10 @@ let interval = null;
|
|||||||
let intervalPing = null;
|
let intervalPing = null;
|
||||||
let debug = false;
|
let debug = false;
|
||||||
let lastPingTime = 0;
|
let lastPingTime = 0;
|
||||||
|
let lastFpsTime = 0;
|
||||||
|
let lastFpsDisplayed = 0;
|
||||||
|
|
||||||
// ------------------- (need to be remove) -------------------- //
|
// ------------------- (need to be remove) -------------------- //
|
||||||
const stats = new Stats();
|
|
||||||
stats.showPanel(0);
|
|
||||||
|
|
||||||
const cameraTmp = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight);
|
const cameraTmp = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight);
|
||||||
let controls = null;
|
let controls = null;
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
@ -78,11 +75,12 @@ class MultiOnlineGamePage
|
|||||||
{
|
{
|
||||||
static create(skin)
|
static create(skin)
|
||||||
{
|
{
|
||||||
document.body.appendChild(stats.dom);
|
if (!skin)
|
||||||
|
skin = {player: 0, opponent: 0};
|
||||||
const bar1 = createBarPlayer(availableSkins[skin.player]);
|
const bar1 = createBarPlayer(availableSkins[skin.player]);
|
||||||
const bar2 = createBarPlayer(availableSkins[skin.opponent]);
|
const bar2 = createBarPlayer(availableSkins[skin.opponent]);
|
||||||
|
|
||||||
|
console.log(document.body.getAttribute('style'));
|
||||||
document.body.setAttribute('style', '');
|
document.body.setAttribute('style', '');
|
||||||
scene = new THREE.Scene()
|
scene = new THREE.Scene()
|
||||||
map = new Map(scene, 13, false);
|
map = new Map(scene, 13, false);
|
||||||
@ -172,7 +170,7 @@ class MultiOnlineGamePage
|
|||||||
sendRequest('game', {action: 4});
|
sendRequest('game', {action: 4});
|
||||||
lastPingTime = Date.now();
|
lastPingTime = Date.now();
|
||||||
}
|
}
|
||||||
}, 16);
|
}, 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dispose()
|
static dispose()
|
||||||
@ -233,6 +231,29 @@ class MultiOnlineGamePage
|
|||||||
text.innerText = ping + ' ms';
|
text.innerText = ping + ' ms';
|
||||||
lastPingTime = null;
|
lastPingTime = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static endGame(win)
|
||||||
|
{
|
||||||
|
const endGameDiv = document.getElementById('endGameDiv');
|
||||||
|
const scoreText = document.getElementById('endGameScore');
|
||||||
|
const simpleText = document.getElementById('endGameSimpleText');
|
||||||
|
let intervalEnd = null;
|
||||||
|
let time = 4;
|
||||||
|
|
||||||
|
endGameScore.innerText = `${map.score.player} - ${map.score.opponent}`;
|
||||||
|
if (win)
|
||||||
|
endGameText.innerText = "You win !"
|
||||||
|
endGameDiv.style.display = 'flex';
|
||||||
|
intervalEnd = setInterval(() => {
|
||||||
|
simpleText.innerText = `You will be redirected to the lobby in ${time} seconds`
|
||||||
|
time--;
|
||||||
|
if (time == -1)
|
||||||
|
{
|
||||||
|
clearInterval(intervalEnd);
|
||||||
|
setTimeout(() => pageRenderer.changePage('lobbyPage'), 500);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createBarPlayer(skin)
|
function createBarPlayer(skin)
|
||||||
@ -240,7 +261,6 @@ function createBarPlayer(skin)
|
|||||||
const geometry = new THREE.BoxGeometry(1, 0.1, 0.1);
|
const geometry = new THREE.BoxGeometry(1, 0.1, 0.1);
|
||||||
let material = null;
|
let material = null;
|
||||||
|
|
||||||
console.log(skin)
|
|
||||||
if (skin.color)
|
if (skin.color)
|
||||||
material = new THREE.MeshPhysicalMaterial({color: skin.color});
|
material = new THREE.MeshPhysicalMaterial({color: skin.color});
|
||||||
else
|
else
|
||||||
@ -251,14 +271,8 @@ function createBarPlayer(skin)
|
|||||||
return (mesh);
|
return (mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeBarColor(bar, color)
|
function windowUpdater()
|
||||||
{
|
{
|
||||||
bar.material.color.set(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
function windowUpdater(e)
|
|
||||||
{
|
|
||||||
console.log('udapte');
|
|
||||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||||
player.camera.aspect = window.innerWidth / window.innerHeight;
|
player.camera.aspect = window.innerWidth / window.innerHeight;
|
||||||
player.camera.updateProjectionMatrix();
|
player.camera.updateProjectionMatrix();
|
||||||
@ -266,10 +280,7 @@ function windowUpdater(e)
|
|||||||
|
|
||||||
function loop()
|
function loop()
|
||||||
{
|
{
|
||||||
/////////////
|
showFps();
|
||||||
stats.begin();
|
|
||||||
/////////////
|
|
||||||
|
|
||||||
player.update();
|
player.update();
|
||||||
opponent.update();
|
opponent.update();
|
||||||
ball.update();
|
ball.update();
|
||||||
@ -281,10 +292,24 @@ function loop()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
renderer.render(scene, player.camera);
|
renderer.render(scene, player.camera);
|
||||||
|
}
|
||||||
|
|
||||||
/////////////
|
let lastFpsArr = [10, 3, 5];
|
||||||
stats.end();
|
|
||||||
////////////
|
function showFps()
|
||||||
|
{
|
||||||
|
const fps = document.getElementById('fps')
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
if (now > lastFpsDisplayed + 800)
|
||||||
|
{
|
||||||
|
fps.innerText = Math.round(lastFpsArr.reduce((a, b) => a + b, 0) / lastFpsArr.length) + ' fps';
|
||||||
|
lastFpsDisplayed = now;
|
||||||
|
lastFpsArr = [];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lastFpsArr.push(Math.floor(1000 / (now - lastFpsTime)));
|
||||||
|
lastFpsTime = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { MultiOnlineGamePage, player, opponent, ball, map};
|
export { MultiOnlineGamePage, player, opponent, ball, map};
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/15 12:00:01 by edbernar #+# #+# */
|
/* Created: 2024/09/15 12:00:01 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/28 21:33:31 by edbernar ### ########.fr */
|
/* Updated: 2024/09/29 00:22:13 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -37,6 +37,8 @@ function typeGame(content)
|
|||||||
map.activeJumper(content.name);
|
map.activeJumper(content.name);
|
||||||
else if (content.action == 9)
|
else if (content.action == 9)
|
||||||
MultiOnlineGamePage.ping();
|
MultiOnlineGamePage.ping();
|
||||||
|
else if (content.action == 10)
|
||||||
|
MultiOnlineGamePage.endGame(content.won)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/20 11:23:41 by edbernar #+# #+# */
|
/* Created: 2024/08/20 11:23:41 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/28 21:38:24 by edbernar ### ########.fr */
|
/* Updated: 2024/09/29 01:11:55 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -193,14 +193,60 @@ body {
|
|||||||
|
|
||||||
.pingDiv {
|
.pingDiv {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 100px;
|
left: 10px;
|
||||||
left: 100px;
|
top: 10px;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
color: white;
|
color: white;
|
||||||
z-index: 800;
|
z-index: 800;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
background-color: rgba(0, 0, 0, 0.329);
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
touch-action: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ping {
|
#ping {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
color: white;
|
color: white;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.123);
|
||||||
|
padding: 5px 10px 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#fps {
|
||||||
|
padding: 5px 10px 5px 10px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.123);
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endGameDiv {
|
||||||
|
display: none;
|
||||||
|
flex-direction: column;
|
||||||
|
position: absolute;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
background-color: rgba(0, 0, 0, 0.9);
|
||||||
|
backdrop-filter: blur(5px);
|
||||||
|
z-index: 900;
|
||||||
|
transition: all 0.5s;
|
||||||
|
animation: fadeOutGames 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endGameText {
|
||||||
|
font-size: 100px;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endGameScore {
|
||||||
|
font-size: 75px;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endGameSimpleText {
|
||||||
|
font-size: 25px;
|
||||||
|
color: white;
|
||||||
|
margin-top: 50px;
|
||||||
}
|
}
|
Reference in New Issue
Block a user