Site
- Add smoothing movement for opponent Django - invert pos in move request
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
|
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
|
||||||
# Updated: 2024/09/16 14:28:57 by tomoron ### ########.fr #
|
# Updated: 2024/09/17 00:07:47 by edbernar ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ class Game:
|
|||||||
|
|
||||||
def move(self, socket, pos, up):
|
def move(self, socket, pos, up):
|
||||||
opponent = self.p1 if socket != self.p1 else self.p2
|
opponent = self.p1 if socket != self.p1 else self.p2
|
||||||
opponent.sync_send({"type":"game","content":{"action":3, "pos":pos, "up":up, "is_opponent":True}})
|
opponent.sync_send({"type":"game","content":{"action":3, "pos":-pos, "up":up, "is_opponent":True}})
|
||||||
|
|
||||||
async def gameLoop(self):
|
async def gameLoop(self):
|
||||||
self.started = True
|
self.started = True
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/21 10:34:49 by edbernar #+# #+# */
|
/* Created: 2024/08/21 10:34:49 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/16 15:51:15 by edbernar ### ########.fr */
|
/* Updated: 2024/09/17 00:22:47 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ class Opponent
|
|||||||
object = null;
|
object = null;
|
||||||
speed = 4;
|
speed = 4;
|
||||||
interval = null;
|
interval = null;
|
||||||
|
interval2 = null;
|
||||||
limits = {
|
limits = {
|
||||||
up : 3,
|
up : 3,
|
||||||
down: 0.3,
|
down: 0.3,
|
||||||
@ -41,13 +42,26 @@ class Opponent
|
|||||||
|
|
||||||
update()
|
update()
|
||||||
{
|
{
|
||||||
console.log(this.object.position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
movePlayer(content)
|
movePlayer(content)
|
||||||
{
|
{
|
||||||
|
const lerp = (start, end, t) => start + (end - start) * t;
|
||||||
const thisClass = this;
|
const thisClass = this;
|
||||||
|
const speedFactor = 0.5;
|
||||||
|
|
||||||
|
if (thisClass.animationFrame)
|
||||||
|
cancelAnimationFrame(thisClass.animationFrame);
|
||||||
|
const animate = () => {
|
||||||
|
this.object.position.x = lerp(this.object.position.x, content.pos, speedFactor);
|
||||||
|
if (Math.abs(this.object.position.x - content.pos) < 0.01)
|
||||||
this.object.position.x = content.pos;
|
this.object.position.x = content.pos;
|
||||||
|
else
|
||||||
|
thisClass.animationFrame = requestAnimationFrame(animate);
|
||||||
|
};
|
||||||
|
|
||||||
|
thisClass.animationFrame = requestAnimationFrame(animate);
|
||||||
|
|
||||||
if (content.up && thisClass.object.position.y < thisClass.limits.up)
|
if (content.up && thisClass.object.position.y < thisClass.limits.up)
|
||||||
{
|
{
|
||||||
if (this.interval)
|
if (this.interval)
|
||||||
|
Reference in New Issue
Block a user