本文整理汇总了Python中hero.Hero.push_handlers方法的典型用法代码示例。如果您正苦于以下问题:Python Hero.push_handlers方法的具体用法?Python Hero.push_handlers怎么用?Python Hero.push_handlers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hero.Hero
的用法示例。
在下文中一共展示了Hero.push_handlers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Stage
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import push_handlers [as 别名]
class Stage(pyglet.event.EventDispatcher):
progress_bar = pyglet.sprite.Sprite(pyglet.resource.image('img/gui/progress_bar.png'), 0, 344)
progress_ball = pyglet.sprite.Sprite(pyglet.resource.image('img/gui/progress_ball.png'), 0, 344)
def __init__(self, name):
self.name = name
self.sections = []
self.game_objects = set()
self.offset = VECTOR_NULL
self.is_scrolling = False
self.actual_scroll_speed = VECTOR_NULL
self.target_scroll_speed = SCROLL_SPEED
self.active_section = None
self.despawned_objects = set()
log.debug(D_INIT.format(type(self).__name__, self.name))
def setup(self):
self.reset()
if self.seed is not None:
random.seed(self.seed)
bg_pattern = pyglet.image.SolidColorImagePattern(
self.background_color)
bg_img = bg_pattern.create_image(640, 360) # TODO: Magic number.
self.background = SH.show_sprite(SH.BG, 0)
self.background.image = bg_img
for sect in self.sections:
sect.setup()
self.section_iter = iter(self.sections)
self.advance_section()
self.is_scrolling = True
self.hero = Hero(Vector(100, 100))
self.spawn_game_objects(set([self.hero]))
self.hero.push_handlers(self)
def reset(self):
self.despawn_game_objects(self.game_objects)
self.actual_scroll_speed = VECTOR_NULL
self.offset = VECTOR_NULL
self.active_section = None
log.info('Reset Stage {}.'.format(self.name))
def update(self, dt):
self.update_stage_position(dt)
self.update_game_objects(dt)
self.update_sprites()
self.check_collisions()
self.update_progress_ball()
def update_stage_position(self, dt):
if self.is_scrolling:
self.update_scroll_speed(dt)
self.offset += self.actual_scroll_speed * dt
if self.active_section is not None:
if self.offset.x >= self.active_section.offset.x:
self.advance_section()
def update_scroll_speed(self, dt):
if self.target_scroll_speed != self.actual_scroll_speed:
delta = 50 * dt
diff = self.target_scroll_speed - self.actual_scroll_speed
self.actual_scroll_speed += diff.unit * min(delta, diff.length)
def start_scrolling(self, scroll_speed):
self.target_scroll_speed = scroll_speed
self.is_scrolling = True
def stop_scrolling(self):
self.actual_scroll_speed = VECTOR_NULL
self.is_scrolling = False
def update_game_objects(self, dt):
self.game_objects -= self.despawned_objects
for obj in self.despawned_objects:
obj.despawn()
self.despawned_objects = set()
for gob in self.game_objects:
gob.update(dt)
def update_sprites(self):
for gob in self.game_objects:
gob.align_sprite(self.offset)
def advance_section(self):
if self.active_section is not None:
self.exit_section(self.active_section)
try:
new_section = self.section_iter.next()
self.enter_section(new_section)
except StopIteration:
self.stop_scrolling()
def exit_section(self, old_section):
if old_section is not None:
#.........这里部分代码省略.........