本文整理汇总了Python中util.Timer.check方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.check方法的具体用法?Python Timer.check怎么用?Python Timer.check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Timer
的用法示例。
在下文中一共展示了Timer.check方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: JumpTimer
# 需要导入模块: from util import Timer [as 别名]
# 或者: from util.Timer import check [as 别名]
class JumpTimer(object):
'''When hitting the ground wait a bit before jumping again. When leaving the ground wait a bit before forbidding jumps'''
def __init__(self):
object.__init__(self)
self.timer = None
self.wait_timer = None
def set(self):
# Add a 100ms timer
self.timer = Timer(config.getint('Physics','jump_time'))
def update(self, ms):
# Remove timer when time runs out
if self.timer and self.timer.check(ms):
self.unset()
def jump_allowed(self):
return self.timer is not None
def unset(self):
self.timer = None
示例2: Level
# 需要导入模块: from util import Timer [as 别名]
# 或者: from util.Timer import check [as 别名]
#.........这里部分代码省略.........
x = 0
if state['left']:
x = -1
elif state['right']:
x = 1
self.player.set_direction(x)
self.input_state = state
if not state['up']:
self.jump_wait_timer = None
def tick(self, ms):
self.player.move(ms)
if self.player.collide_rect.left >= self.world_map.pixel_width - 16:
debug('Level complete')
return True
# Handle collisions with walls/platforms
try:
self.collide_walls(ms)
except OutOfBounds:
debug('%s out of bounds', self.player.collide_rect)
raise FellOffMap()
# Check for jump every frame, in case user is holding down the button
if not self.jump_wait_timer and self.input_state and self.input_state['up'] and self.jump_timer.jump_allowed():
debug('jump')
self.jump_timer.unset()
self.jump_wait_timer = Timer(config.getint('Physics','jump_wait_time')) # wait a bit between jumps
self.player.start_jump()
elif self.jump_wait_timer:
if self.jump_wait_timer.check(ms):
self.jump_wait_timer = None
# Center camera on player
self.camera.center = self.player.rect.center
# Constrain camera to the level
self.camera.right = min(self.camera.right, self.world_map.pixel_width)
self.camera.bottom = min(self.camera.bottom, self.world_map.pixel_height)
self.camera.left = max(self.camera.left, 0)
self.camera.top = max(self.camera.top, 0)
self.renderer.set_camera_position(self.camera.centerx, self.camera.centery)
self.renderer.set_camera_margin(0, 0, 0, 0) # something is resetting the margin to 16px each frame... grrr
def debug(self):
debug('camera %s %s', self.camera.topleft,self.camera.bottomright)
sprite_layers = self.renderer.get_layers_from_map()
for sprite_layer in sprite_layers:
debug('layer %s: margin %s, cam rect %s, render cam rect %s, paralax factor %s,%s',
id(sprite_layer),
self.renderer._margin,
self.renderer._cam_rect,
self.renderer._render_cam_rect,
sprite_layer.paralax_factor_x,
sprite_layer.paralax_factor_y)
def screen_coordinates(self, pos):
'''Convert world coordinates into screen coordinates'''
x,y = pos
return (x-self.camera.left, y-self.camera.top)
def draw(self, screen):
screen.fill((255,255,255))