Redone the spawn procedute and destination objects

This commit is contained in:
Steffen Illium
2023-10-11 16:36:48 +02:00
parent e64fa84ef1
commit e326a95bf4
32 changed files with 266 additions and 146 deletions

View File

@@ -55,6 +55,12 @@ class Entity(EnvObject, abc.ABC):
curr_x, curr_y = self.pos
return last_x - curr_x, last_y - curr_y
def destroy(self):
valid = self._collection.remove_item(self)
for observer in self.observers:
observer.notify_del_entity(self)
return valid
def move(self, next_tile):
curr_tile = self.tile
if not_same_tile := curr_tile != next_tile:
@@ -71,7 +77,7 @@ class Entity(EnvObject, abc.ABC):
super().__init__(**kwargs)
self._status = None
self._tile = tile
tile.enter(self)
assert tile.enter(self, spawn=True), "Positions was not valid!"
def summarize_state(self) -> dict:
return dict(name=str(self.name), x=int(self.x), y=int(self.y),

View File

@@ -81,8 +81,12 @@ class Floor(EnvObject):
def is_occupied(self):
return bool(len(self._guests))
def enter(self, guest):
if (guest.name not in self._guests and not self.is_blocked) and not (guest.var_is_blocking_pos and self.is_occupied()):
def enter(self, guest, spawn=False):
same_pos = guest.name not in self._guests
not_blocked = not self.is_blocked
no_become_blocked_when_occupied = not (guest.var_is_blocking_pos and self.is_occupied())
not_introduce_collision = not (spawn and guest.var_can_collide and any(x.var_can_collide for x in self.guests))
if same_pos and not_blocked and no_become_blocked_when_occupied and not_introduce_collision:
self._guests.update({guest.name: guest})
return c.VALID
else: