diff --git a/README.md b/README.md index bbd37ca..06ae413 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ A Garage where you can change the colour of the car Multiplayer -So far I have been working on this game for a month. Feel free to leave comments or feedback on how I can improve the game +Feel free to leave comments or feedback on how I can improve the game # Installation diff --git a/main.py b/main.py index bd68592..069390e 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ from tracks.grass_track import GrassTrack from tracks.snow_track import SnowTrack -# application.development_mode = False +application.development_mode = False app = Ursina() window.borderless = False @@ -70,5 +70,6 @@ def input(key): if car.multiplayer_update: multiplayer.client.send_message("MyPosition", tuple(multiplayer.car.position)) multiplayer.client.send_message("MyRotation", tuple(multiplayer.car.rotation)) + multiplayer.client.send_message("MyTexture", str(multiplayer.car.texture)) app.run() \ No newline at end of file diff --git a/multiplayer.py b/multiplayer.py index 0b9b15f..774db12 100644 --- a/multiplayer.py +++ b/multiplayer.py @@ -12,6 +12,7 @@ def __init__(self, car): self.players = {} self.players_target_pos = {} self.players_target_rot = {} + self.players_target_tex = {} self.selfId = -1 @@ -28,6 +29,7 @@ def onReplicatedVariableCreated(variable): if variable_type == "player": self.players_target_pos[variable_name] = Vec3(-80, -30, 15) self.players_target_rot[variable_name] = Vec3(0, 90, 0) + self.players_target_tex[variable_name] = "./assets/garage/car-red.png" self.players[variable_name] = CarRepresentation((-80, -30, 15), (0, 90, 0)) if self.selfId == int(variable.content["id"]): @@ -38,6 +40,7 @@ def onReplicatedVariableCreated(variable): def onReplicatedVariableUpdated(variable): self.players_target_pos[variable.name] = variable.content["position"] self.players_target_rot[variable.name] = variable.content["rotation"] + self.players_target_tex[variable.name] = variable.content["texture"] @self.easy.event def onReplicatedVariableRemoved(variable): @@ -52,5 +55,6 @@ def update_multiplayer(self): for p in self.players: self.players[p].position += (Vec3(self.players_target_pos[p]) - self.players[p].position) / 25 self.players[p].rotation += (Vec3(self.players_target_rot[p]) - self.players[p].rotation) / 25 + self.players[p].texture = f"{self.players_target_tex[p]}" self.easy.process_net_events() \ No newline at end of file diff --git a/server.py b/server.py index 3fdc772..3fbbf42 100644 --- a/server.py +++ b/server.py @@ -13,7 +13,7 @@ def onClientConnected(client): easy.create_replicated_variable( f"player_{client.id}", - { "type" : "player", "id" : client.id, "position": (0, 0, 0), "rotation" : (0, 0, 0)} + { "type" : "player", "id" : client.id, "position": (0, 0, 0), "rotation" : (0, 0, 0), "texture" : "car-red.png"} ) print(f"{client} connected!") client.send_message("GetId", client.id) @@ -30,5 +30,9 @@ def MyPosition(client, newpos): def MyRotation(client, newrot): easy.update_replicated_variable_by_name(f"player_{client.id}", "rotation", newrot) +@server.event +def MyTexture(client, newtex): + easy.update_replicated_variable_by_name(f"player_{client.id}", "texture", newtex) + while True: easy.process_net_events() \ No newline at end of file