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


Python Actor.move_to方法代码示例

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


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

示例1: Tilemap_Tester_With_Box

# 需要导入模块: from actor import Actor [as 别名]
# 或者: from actor.Actor import move_to [as 别名]
class Tilemap_Tester_With_Box(Location_Layer):

    is_event_handler = True
    BASE_CAMERA_SPEED = 600.0
    is_debag = False

    def __init__(self, force_ground, scroller):
        layer.ScrollableLayer.__init__(self)
        self.scroller = scroller
        self.force_ground = force_ground
        self.b2world = b2.b2World(gravity=(0, -GRAVITY),
                                  contactListener=b2Listener())
        self.b2level = self.b2world.CreateStaticBody()
        self._create_b2_tile_map(force_ground)
        #FROM TILEMAP TESTER
        self.camera_pos = [16*25, 16*25]
        self.keys = {key.LEFT: False,
                     key.RIGHT: False,
                     key.UP: False,
                     key.DOWN: False}
        movable_object.Movable_Object.tilemap = self.force_ground
        movable_object.Movable_Object.world = self.b2world

        self.unit = Actor(Human)
        #print self.unit.cshape
        self.unit.move_to(60, 1716)
        self.add(self.unit, z=100)
        self.unit.do(Brain())
        self.cellmap = force_ground
        #self.counter = 0
        self.path = None

        self.counter = 0
        self.fr = None

        self.schedule(self.update)

    def update(self, dt):
        floor = self.unit.get_rect().midbottom
        current_cell = self.force_ground.get_at_pixel(*floor)
        down = self.force_ground.get_neighbor(current_cell, (0, -1))
        i, j = down.i, down.j
        self.force_ground.set_cell_opacity(i, j, 100)

        self.b2world.Step(dt, 1, 1)

        self.camera_pos[0] += (self.keys[key.RIGHT] - self.keys[key.LEFT])*self.BASE_CAMERA_SPEED*dt
        self.camera_pos[1] += (self.keys[key.UP] - self.keys[key.DOWN])*self.BASE_CAMERA_SPEED*dt
        self.scroller.set_focus(*self.camera_pos)

    def on_key_press(self, symbol, modifers):
        self.keys[symbol] = True

    def on_key_release(self, symbol, modifers):
        self.keys[symbol] = False

    def on_mouse_press(self, x, y, button, modifiers):
        if not self.is_debag:
            if self.path:
                self.path.kill()
            x, y = self.scroller.pixel_from_screen(x, y)
            to = self.cellmap.get_at_pixel(x, y)
            #fr = self.cellmap.get_neighbor(self.cellmap.get_at_pixel(*self.unit.get_rect().midbottom), self.cellmap.UP)
            fr = self.cellmap.get_at_pixel(*self.unit.get_rect().midbottom)
            #print self.cellmap.get_neighbor(fr, self.cellmap.DOWN).tile.properties
            oth_path = Connections_Net([(fr, to)])
            #self.add(oth_path, z=10)
            t = clock()
            #path = manhattan_dijkstra(self.fr, self.to)
            #path = bfs(self.fr, self.to)
            path = manhattan_Grankovski_a_star(fr, to)
            print clock() - t
            self.path = create_drawed_path(path)
            self.unit.push_task(Follow_To(self.unit, path))
            self.cellmap.add(self.path, z=10)
        else:
            if self.counter == 0:
                if self.path:
                    self.path.kill()
                x, y = self.scroller.pixel_from_screen(x, y)
                self.fr = self.cellmap.get_at_pixel(x, y)
                self.counter = 1
            else:
                x, y = self.scroller.pixel_from_screen(x, y)
                to = self.cellmap.get_at_pixel(x, y)
                path = manhattan_Grankovski_a_star(self.fr, to)
                self.path = create_drawed_path(path)
                self.cellmap.add(self.path, z=10)
                self.counter = 0

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifers):
        pass

    def on_mouse_motion(self, x, y, dx, dy):
        pass

    def on_mouse_release(self, x, y, buttons, modifers):
        pass
开发者ID:Ecialo,项目名称:Codename-Parzalon,代码行数:100,代码来源:tmx_map_research.py


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