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


Python Timer.is_complete方法代码示例

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


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

示例1: Player

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import is_complete [as 别名]
class Player (Sprite):

	def __init__ (self, x, y):
		
		Sprite.__init__(self, x, y, 'princess')
		
		self.grid_x = x
		self.grid_y = y

		self.light = Sprite(x, y, 'light')
		self.light.offset_x = -96
		self.light.offset_y = -106
		self.light.play('default', loop=True)
		
		# walk timer
		self.timer = None
		
		# default orientation
		self.ori = 'up'
		
		# animations		
		self.add_anim('walk_up', common.WALK_MOVEMENT_TIME, range(0, 9))
		self.add_anim('walk_left', common.WALK_MOVEMENT_TIME, range(9, 18))
		self.add_anim('walk_down', common.WALK_MOVEMENT_TIME, range(18, 27))
		self.add_anim('walk_right', common.WALK_MOVEMENT_TIME, range(27, 36))
	
	@property
	def grid_x (self):		
		return int(self.x / common.TILE_SIZE)
		
	@property
	def grid_y (self):		
		return int(self.y / common.TILE_SIZE)
	
	@grid_x.setter
	def grid_x (self, x):		
		self.x = x * common.TILE_SIZE
		
	@grid_y.setter
	def grid_y (self, y):		
		self.y = y * common.TILE_SIZE
	
	def walk (self, x, y):
		
		assert(x == 1 or x == -1 or x == 0)
		assert(y == 1 or y == -1 or y == 0)
		
		if x == 0 and y == 0:
			return
		
		elif self.timer is None or self.timer.is_complete():
		
			x *= common.TILE_SIZE
			y *= common.TILE_SIZE
			
			self._prev_x = self.x
			self._prev_y = self.y
			
			self._next_x = self.x + x
			self._next_y = self.y + y
			
			self._move_x = x
			self._move_y = y
			
			if x < 0:
				self.ori = 'left'
			elif x > 0:
				self.ori = 'right'
			elif y > 0:
				self.ori = 'down'
			else:
				self.ori = 'up'

			self.play('walk_' + self.ori)
			self.timer = Timer(common.WALK_MOVEMENT_TIME)
	
	def update (self, time):
		
		Sprite.update(self, time)		
		self.light.update(time)
		
		if self.timer is not None and not self.timer.is_complete():

			self.timer.update(time)
			
			self.x = self._prev_x + self.timer.percent_done * self._move_x
			self.y = self._prev_y + self.timer.percent_done * self._move_y

		# adjust player light position
		self.light.x = self.x
		self.light.y = self.y
开发者ID:thiagojobson,项目名称:Maze-Of-Kindred,代码行数:93,代码来源:player.py

示例2: MazeOfKindred

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import is_complete [as 别名]

#.........这里部分代码省略.........
		
	def draw (self):
		
		surface = self.maze.image.copy()
		self.fog.fill((0, 0, 0))
		
		x = common.GAME_WIDTH * 0.5 - self.player.x
		y = common.GAME_HEIGHT * 0.8 - self.player.y

		# normalize x and y
		if x > 0: x = 0
		elif x < -320: x = -320
		
		if y > 0: y = 0
		elif y < -960: y = -960
		
		surface.blit(self.castle.image, (self.castle.vx, self.castle.vy))
		surface.blit(self.player.image, (self.player.vx, self.player.vy))
		
		for t in self.torches:
			surface.blit(t.image, (t.vx, t.vy))
		
		for l in self.lights:
			self.fog.blit(l.image, (l.vx, l.vy))
		
		player_light = self.player.light
		self.fog.blit(player_light.image, (player_light.vx, player_light.vy))

		self.screen.blit(surface, (x, y))
		
		if common.ENABLE_FOG:
			self.screen.blit(self.fog, (x, y))
		
		if not self.fade_timer.is_complete():
		
			alpha = 255 - self.fade_timer.percent_done * 255 
			alpha = int(alpha)
			
			fog = pygame.Surface((common.GAME_WIDTH, common.GAME_HEIGHT), pygame.SRCALPHA)
			pygame.draw.rect(fog, (0, 0, 0, alpha), (0, 0, common.GAME_WIDTH, common.GAME_HEIGHT))
			self.screen.blit(fog, (0, 0))
			
		elif self.is_at_door():
		
			fog = pygame.Surface((common.GAME_WIDTH, common.GAME_HEIGHT), pygame.SRCALPHA)
			pygame.draw.rect(fog, (0, 0, 0, 170), (0, 0, common.GAME_WIDTH, common.GAME_HEIGHT))
			self.screen.blit(fog, (0, 0))
			
			self.screen.blit(self.restart.image, (self.restart.vx, self.restart.vy))

		elif self.enable_sound:	
			self.screen.blit(self.sound.image, (self.sound.vx, self.sound.vy))
			
		else:
			self.screen.blit(self.nosound.image, (self.nosound.vx, self.nosound.vy))
		
		pygame.display.update()
		
	def main (self):
		
			clock = pygame.time.Clock()
			
			pygame.key.set_repeat(1, 100)
			
			x = y = 0
			
开发者ID:thiagojobson,项目名称:Maze-Of-Kindred,代码行数:69,代码来源:main.py


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