当前位置: 首页>>代码示例>>Python>>正文


Python Brain.pop_state方法代码示例

本文整理汇总了Python中brain.Brain.pop_state方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.pop_state方法的具体用法?Python Brain.pop_state怎么用?Python Brain.pop_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在brain.Brain的用法示例。


在下文中一共展示了Brain.pop_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import pop_state [as 别名]
class Actor:

    def __init__(self):
        self.brain = Brain()
        self.movement = Movement(self, max_speed=800)
        self.max_velocity = 800
        self.move_target = None
        self.attack_target = None
        self.brain.push_state(self.ai_idle)

    def remove_body(self):
        try:
            for s in self.body.shapes:
                self.game.space.remove(s)
            self.game.space.remove(self.body)
        except:
            print("Something fucky with physics.")

    def ai_wander(self):
        if self.body:
            self.body.apply_impulse(
                (randrange(-2500, 2500), randrange(-2500, 2500))
            )
            self.brain.pop_state()

    def ai_move_to_target(self, *args, **kwargs):
        mt = self.move_target
        if mt:
            d = get_dist(
                mt.x,
                mt.y,
                self.x,
                self.y
            )
            if d > self.get_stat("arng"):
                line_of_sight = True
                line = (
                    (self.x, self.y), (mt.x, mt.y)
                )
                raycast_objects = self.game.spatial_hash.get_objects_from_line(
                    *line,
                    type=Collidable
                )
                for o in raycast_objects:
                    for s in o.body.shapes:
                        if s.segment_query(*line):
                            line_of_sight = False
                            break
                if line_of_sight:
                    self.movement.target = (mt.x, mt.y)
                else:
                    self.movement.target = None
                    self.brain.pop_state()
            else:
                self.brain.pop_state()
        else:
            self.brain.pop_state()

    def ai_feared(self, *args, **kwargs):
        pass

    def ai_attack(self):
        if self.attack_target:
            if self.attack_target.hp <= 0:
                self.brain.pop_state()
                self.attack_target = None
                self.auto_attack_target = None
            else:
                d = get_dist(
                    self.attack_target.x,
                    self.attack_target.y,
                    self.x,
                    self.y
                )
                if d < 40:
                    if not self.auto_attack_target:
                        self.auto_attack_target = self.attack_target
                else:
                    self.move_target = self.attack_target
                    self.brain.push_state(self.ai_move_to_target)
        else:
            self.brain.pop_state()

    def ai_idle(self):
        if self.game.player:
            d = get_dist(
                self.game.player.x,
                self.game.player.y,
                self.x,
                self.y
            )
            if d <= 100:
                self.attack_target = self.game.player
                self.brain.push_state(self.ai_attack)
        else:
            self.move_target = None
            self.attack_target = None
            self.auto_attack_target = None
开发者ID:NiclasEriksen,项目名称:rpg_procgen,代码行数:100,代码来源:actor.py


注:本文中的brain.Brain.pop_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。