Game
- add rollback when user pos is not sync with serv - move player when player is out of bound
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
|
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/10/15 21:12:25 by edbernar ### ########.fr */
|
/* Updated: 2024/10/22 16:14:43 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -110,6 +110,11 @@ class Player
|
|||||||
showGamePad();
|
showGamePad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
movePlayer(content)
|
||||||
|
{
|
||||||
|
this.object.position.x = content.pos;
|
||||||
|
}
|
||||||
|
|
||||||
dispose()
|
dispose()
|
||||||
{
|
{
|
||||||
playerExist = false;
|
playerExist = false;
|
||||||
@ -371,12 +376,16 @@ class Player
|
|||||||
this.object.position.x += this.speed * this.deltaTime;
|
this.object.position.x += this.speed * this.deltaTime;
|
||||||
if (!this.cameraFixed && !isOnPointAnim)
|
if (!this.cameraFixed && !isOnPointAnim)
|
||||||
this.camera.position.x += this.speed * this.deltaTime;
|
this.camera.position.x += this.speed * this.deltaTime;
|
||||||
|
if (this.object.position.x > this.limits.right)
|
||||||
|
this.object.position.x = this.limits.right;
|
||||||
}
|
}
|
||||||
if (pressedButton[i] == key.left && this.object.position.x > this.limits.left)
|
if (pressedButton[i] == key.left && this.object.position.x > this.limits.left)
|
||||||
{
|
{
|
||||||
this.object.position.x -= this.speed * this.deltaTime;
|
this.object.position.x -= this.speed * this.deltaTime;
|
||||||
if (!this.cameraFixed && !isOnPointAnim)
|
if (!this.cameraFixed && !isOnPointAnim)
|
||||||
this.camera.position.x -= this.speed * this.deltaTime;
|
this.camera.position.x -= this.speed * this.deltaTime;
|
||||||
|
if (this.object.position.x < this.limits.left)
|
||||||
|
this.object.position.x = this.limits.left;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/15 12:00:01 by edbernar #+# #+# */
|
/* Created: 2024/09/15 12:00:01 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/10/10 13:51:15 by edbernar ### ########.fr */
|
/* Updated: 2024/10/22 16:05:38 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -28,6 +28,8 @@ function typeGame(content)
|
|||||||
{
|
{
|
||||||
if (content.action == 3 && content.is_opponent)
|
if (content.action == 3 && content.is_opponent)
|
||||||
opponent.movePlayer(content);
|
opponent.movePlayer(content);
|
||||||
|
else if (content.action == 3 && !content.is_opponent)
|
||||||
|
player.movePlayer(content);
|
||||||
else if (content.action == 4)
|
else if (content.action == 4)
|
||||||
player.scalePlayer(content.is_opponent);
|
player.scalePlayer(content.is_opponent);
|
||||||
else if (content.action == 5 && ball)
|
else if (content.action == 5 && ball)
|
||||||
|
Reference in New Issue
Block a user