Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bge
- import bpy, sys
- from threading import Timer
- # This is the absolute path to the initialization module.
- folderpath = bpy.path.abspath("//../4_server/")
- filepath = folderpath + "client.py"
- # Append the folder so all scripts are readable within that folder.
- sys.path.append( folderpath )
- # Finally execute the init file
- exec(compile(open(filepath).read(), filepath, 'exec'))
- ##
- # @def main()
- ##
- def main():
- controller = bge.logic.getCurrentController()
- scene = bge.logic.getCurrentScene()
- owner = controller.owner
- owner['_client'] = Client()
- def _spawnPlayer(address, playerNumber, tracker):
- spawnLocation = 'Spawner' + str(playerNumber)
- print("Player Number:", playerNumber, "has been spawned on:", spawnLocation )
- player = scene.addObject('Player', spawnLocation)
- player['_client'] = owner['_client']
- #TEST
- _onJoinHandled( (), { 'ID': -1, 'PlayerNumber': 4}, () );
- def _onLocationUpdate( address, data, location, tracker ):
- controller = bge.logic.getCurrentController()
- owner = controller.owner
- player.position.x = location['x']
- player.position.y = location['y']
- player.position.z = location['z']
- def _onJoinHandled( address, data, tracker ):
- spawnLocation = 'Spawner' + str(data['PlayerNumber'])
- print( address, 'with ID:', data['ID'], 'and Player Number:', data['PlayerNumber'], 'has joined your game and has spawned on:', spawnLocation)
- enemy = scene.addObject('Enemy', spawnLocation)
- owner['_client'].On( Client.LISTEN_EVENT_ON_JOIN_HANDLED, _onJoinHandled, -1)
- owner['_client'].On( Client.LISTEN_EVENT_ON_LOCATION_UPDATE, _onLocationUpdate, -1)
- owner['_client'].On( Client.LISTEN_EVENT_ON_ASSIGN_PLAYER_PLAYER_NUMBER, _spawnPlayer, 1)
- owner['_client'].Start()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement