Game solo - End game process
This commit is contained in:
@ -6,22 +6,23 @@
|
|||||||
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/28 12:07:39 by edbernar #+# #+# */
|
/* 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 * 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 { Players, player1, player2 } from './soloClass/Players.js'
|
||||||
import { Ball } from './soloClass/Ball.js'
|
import { Ball } from './soloClass/Ball.js'
|
||||||
|
|
||||||
import { stats } from './MultiGame.js';
|
import { stats } from './MultiGame.js';
|
||||||
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
||||||
|
|
||||||
let scene = null;
|
let scene = null;
|
||||||
let renderer = null;
|
let renderer = null;
|
||||||
let camera = null;
|
let camera = null;
|
||||||
let controls = null;
|
let controls = null;
|
||||||
|
let gameEnd = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Controls :
|
Controls :
|
||||||
@ -93,6 +94,8 @@ class SoloGame
|
|||||||
function loop()
|
function loop()
|
||||||
{
|
{
|
||||||
stats.begin();
|
stats.begin();
|
||||||
|
if (gameEndStatus) // fin du jeu faire les dispose en conséquence
|
||||||
|
console.log('Game end');
|
||||||
controls.update();
|
controls.update();
|
||||||
Ball.update();
|
Ball.update();
|
||||||
Map.update();
|
Map.update();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/28 12:23:48 by edbernar #+# #+# */
|
/* 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;
|
let onUpdate = false;
|
||||||
const scoreElement = document.getElementById('score');
|
const scoreElement = document.getElementById('score');
|
||||||
let initialSpeed = 3;
|
let initialSpeed = 3;
|
||||||
|
let gameEndStatus = false;
|
||||||
|
|
||||||
class Map
|
class Map
|
||||||
{
|
{
|
||||||
@ -262,10 +262,13 @@ class Map
|
|||||||
if (player1Lose)
|
if (player1Lose)
|
||||||
score.player2++;
|
score.player2++;
|
||||||
else
|
else
|
||||||
score.player1++;
|
score.player1++;
|
||||||
scoreElement.innerHTML = score.player1 + '-' +score.player2;
|
scoreElement.innerHTML = score.player1 + '-' +score.player2;
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
if ((player1Lose && score.player2 >= 2) || (!player1Lose && score.player1 >= 2))
|
||||||
|
return (this.#endGame());
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
speed = 3;
|
speed = 3;
|
||||||
initialSpeed = Math.sqrt(vec3.x * vec3.x + vec3.z * vec3.z);
|
initialSpeed = Math.sqrt(vec3.x * vec3.x + vec3.z * vec3.z);
|
||||||
@ -314,6 +317,32 @@ class Map
|
|||||||
else if (typeof(texture) == 'number')
|
else if (typeof(texture) == 'number')
|
||||||
ground.material.color.set(texture);
|
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)
|
function createGround(scene, texture)
|
||||||
@ -348,4 +377,4 @@ function createWall(onTop)
|
|||||||
return (mesh);
|
return (mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Map, wallBottom, wallTop, ground };
|
export { Map, wallBottom, wallTop, ground, gameEndStatus };
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* main.js :+: :+: :+: */
|
/* main.js :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/28 12:05:53 by edbernar #+# #+# */
|
/* 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 { MultiGame } from "./class/MultiGame";
|
||||||
import { SoloGame } from "./class/SoloGame";
|
import { SoloGame } from "./class/SoloGame";
|
||||||
|
|
||||||
MultiGame.create();
|
// MultiGame.create();
|
||||||
// SoloGame.create();
|
SoloGame.create();
|
||||||
|
Reference in New Issue
Block a user