Ok, so i need a little bit of advice and help, im making a 2d Multiplayer FPS (first person shooter) game using pygame, threading and sockets (ill convert it to websockets later dw). and each client has a player class and the player has a list/dict of bullets the player shot then it sends it to the server
##################### CLIENT SIDE #####################
r.clear() # r is a mutable data type aka list (its the only way to return values from threaded functions)
b = []
for bu in theply.bullets:
bl = theply.bullets[bu]
b.append({
"id":str(bl.id),
"x":float(bl.x),
"y":float(bl.y),
"x_vel":float(bl.x_vel),
"y_vel":float(bl.y_vel),
"angle":float(bl.angle),
})
req = {
"id":str(theply.id),
"color":theply.color,
"name":str(theply.name),
"x":float(theply.x),
"y":float(theply.y),
"reload_": int(theply.reload_),
"bullets": b
}
r.append(send(req)) # return and sends the msg to the server, the func send returns values from the server and my code later takes r[0] as return value of the threaded func
And the Server takes the player and send all game objects back:-
##################### SERVER SIDE #####################
def R(msg):
if msg == "reset":
GAME.clear()
GAME["players"] = dict()
return True
else:
b = dict()
for i in msg["bullets"]:
b[i["id"]] = {
"x":i["x"],
"y":i["y"],
"x_vel":i["x_vel"],
"y_vel":i["y_vel"],
"angle":i["angle"]
}
GAME["players"][msg["id"]] = {
"color":msg["color"],
"name":msg["name"],
"x":msg["x"],
"y":msg["y"],
"reload_":msg["reload_"],
"bullets":b,
}
return GAME
Also both the player and bullets have their own Pygame Rectangles, so where should i check the bullet collision? using these -
pygame.Rect.colliderect
# OR
pygame.Rect.collidelist
- a) the player checks all the other player bullets if they have hit it
- b) the player who shoots the bullets, checks if his bullets have hit others
- c) do the colision server side (not possible bcs the pygame lib cant check colision without window)
- d) whatever you guys suggest