-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bae451f
commit 96883b0
Showing
6 changed files
with
333 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from ursinanetworking import * | ||
from ursina import * | ||
from car import CarRepresentation | ||
|
||
class Multiplayer(Entity): | ||
def __init__(self, car): | ||
self.car = car | ||
|
||
self.client = UrsinaNetworkingClient(self.car.ip.text, 25565) | ||
self.easy = EasyUrsinaNetworkingClient(self.client) | ||
|
||
self.players = {} | ||
self.players_target_pos = {} | ||
self.players_target_rot = {} | ||
|
||
self.selfId = -1 | ||
|
||
@self.client.event | ||
def GetId(id): | ||
self.selfId = id | ||
print(f"My ID is : {self.selfId}") | ||
|
||
@self.easy.event | ||
def onReplicatedVariableCreated(variable): | ||
variable_name = variable.name | ||
variable_type = variable.content["type"] | ||
|
||
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[variable_name] = CarRepresentation((-80, -30, 15), (0, 90, 0)) | ||
|
||
if self.selfId == int(variable.content["id"]): | ||
self.players[variable_name].color = color.red | ||
self.players[variable_name].visible = False | ||
|
||
@self.easy.event | ||
def onReplicatedVariableUpdated(variable): | ||
self.players_target_pos[variable.name] = variable.content["position"] | ||
self.players_target_rot[variable.name] = variable.content["rotation"] | ||
|
||
@self.easy.event | ||
def onReplicatedVariableRemoved(variable): | ||
variable_name = variable.name | ||
variable_type = variable.content["type"] | ||
|
||
if variable_type == "player": | ||
destroy(self.players[variable_name]) | ||
del self.players[variable_name] | ||
|
||
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.easy.process_net_events() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters