return 0
return self.things[-1].id_ + 1
- def ensure_map(self, map_pos):
- if map_pos in self.maps and self.maps[map_pos].size == self.map_size:
- return
- self.maps[map_pos] = self.game.map_type(self.map_size)
+ def get_map(self, map_pos, create_unfound=True):
+ if not (map_pos in self.maps and
+ self.maps[map_pos].size == self.map_size):
+ if create_unfound:
+ self.maps[map_pos] = self.game.map_type(self.map_size)
+ for pos in self.maps[map_pos]:
+ self.maps[map_pos][pos] = '~'
+ else:
+ return None
+ return self.maps[map_pos]
def proceed_to_next_player_turn(self):
"""Run game world turns until player can decide their next step.
self.turn = 0
self.maps = {}
self.map_size = yx
- self.ensure_map(YX(0,0))
- self.ensure_map(YX(0,1))
- self.ensure_map(YX(1,1))
- self.ensure_map(YX(1,0))
- self.ensure_map(YX(1,-1))
- self.ensure_map(YX(0,-1))
- self.ensure_map(YX(-1,-1))
- self.ensure_map(YX(-1,0))
- self.ensure_map(YX(-1,1))
- for map_pos in self.maps:
- map_ = self.maps[map_pos]
- if YX(0,0) == map_pos:
- for pos in map_:
- map_[pos] = self.rand.choice(('.', '.', '.', '.', 'x'))
- else:
- for pos in map_:
- map_[pos] = '~'
+ map_ = self.get_map(YX(0,0))
+ for pos in map_:
+ map_[pos] = self.rand.choice(('.', '.', '.', '.', 'x'))
player = add_thing_at_random('human')
self.player_id = player.id_
add_thing_at_random('monster')
def __init__(self, world, id_=None, position=(YX(0,0), YX(0,0))):
self.world = world
- self.position = position
if id_ is None:
self.id_ = self.world.new_thing_id()
else:
self.id_ = id_
+ self.position = position
@property
def position(self):
def __init__(self, *args, **kwargs):
self.inventory = []
+ self._radius = 8
super().__init__(*args, **kwargs)
def proceed(self):
for t_id in self.inventory:
t = self.world.get_thing(t_id)
t.position = self.position
+ if not self.id_ == self.world.player_id:
+ return
+ edge_left = self.position[1].x - self._radius
+ edge_right = self.position[1].x + self._radius
+ edge_up = self.position[1].y - self._radius
+ edge_down = self.position[1].y + self._radius
+ if edge_left < 0:
+ self.world.get_map(self.position[0] - YX(1,-1))
+ self.world.get_map(self.position[0] - YX(0,-1))
+ self.world.get_map(self.position[0] - YX(-1,-1))
+ if edge_right >= self.world.map_size.x:
+ self.world.get_map(self.position[0] + YX(1,1))
+ self.world.get_map(self.position[0] + YX(0,1))
+ self.world.get_map(self.position[0] + YX(-1,1))
+ if edge_up < 0:
+ self.world.get_map(self.position[0] - YX(-1,1))
+ self.world.get_map(self.position[0] - YX(-1,0))
+ self.world.get_map(self.position[0] - YX(-1,-1))
+ if edge_down >= self.world.map_size.y:
+ self.world.get_map(self.position[0] + YX(1,1))
+ self.world.get_map(self.position[0] + YX(1,0))
+ self.world.get_map(self.position[0] + YX(1,-1))
super().__init__(*args, **kwargs)
self.set_task('WAIT')
self._last_task_result = None
- self._radius = 8
self.unset_surroundings()
def move_on_dijkstra_map(self, own_pos, targets):
big_x, small_x = pan_and_scan(size.x, pos.x, offset.x)
big_yx = YX(big_y, big_x)
small_yx = YX(small_y, small_x)
- self._surrounding_map[pos] = self.world.maps[big_yx][small_yx]
+ map_ = self.world.get_map(big_yx, False)
+ if map_ is None:
+ map_ = self.world.game.map_type(size=self.world.map_size)
+ self._surrounding_map[pos] = map_[small_yx]
return self._surrounding_map
def get_stencil(self):