add ball move request to client
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/17 12:53:12 by tomoron ### ########.fr #
|
# Updated: 2024/09/17 14:44:29 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -17,6 +17,14 @@ import asyncio
|
|||||||
class Game:
|
class Game:
|
||||||
waitingForPlayerLock = False
|
waitingForPlayerLock = False
|
||||||
waitingForPlayer = None
|
waitingForPlayer = None
|
||||||
|
limits = {
|
||||||
|
left = -3
|
||||||
|
right = 3
|
||||||
|
back = -6.5
|
||||||
|
front = 6.5
|
||||||
|
|
||||||
|
}
|
||||||
|
StartSpeed = 0.5
|
||||||
def __init__(self, socket, withBot):
|
def __init__(self, socket, withBot):
|
||||||
self.p1 = None
|
self.p1 = None
|
||||||
self.p2 = None
|
self.p2 = None
|
||||||
@ -27,10 +35,12 @@ class Game:
|
|||||||
self.playerLeft = False
|
self.playerLeft = False
|
||||||
self.end = False
|
self.end = False
|
||||||
|
|
||||||
self.player1Pos = {"pos":0, "up": False)
|
self.p1Pos = {"pos":0, "up": False}
|
||||||
self.player1Pos = {"pos":0, "up": False)
|
self.p1Pos = {"pos":0, "up": False}
|
||||||
|
|
||||||
self.ballPos = {"pos":(0, 0), "up", False)
|
self.ballPos = {"pos":(0, 0), "up": False}
|
||||||
|
self.speed = Game.startSpeed
|
||||||
|
self.ballVel = (0, self.speed)
|
||||||
|
|
||||||
if(withBot):
|
if(withBot):
|
||||||
self.join(socket)
|
self.join(socket)
|
||||||
@ -81,9 +91,9 @@ class Game:
|
|||||||
self.p2 = None
|
self.p2 = None
|
||||||
self.p2Ready =False
|
self.p2Ready =False
|
||||||
if(self.p1 != None):
|
if(self.p1 != None):
|
||||||
self.p2.sync_send({"type":"game","content":{"action":4}})
|
|
||||||
if(self.p2 != None):
|
|
||||||
self.p1.sync_send({"type":"game","content":{"action":4}})
|
self.p1.sync_send({"type":"game","content":{"action":4}})
|
||||||
|
if(self.p2 != None):
|
||||||
|
self.p2.sync_send({"type":"game","content":{"action":4}})
|
||||||
if(not self.started):
|
if(not self.started):
|
||||||
while(Game.waitingForPlayerLock):
|
while(Game.waitingForPlayerLock):
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
@ -102,11 +112,20 @@ 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
|
||||||
|
if(socket == self.p1):
|
||||||
|
self.p1Pos["pos"] = pos
|
||||||
|
self.p1Pos["up"] = up;
|
||||||
|
else:
|
||||||
|
self.p2Pos["pos"] = -pos;
|
||||||
|
self.p2Pos["up"] = up
|
||||||
|
if(opponent != None):
|
||||||
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
|
||||||
self.sendPlayers({"action":2})
|
self.sendPlayers({"action":2})
|
||||||
|
self.ballPos = {"pos":(0, 0), "up": False}
|
||||||
|
self.sendPlayers({"action":5, "pos" : [self.ballPos["pos"][0],self.ballPos["pos"][1]], "velocity":[self.velocrity[0], self.velocity[1]]})
|
||||||
while(not self.end):
|
while(not self.end):
|
||||||
print("AAAAAAAAAAAAAAAAAAA")
|
print("AAAAAAAAAAAAAAAAAAA")
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/09/09 16:10:26 by tomoron #+# #+# #
|
# Created: 2024/09/09 16:10:26 by tomoron #+# #+# #
|
||||||
# Updated: 2024/09/16 16:31:10 by tomoron ### ########.fr #
|
# Updated: 2024/09/17 14:44:01 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -32,6 +32,10 @@ from .gameActions.move import move
|
|||||||
# - up
|
# - up
|
||||||
#
|
#
|
||||||
# 4 : leave : when the opponent left the game
|
# 4 : leave : when the opponent left the game
|
||||||
|
#
|
||||||
|
# 5 : ball_move : send new directtion/movement to the client
|
||||||
|
# - pos : [x, z]
|
||||||
|
# - velocity : [x, z]
|
||||||
|
|
||||||
#client actions (actions sent by the client) :
|
#client actions (actions sent by the client) :
|
||||||
# 0 : start : starts a game
|
# 0 : start : starts a game
|
||||||
|
Reference in New Issue
Block a user