Let NPCs randomly walk
This commit is contained in:
parent
1cd45d366b
commit
a43e403e9c
1 changed files with 14 additions and 1 deletions
|
@ -2,10 +2,11 @@
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import random
|
||||||
import tcod
|
import tcod
|
||||||
from .actions import ExitAction, MovePlayerAction, RegenerateRoomsAction
|
from .actions import ExitAction, MovePlayerAction, RegenerateRoomsAction
|
||||||
from .events import EventHandler
|
from .events import EventHandler
|
||||||
from .geometry import Point, Size
|
from .geometry import Direction, Point, Size
|
||||||
from .map import Map
|
from .map import Map
|
||||||
from .object import Entity
|
from .object import Entity
|
||||||
from typing import AbstractSet
|
from typing import AbstractSet
|
||||||
|
@ -47,6 +48,18 @@ class Engine:
|
||||||
|
|
||||||
action.perform(self, self.player)
|
action.perform(self, self.player)
|
||||||
|
|
||||||
|
directions = list(Direction.all())
|
||||||
|
|
||||||
|
for ent in self.entities:
|
||||||
|
if ent == self.player:
|
||||||
|
continue
|
||||||
|
|
||||||
|
while True:
|
||||||
|
new_position = ent.position + random.choice(directions)
|
||||||
|
if self.map.tile_is_walkable(new_position):
|
||||||
|
ent.position = new_position
|
||||||
|
break
|
||||||
|
|
||||||
self.update_field_of_view()
|
self.update_field_of_view()
|
||||||
|
|
||||||
def print_to_console(self, console):
|
def print_to_console(self, console):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue