- multiplayer move
This commit is contained in:
Kum1ta
2024-09-16 15:52:38 +02:00
parent cbf665b837
commit 12b33d0ee4
5 changed files with 67 additions and 13 deletions

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/21 10:34:49 by edbernar #+# #+# */
/* Updated: 2024/09/15 14:56:35 by edbernar ### ########.fr */
/* Updated: 2024/09/16 15:51:15 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,10 +15,15 @@ let opponentExist = false;
class Opponent
{
object = null;
speed = 0.1;
speed = 4;
interval = null;
limits = {};
player = null;
limits = {
up : 3,
down: 0.3,
left: -3,
right: 3,
};
last = false;
constructor (object, map)
{
@ -26,7 +31,6 @@ class Opponent
throw Error("Opponent is already init.");
opponentExist = true;
this.object = object;
this.limits = map.limits;
this.object.position.set(0, 0.3, -map.mapLength / 2 + 0.2);
}
@ -37,7 +41,40 @@ class Opponent
update()
{
//en attente du serveur
console.log(this.object.position);
}
movePlayer(content)
{
const thisClass = this;
this.object.position.x = content.pos;
if (content.up && thisClass.object.position.y < thisClass.limits.up)
{
if (this.interval)
clearInterval(this.interval);
thisClass.interval = setInterval(() => {
thisClass.object.position.y += thisClass.speed / 40;
if (thisClass.object.position.y >= thisClass.limits.up)
{
clearInterval(thisClass.interval);
thisClass.interval = null;
}
}, 5);
}
else if (!content.up && thisClass.object.position.y > thisClass.limits.down)
{
if (this.interval)
clearInterval(this.interval);
this.interval = setInterval(() => {
thisClass.object.position.y -= thisClass.speed / 40;
if (thisClass.object.position.y <= thisClass.limits.down)
{
clearInterval(thisClass.interval);
thisClass.interval = null;
thisClass.object.position.y = thisClass.limits.down;
}
}, 5);
}
}
}