Game solo - End game process

This commit is contained in:
hubourge
2024-09-11 16:13:28 +02:00
parent 9920af659e
commit 6ad400b70c
3 changed files with 45 additions and 13 deletions

View File

@ -6,22 +6,23 @@
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/28 12:07:39 by edbernar #+# #+# */
/* Updated: 2024/09/10 17:16:02 by hubourge ### ########.fr */
/* Updated: 2024/09/11 16:12:16 by hubourge ### ########.fr */
/* */
/* ************************************************************************** */
import * as THREE from 'three';
import { Map, ground } from './soloClass/Map.js'
import { Map, ground, gameEndStatus } from './soloClass/Map.js'
import { Players, player1, player2 } from './soloClass/Players.js'
import { Ball } from './soloClass/Ball.js'
import { stats } from './MultiGame.js';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
let scene = null;
let scene = null;
let renderer = null;
let camera = null;
let controls = null;
let controls = null;
let gameEnd = false;
/*
Controls :
@ -93,6 +94,8 @@ class SoloGame
function loop()
{
stats.begin();
if (gameEndStatus) // fin du jeu faire les dispose en conséquence
console.log('Game end');
controls.update();
Ball.update();
Map.update();

View File

@ -6,7 +6,7 @@
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/28 12:23:48 by edbernar #+# #+# */
/* Updated: 2024/09/10 18:13:14 by hubourge ### ########.fr */
/* Updated: 2024/09/11 16:10:26 by hubourge ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,7 +36,7 @@ let score = {player1: 0, player2: 0};
let onUpdate = false;
const scoreElement = document.getElementById('score');
let initialSpeed = 3;
let gameEndStatus = false;
class Map
{
@ -262,10 +262,13 @@ class Map
if (player1Lose)
score.player2++;
else
score.player1++;
scoreElement.innerHTML = score.player1 + '-' +score.player2;
score.player1++;
scoreElement.innerHTML = score.player1 + '-' +score.player2;
}, 500);
if ((player1Lose && score.player2 >= 2) || (!player1Lose && score.player1 >= 2))
return (this.#endGame());
setTimeout(() => {
speed = 3;
initialSpeed = Math.sqrt(vec3.x * vec3.x + vec3.z * vec3.z);
@ -314,6 +317,32 @@ class Map
else if (typeof(texture) == 'number')
ground.material.color.set(texture);
}
static #endGame()
{
speed = 3;
vec3.x = 0;
vec3.y = 0;
vec3.z = 0
initialZ = vec3.z;
setTimeout(() => {
ballBody.velocity.set(0,0,0);
ballBody.position.set(0, 0.15, 0);
ball.position.copy(ballBody.position);
ball.material.opacity = 1;
player1Body.position.set(-12, 0.4, 0);
player1.position.copy(player1Body.position);
player2Body.position.set(12, 0.4, 0);
player2.position.copy(player2Body.position);
scoreElement.style.animation = 'fadeOut 0.199s';
document.getElementsByTagName('canvas')[3].style.filter = 'brightness(1)';
scoreElement.style.animation = 'fadeOutText 0.399s';
scoreElement.style.color = 'rgb(255, 255, 255, 0.1)';
onUpdate = false;
gameEndStatus = true;
}, 1200);
}
}
function createGround(scene, texture)
@ -348,4 +377,4 @@ function createWall(onTop)
return (mesh);
}
export { Map, wallBottom, wallTop, ground };
export { Map, wallBottom, wallTop, ground, gameEndStatus };

View File

@ -3,15 +3,15 @@
/* ::: :::::::: */
/* main.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/28 12:05:53 by edbernar #+# #+# */
/* Updated: 2024/09/09 13:07:00 by edbernar ### ########.fr */
/* Updated: 2024/09/11 15:18:08 by hubourge ### ########.fr */
/* */
/* ************************************************************************** */
import { MultiGame } from "./class/MultiGame";
import { SoloGame } from "./class/SoloGame";
MultiGame.create();
// SoloGame.create();
// MultiGame.create();
SoloGame.create();