- ball trail change color with speed
    = add goal id for opponnent
This commit is contained in:
Kum1ta
2024-10-11 11:08:52 +02:00
parent 0b58783565
commit be60de564a
6 changed files with 33 additions and 22 deletions

View File

@ -3,10 +3,10 @@
# ::: :::::::: #
# DummySocket.py :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/08 07:33:29 by tomoron #+# #+# #
# Updated: 2024/10/10 19:25:49 by tomoron ### ########.fr #
# Updated: 2024/10/11 10:47:53 by edbernar ### ########.fr #
# #
# **************************************************************************** #

View File

@ -25,7 +25,7 @@ urlpatterns = [
path("multiOnlineGamePage", views.multiOnlineGamePage, name='multiOnlineGamePage'),
path("waitingGamePage", views.waitingGamePage, name='waitingGamePage'),
path("profilPage", views.profilPage, name='profilPage'),
# path("game", views.game, name='game'),
path("game", views.game, name='game'),
path("wait_game", views.game, name='wait_game'),
path("tournament", views.tournament, name='tournament'),
path("login42", views.login42, name='login42'),

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 17:02:47 by edbernar #+# #+# */
/* Updated: 2024/10/07 14:10:52 by edbernar ### ########.fr */
/* Updated: 2024/10/11 10:43:04 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -287,11 +287,9 @@ class Ball
this.updateTrail();
}
updateTrail()
{
updateTrail() {
const trailColors = trailGeometry.attributes.customColor.array;
for (let i = trailPositions.length - 3; i >= 3; i--)
trailPositions[i] = trailPositions[i - 3];
trailPositions[0] = this.object.position.x;
@ -300,19 +298,35 @@ class Ball
for (let i = 0; i < 33; i++)
trailSizes[i] = Math.max(0.5 * (1 - i / 33), 0.1);
const velocityMagnitude = Math.sqrt(
this.srvPos.vel[0] * this.srvPos.vel[0] +
this.srvPos.vel[1] * this.srvPos.vel[1]
);
// Normalisation de la vitesse entre 0 (lente) et 1 (rapide)
const speedFactor = Math.min(velocityMagnitude / 10, 1); // Divisé par 10 pour ajuster l'échelle
for (let i = 0; i < 33; i++) {
const alpha = Math.max(1 - i / 33, 0);
trailColors[i * 4] = 1.0 / Math.max(this.srvPos.vel[0] < 0 ? - this.srvPos.vel[0] : this.srvPos.vel[0], 0.3);
trailColors[i * 4 + 1] = 1.0 / Math.max(this.srvPos.vel[1] < 0 ? - this.srvPos.vel[1] : this.srvPos.vel[1], 0.3);
trailColors[i * 4 + 2] = 1.0 / Math.max((this.srvPos.vel[0] < 0 ? - this.srvPos.vel[0] : this.srvPos.vel[0]) + this.srvPos.vel[1] < 0 ? - this.srvPos.vel[1] : this.srvPos.vel[1], 0.3);
// Couleur entre blanc et rouge selon la vitesse
const r = 1; // Rouge maximum
const g = 1 - speedFactor; // Moins de vert avec l'augmentation de la vitesse
const b = 1 - speedFactor; // Moins de bleu avec l'augmentation de la vitesse
// Appliquer la couleur
trailColors[i * 4] = r;
trailColors[i * 4 + 1] = g;
trailColors[i * 4 + 2] = b;
trailColors[i * 4 + 3] = alpha;
}
// Marquer les attributs comme nécessitant une mise à jour
trailGeometry.attributes.position.needsUpdate = true;
trailGeometry.attributes.size.needsUpdate = true;
trailGeometry.attributes.customColor.needsUpdate = true;
}
dispose()
{

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
/* Updated: 2024/10/10 13:46:36 by edbernar ### ########.fr */
/* Updated: 2024/10/11 11:08:30 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -87,9 +87,7 @@ class Player
pressedButton = [];
console.log(layoutSelected);
key = {up: layoutSelected.US ? "w" : "z", down: "s", left: layoutSelected.US ? "a" : "q", right: "d"};
console.warn("Remettre opponentGoal = availableGoals[goalIdOppenent] qaund le serveur le permettra");
this.opponentGoal = availableGoals[0];
// opponentGoal = availableGoals[goalIdOppenent];
this.opponentGoal = availableGoals[goalIdOppenent];
this.object = object;
this.limits = map.playerLimits;
this.camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 10000);
@ -266,8 +264,6 @@ class Player
tmpCamera.fov -= 0.05;
tmpCamera.updateProjectionMatrix();
}, 10);
console.log("Oppenent : " + this.opponentGoal);
setTimeout(() => {
map.animationGoal(this.opponent.object.position.x, this.opponent.object.position.y, this.opponent.object.position.z, this.opponent.playerGoalAnimation, this.opponentGoal);
}, 1000);

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/10/10 13:47:22 by edbernar ### ########.fr */
/* Updated: 2024/10/11 10:56:51 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -86,6 +86,7 @@ class MultiOnlineGamePage
{
static create(skin)
{
console.log('skin', skin);
if (!skin)
{
skin = {player: 4, opponent: 0};
@ -108,7 +109,7 @@ class MultiOnlineGamePage
vrMode();
opponent = new Opponent(bar2, map, Math.floor(Math.random() * 100 % 6));
player = new Player(bar1, map, opponent, Math.floor(Math.random() * 100 % 6), skin.goalId);
player = new Player(bar1, map, opponent, Math.floor(Math.random() * 100 % 6), skin.opponentGoaldId);
spotLight = new THREE.SpotLight(0xffffff, 10000, 0, 0.2);
spotLight.castShadow = true;
ambiantLight = new THREE.AmbientLight(0xffffff, 0.5);

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/14 21:20:45 by edbernar #+# #+# */
/* Updated: 2024/10/08 17:48:27 by edbernar ### ########.fr */
/* Updated: 2024/10/11 10:54:35 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -90,7 +90,7 @@ class WaitingGamePage
timeout = setTimeout(() => {
document.body.style.animation = 'anim3 0.5s';
document.body.style.opacity = 0;
pageRenderer.changePage("multiOnlineGamePage", false, {player: lastSelected ? lastSelected.id : 0, opponent: content.skin, opponentGoaldId: content.goalId, pfp: content.pfpSelf, pfpOpponent: content.pfpOpponent});
pageRenderer.changePage("multiOnlineGamePage", false, {player: lastSelected ? lastSelected.id : 0, opponent: content.skin, opponentGoaldId: content.goal, pfp: content.pfpSelf, pfpOpponent: content.pfpOpponent});
}, 1000);
}, 500);
document.body.removeChild(returnButton);