- add action 8 for jumper
This commit is contained in:
Kum1ta
2024-09-25 14:00:11 +02:00
parent 799b298625
commit 8b8f23d693
3 changed files with 16 additions and 61 deletions

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 17:02:47 by edbernar #+# #+# */
/* Updated: 2024/09/22 17:49:04 by edbernar ### ########.fr */
/* Updated: 2024/09/25 13:47:32 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -71,7 +71,7 @@ class Ball
this.object.position.set(x, y, z);
}
changeGravity(ballIsOnJumper)
changeGravity()
{
let diffTop = this.limits.up - this.object.position.y;
let diffBot = this.object.position.y - this.limits.down;
@ -93,40 +93,11 @@ class Ball
this.setPosition(this.object.position.x, this.limits.up, this.object.position.z);
else
this.setPosition(this.object.position.x, this.limits.down, this.object.position.z);
ballIsOnJumper.can = true;
}
speed -= speed * slower;
}, 10);
}
/*---------------- FUNCTION FOR TEST ----------------*/
initMoveBallTmp()
{
console.warn("Don't forget to remove function initMoveBallTmp");
const speedBallTmp = 0.1;
let warn = false;
document.addEventListener('keypress', (e) => {
if (!this.object && !warn)
{
console.warn("EventListener in initMoveBallTmp() is still here");
warn = true;
return ;
}
if (e.key == '4')
this.object.position.x -= speedBallTmp;
if (e.key == '6')
this.object.position.x += speedBallTmp;
if (e.key == '8')
this.object.position.z -= speedBallTmp;
if (e.key == '2')
this.object.position.z += speedBallTmp;
if (e.key == '9')
this.changeGravity();
});
}
/*---------------------------------------------------*/
updatePos(content)
{
// {action: 5, pos: [ball.object.position.x, ball.object.position.z], velocity: [ball.object.velocity.x, ball.object.velocity.z]}

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
/* Updated: 2024/09/23 13:44:57 by edbernar ### ########.fr */
/* Updated: 2024/09/25 13:58:28 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -79,9 +79,6 @@ class Map
left: -3,
right: 3,
};
ballIsOnJumper = {
can: true
};
dispose()
{
@ -831,7 +828,6 @@ class Map
listObject = listObject.content;
for (let i = 0; i < listObject.length; i++ )
{
console.log(listObject[i]);
if (listObject[i].type == 1)
{
this.#createGravityChanger(listObject[i].pos.x, listObject[i].pos.y, listObject[i].pos.z, "gravityChanger" + i, listObject[i].isUp ? "jumperTop" : "jumperBottom", listObject[i].isUp);
@ -842,6 +838,16 @@ class Map
}
}
activeJumper(index)
{
ball.changeGravity();
if (listObject[index].isUp)
this.#animationGravityChanger(this.arrObject[index].mesh, true);
else
this.#animationGravityChanger(this.arrObject[index].mesh, false);
}
#generateObstacle()
{
const wallPos = [
@ -916,18 +922,6 @@ class Map
}
if (this.arrObject[i].type == 'jumperBottom')
{
const cylinder = this.arrObject[i].mesh.children[5];
const distance = ball.object.position.distanceTo(cylinder.position);
const speed = 0.1;
// Detect if the ball is on the jumper
if (distance < 0.25 && this.ballIsOnJumper.can)
{
this.ballIsOnJumper.can = false;
ball.changeGravity(this.ballIsOnJumper);
this.#animationGravityChanger(this.arrObject[i].mesh, false);
}
// Gravity changer animation
for (let j = 0; j < 3; j++)
{
@ -937,18 +931,6 @@ class Map
}
else if (this.arrObject[i].type == 'jumperTop')
{
const cylinder = this.arrObject[i].mesh.children[5];
const distance = ball.object.position.distanceTo(cylinder.position);
const speed = 0.1;
// Detect if the ball is on the jumper
if (distance < 0.4 && this.ballIsOnJumper.can)
{
this.ballIsOnJumper.can = false;
ball.changeGravity(this.ballIsOnJumper);
this.#animationGravityChanger(this.arrObject[i].mesh, true);
}
// Gravity changer animation
for (let j = 0; j < 3; j++)
{

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/15 12:00:01 by edbernar #+# #+# */
/* Updated: 2024/09/21 22:52:13 by edbernar ### ########.fr */
/* Updated: 2024/09/25 13:38:28 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,6 +31,8 @@ function typeGame(content)
player.makeAnimation(content.is_opponent);
else if (content.action == 7 && pageRenderer.actualPage == MultiOnlineGamePage)
map.placeObject(content);
else if (content.action == 8 && pageRenderer.actualPage == MultiOnlineGamePage)
map.activeJumper(content.index);
}
export { typeGame };