Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import bge
  2. import bpy, sys
  3. from threading import Timer
  4.  
  5. # This is the absolute path to the initialization module.
  6. folderpath = bpy.path.abspath("//../4_server/")
  7. filepath = folderpath + "client.py"
  8.  
  9. # Append the folder so all scripts are readable within that folder.
  10. sys.path.append( folderpath )
  11.  
  12. # Finally execute the init file
  13. exec(compile(open(filepath).read(), filepath, 'exec'))
  14.  
  15. ##
  16. # @def main()
  17. ##
  18. def main():
  19. controller = bge.logic.getCurrentController()
  20. scene = bge.logic.getCurrentScene()
  21.  
  22. owner = controller.owner
  23.  
  24. owner['_client'] = Client()
  25.  
  26. def _spawnPlayer(address, playerNumber, tracker):
  27. spawnLocation = 'Spawner' + str(playerNumber)
  28. print("Player Number:", playerNumber, "has been spawned on:", spawnLocation )
  29.  
  30. player = scene.addObject('Player', spawnLocation)
  31. player['_client'] = owner['_client']
  32.  
  33. #TEST
  34. _onJoinHandled( (), { 'ID': -1, 'PlayerNumber': 4}, () );
  35.  
  36. def _onLocationUpdate( address, data, location, tracker ):
  37. controller = bge.logic.getCurrentController()
  38. owner = controller.owner
  39.  
  40. player.position.x = location['x']
  41. player.position.y = location['y']
  42. player.position.z = location['z']
  43.  
  44. def _onJoinHandled( address, data, tracker ):
  45. spawnLocation = 'Spawner' + str(data['PlayerNumber'])
  46. print( address, 'with ID:', data['ID'], 'and Player Number:', data['PlayerNumber'], 'has joined your game and has spawned on:', spawnLocation)
  47. enemy = scene.addObject('Enemy', spawnLocation)
  48.  
  49. owner['_client'].On( Client.LISTEN_EVENT_ON_JOIN_HANDLED, _onJoinHandled, -1)
  50. owner['_client'].On( Client.LISTEN_EVENT_ON_LOCATION_UPDATE, _onLocationUpdate, -1)
  51. owner['_client'].On( Client.LISTEN_EVENT_ON_ASSIGN_PLAYER_PLAYER_NUMBER, _spawnPlayer, 1)
  52.  
  53. owner['_client'].Start()
  54.  
  55. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement