Generate entities in rooms at different locations
Prior to this change, entities in rooms would always be spawned on the same tile.
This commit is contained in:
parent
c9b86271d3
commit
7820adf057
1 changed files with 9 additions and 6 deletions
|
@ -57,12 +57,12 @@ class Engine:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
floor = list(room.walkable_tiles)
|
floor = list(room.walkable_tiles)
|
||||||
while True:
|
|
||||||
random_start_position = random.choice(floor)
|
|
||||||
if not any(ent.position == random_start_position for ent in self.entities):
|
|
||||||
break
|
|
||||||
|
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
|
while True:
|
||||||
|
random_start_position = random.choice(floor)
|
||||||
|
if not any(ent.position == random_start_position for ent in self.entities):
|
||||||
|
break
|
||||||
|
|
||||||
spawn_monster_chance = random.random()
|
spawn_monster_chance = random.random()
|
||||||
if spawn_monster_chance > 0.8:
|
if spawn_monster_chance > 0.8:
|
||||||
monster = Monster(monsters.Troll, ai_class=HostileEnemy, position=random_start_position)
|
monster = Monster(monsters.Troll, ai_class=HostileEnemy, position=random_start_position)
|
||||||
|
@ -78,7 +78,10 @@ class Engine:
|
||||||
'''Print the whole game to the given console.'''
|
'''Print the whole game to the given console.'''
|
||||||
self.map.print_to_console(console)
|
self.map.print_to_console(console)
|
||||||
|
|
||||||
for ent in self.entities:
|
hp, max_hp = self.hero.fighter.hit_points, self.hero.fighter.maximum_hit_points
|
||||||
|
console.print(x=1, y=47, string=f'HP: {hp}/{max_hp}')
|
||||||
|
|
||||||
|
for ent in sorted(self.entities, key=lambda e: e.render_order.value):
|
||||||
# Only print entities that are in the field of view
|
# Only print entities that are in the field of view
|
||||||
if not self.map.visible[tuple(ent.position)]:
|
if not self.map.visible[tuple(ent.position)]:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue