Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TargetPriority(enum.Enum):
- LOW_HEALTH = 1
- HIGH_HEALTH = 2
- FIRST = 3
- LAST = 4
- CLOSEST = 5
- class Tower(Entity):
- def __init__(self, *args, **kwargs, target_priority=TargetPriority.FIRST):
- super().__init__(*args, **kwargs)
- self.target_priority = target_priority
- def find_target(self, all_monsters):
- sort_functions = {
- TargetPriority.LOW_HEALTH: lambda monster: monster.health,
- TargetPriority.HIGH_HEALTH: lambda monster: -monster.health,
- TargetPriority.FIRST: ???,
- TargetPriority.LAST: ???,
- TargetPriority.CLOSEST: self.distance_to,
- }
- func = sort_functions[self.target_priority]
- return next(sorted(all_monsters, key=func), None)
- class Monster(Entity):
- def __init__(self, *args, **kwargs, health, checkpoint):
- super().__init__(*args, **kwargs)
- self.health = health
- self.checkpoint = checkpoint
- def update(self, dt):
- travel = self.velocity / 1000 * dt
- remaining_distance = self.distance_to(self.checkpoint)
- if travel.length < remaining_distance:
- self.position += travel
- else:
- self.checkpoint.check_in(self)
- self.position += travel
- self.total_distance_travelled += travel.length
Add Comment
Please, Sign In to add comment