laneya

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

commit
8a77e649e671f43bd8929e6d716d5ee4112fcea1
parent
8e11884ec9d968e169948323744a943e879cdb94
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-08-03 09:16
gardening

Diffstat

M laneya/actions.py 2 +-
M laneya/client.py 32 ++++++++++++++++++--------------
M laneya/map.py 28 ++++++++++++++++------------
M laneya/protocol.py 10 +++++-----

4 files changed, 40 insertions, 32 deletions


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

@@ -38,5 +38,5 @@ def logout():
   38    38 
   39    39 
   40    40 def get_map(map_id):
   41    -1     """Ask the server to send a serialisation of the specified map. """
   -1    41     """Ask the server to send a serialisation of the specified map."""
   42    42     pass

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

@@ -22,20 +22,24 @@ class Client(protocol.ClientProtocolFactory):
   22    22         width = len(floor_layer)
   23    23         height = len(floor_layer[0])
   24    24 
   25    -1         is_wall = lambda x, y: (
   26    -1             x < 0 or x >= width or
   27    -1             y < 0 or y >= height or
   28    -1             floor_layer[x][y] == 'wall')
   29    -1 
   30    -1         sorrunded = lambda x, y: (
   31    -1             is_wall(x - 1, y) and
   32    -1             is_wall(x - 1, y - 1) and
   33    -1             is_wall(x - 1, y + 1) and
   34    -1             is_wall(x, y - 1) and
   35    -1             is_wall(x + 1, y) and
   36    -1             is_wall(x, y + 1) and
   37    -1             is_wall(x + 1, y - 1) and
   38    -1             is_wall(x + 1, y + 1))
   -1    25         def is_wall(x, y):
   -1    26             return (
   -1    27                 x < 0 or x >= width or
   -1    28                 y < 0 or y >= height or
   -1    29                 floor_layer[x][y] == 'wall'
   -1    30             )
   -1    31 
   -1    32         def sorrunded(x, y):
   -1    33             return (
   -1    34                 is_wall(x - 1, y) and
   -1    35                 is_wall(x - 1, y - 1) and
   -1    36                 is_wall(x - 1, y + 1) and
   -1    37                 is_wall(x, y - 1) and
   -1    38                 is_wall(x + 1, y) and
   -1    39                 is_wall(x, y + 1) and
   -1    40                 is_wall(x + 1, y - 1) and
   -1    41                 is_wall(x + 1, y + 1)
   -1    42             )
   39    43 
   40    44         for x, column in enumerate(floor_layer):
   41    45             for y, field in enumerate(column):

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

@@ -44,22 +44,26 @@ class MapManager(object):
   44    44                 'y_max': max(y1, y2),
   45    45             }
   46    46 
   47    -1             collision_free = lambda other: (
   48    -1                 room['x_min'] > other['x_max'] + 1 or
   49    -1                 room['x_max'] < other['x_min'] - 1 or
   50    -1                 room['y_min'] > other['y_max'] + 1 or
   51    -1                 room['y_max'] < other['y_min'] - 1)
   -1    47             def collision_free(other):
   -1    48                 return (
   -1    49                     room['x_min'] > other['x_max'] + 1 or
   -1    50                     room['x_max'] < other['x_min'] - 1 or
   -1    51                     room['y_min'] > other['y_max'] + 1 or
   -1    52                     room['y_max'] < other['y_min'] - 1
   -1    53                 )
   52    54 
   53    55             if (room['x_max'] - room['x_min'] > 2 and
   54    56                     room['y_max'] - room['y_min'] > 2):
   55    57                 if all((collision_free(other) for other in rooms)):
   56    58                     rooms.append(room)
   57    59 
   58    -1         in_room = lambda x, y, room: (
   59    -1             x >= room['x_min'] and
   60    -1             x <= room['x_max'] and
   61    -1             y >= room['y_min'] and
   62    -1             y <= room['y_max'])
   -1    60         def in_room(x, y, room):
   -1    61             return (
   -1    62                 x >= room['x_min'] and
   -1    63                 x <= room['x_max'] and
   -1    64                 y >= room['y_min'] and
   -1    65                 y <= room['y_max']
   -1    66             )
   63    67 
   64    68         # carve rooms
   65    69         for x in range(self.width):
@@ -133,9 +137,9 @@ class Map(object):
  133   137         self.height = height
  134   138         self.sprites = {}
  135   139         self.movable_layer = [
  136    -1             [None for i in xrange(height)] for i in xrange(width)]
   -1   140             [None for i in range(height)] for i in range(width)]
  137   141         self.floor_layer = [
  138    -1             [None for i in xrange(height)] for i in xrange(width)]
   -1   142             [None for i in range(height)] for i in range(width)]
  139   143         self.ghost = Ghost('example', self, 15, 15)
  140   144 
  141   145     def step(self):

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

@@ -143,12 +143,12 @@ class NetstringReceiver(asyncio.Protocol):
  143   143 
  144   144         while ':' in self.__buffer:
  145   145             length, remainder = self.__buffer.split(':', 1)
  146    -1             l = int(length)
   -1   146             length = int(length)
  147   147 
  148    -1             if len(remainder) > int(length):
  149    -1                 assert remainder[l] == ','
  150    -1                 s = remainder[:int(length)]
  151    -1                 self.__buffer = self.__buffer[len('%i:%s,' % (l, s)):]
   -1   148             if len(remainder) > length:
   -1   149                 assert remainder[length] == ','
   -1   150                 s = remainder[:length]
   -1   151                 self.__buffer = self.__buffer[len('%i:%s,' % (length, s)):]
  152   152                 self.string_received(s)
  153   153             else:
  154   154                 break