laneya

multiplayer roguelike game
git clone https://git.ce9e.org/laneya.git

commit
5eab349dc3be9901181021a0a2487a39a87cee27
parent
31eb52a482d14cc1299f20f2d2b1b1fd0fdb9ee5
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-10-05 10:06
Basic move implementation in server

Diffstat

M laneya/server.py 23 ++++++++++++++++++++++-

1 files changed, 22 insertions, 1 deletions


diff --git a/laneya/server.py b/laneya/server.py

@@ -12,6 +12,9 @@ class ServerProtocol(protocol.ServerProtocol):
   12    12     def requestReceived(self, user, action, **kwargs):  # TODO
   13    13         if action == 'echo':
   14    14             return kwargs
   -1    15         elif action == 'move':
   -1    16             self.factory.direction = kwargs['direction']
   -1    17             return {}
   15    18         else:
   16    19             self.broadcastUpdate(action, **kwargs)
   17    20             reactor.callLater(5, self.broadcastUpdate, action, **kwargs)
@@ -22,8 +25,26 @@ class Server(protocol.ServerProtocolFactory):
   22    25     def __init__(self):
   23    26         protocol.ServerProtocolFactory.__init__(self, ServerProtocol)
   24    27 
   -1    28         # TODO: should be set per user
   -1    29         self.direction = 'stop'
   -1    30         self.position_x = 0
   -1    31         self.position_y = 0
   -1    32 
   25    33     def mainloop(self):
   26    -1         self.broadcastUpdate('echo', foo='mainloop')
   -1    34         if self.direction == 'north':
   -1    35             self.position_y -= 1
   -1    36         elif self.direction == 'east':
   -1    37             self.position_x += 1
   -1    38         elif self.direction == 'south':
   -1    39             self.position_y += 1
   -1    40         elif self.direction == 'west':
   -1    41             self.position_x -= 1
   -1    42         if self.direction != 'stop':
   -1    43             self.broadcastUpdate(
   -1    44                 'position',
   -1    45                 x=self.position_x,
   -1    46                 y=self.position_y,
   -1    47                 entity='example')
   27    48 
   28    49 
   29    50 def main():