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


Python Sprite.use_frames方法代码示例

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


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

示例1: ColorChangingBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import use_frames [as 别名]
class ColorChangingBlock(PhysicsObject):

	PATTERN_SIZE = 3

	def __init__(self, pos, interval, exclude_color):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/blocks.png', (32, 32), 0.1)

		self.id = ID_OBJ

		self.timer = 0.0
		self.interval = float(interval)

		self.colors = ['red', 'green', 'blue']
		self.exclude_color = self.colors.index(exclude_color)

		# create a pattern for changing colors
		self.pattern = []

		while len(self.pattern) < self.PATTERN_SIZE:
			color = random.randint(0, 2)
			if not color == self.exclude_color and self.pattern.count(color) < 2:
				self.pattern.append(color)

		self.pattern_color_pointer = random.randint(0, self.PATTERN_SIZE - 1)
		self.previous_active_color = 0
		self.active_color = self.colors[ self.pattern[self.pattern_color_pointer] ]
		self.sprite.use_frames([ self.pattern[self.pattern_color_pointer] ])

	def on_collide_obj(self, obj):
		return True

	def on_collide_platform(self, plat):
		return True

	def update(self, dt):
		self.sprite.update(dt)
		self.timer += dt

		self.previous_active_color = self.active_color
		
		if self.timer >= self.interval:
			self.timer = 0
			self.previous_pointer = self.pattern_color_pointer
			self.pattern_color_pointer += 1

			if self.pattern_color_pointer >= self.PATTERN_SIZE:
				self.pattern_color_pointer = 0

			next_color = self.pattern[self.pattern_color_pointer]
			self.sprite.use_frames([next_color])
			self.active_color = self.colors[next_color]

	def draw(self, screen, view_rect):
		rect = Rect(self.rect.left, self.rect.top, self.rect.width, self.rect.height)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top

		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:61,代码来源:play_scene.py

示例2: LavaBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import use_frames [as 别名]
class LavaBlock(PhysicsObject):

	def __init__(self, pos):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/blocks.png', (32, 32), 0.1)
		self.sprite.use_frames([0, 1, 2])
		self.id = ID_OBJ

	def update(self, dt):
		self.sprite.update(dt)

	def draw(self, screen, view_rect):
		rect = Rect(self.rect.left, self.rect.top, self.rect.width, self.rect.height)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top
		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:18,代码来源:play_scene.py

示例3: ImpulseBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import use_frames [as 别名]
class ImpulseBlock(PhysicsObject):

	BOUNCE_FACTOR = 1.35
	BOUNCE_MIN_INTERVAL = 0.5

	def __init__(self, pos, color, direction):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/arrow_blocks.png', (32, 32), 0.1)
		self.id = ID_OBJ
		self.colors = COLORS + ['gray']
		color_index = self.colors.index(color)
		self.active_color = self.colors[ color_index ]
		self.sprite.use_frames([color_index])
		self.sprite.update(5)
		self.direction = direction # 1(down) or -1(up)
		self.sprite.set_direction(False, direction)

	def change_obj_velocity(self, obj):
		if obj.active_color != self.active_color:
			if obj.bounce_timer <= 0.0:
				if obj.id == ID_PLAYER:
					PLAY_SOUND(obj.sound_jump)
				obj.bounce_timer = self.BOUNCE_MIN_INTERVAL
				if obj.vel.y < 50:
					obj.vel.y = PLAYER_JUMP_FORCE
				else:
					obj.vel.y = (obj.vel.y * self.BOUNCE_FACTOR) * self.direction
			return True
		return False

	def update(self, dt):
		pass

	def draw(self, screen, view_rect):
		rect = copy.copy(self.rect)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top
		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:40,代码来源:play_scene.py

示例4: MovableBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import use_frames [as 别名]
class MovableBlock(PhysicsObject):

	def __init__(self, pos, color):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_DYNAMIC)
		self.set_foot(True)
		self.sprite = Sprite('./assets/img/ground.png', (32, 32), 0.1)
		self.bounce_timer = 0.0

		self.id = ID_MOVABLE_BLOCK
		self.acceleration = 300

		self.colors = COLORS + ['gray']
		self.colors_values = [RED, GREEN, BLUE, GRAY]
		self.color_index = self.colors.index(color)

		self.active_color = self.colors[ self.colors.index(color) ]
		self.previous_active_color = 0

		self.sprite.use_frames([ 12 + self.color_index ])
		self.sprite.update(5)

	def on_collide_obj(self, obj):
		return True

	def on_collide_platform(self, p):
		return p.layer != self.active_color

	def update(self, dt):
		PhysicsObject.update(self, dt)
		self.sprite.update(dt)

		if self.bounce_timer > 0.0:
			self.bounce_timer -= dt

	def draw(self, screen, view_rect):
		rect = copy.copy(self.rect)
		rect.left += rect.width / 2
		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:40,代码来源:play_scene.py

示例5: Player

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import use_frames [as 别名]
class Player(PhysicsObject):

	def __init__(self, pos, color_interval, input):
		PhysicsObject.__init__(self, pos, (0, 0), (28, 48), BODY_DYNAMIC)
		self.change_color_mode = False
		self.color_interval = 0
		self.color_timer_text = None
		if color_interval > 0:
			self.change_color_mode = True
			self.color_interval = color_interval
			font = Font('./assets/font/vcr.ttf', 18)
			self.color_timer_text = Text(font, str(color_interval), (740, 5))
			self.color_timer_text.update = True
		self.color_timer = 0.0
		self.input = input
		self.sprite = Sprite("./assets/img/new_guy.png", (64, 64), (1.0 / 12.0))
		self.set_foot(True)
		self.active_color = 'red'
		self.acceleration = 400
		self.dead = False
		self.sound_jump = Sound('./assets/audio/jump.wav')
		self.sound_land = Sound('./assets/audio/land.wav')
		self.sound_push = Sound('./assets/audio/push.wav')
		self.sound_timer = 0.0
		self.sound_min_interval = 0.5
		self.id = ID_PLAYER
		self.bounce_timer = 0.0

		# view rectangle for HUD stuff
		self.view_rect = Rect(0, 0, 0, 0)

	def handle_input(self, dt):
		
		self.target_vel.x = 0
		if self.input.is_pressed(K_RIGHT):
			if not self.wants_to_move:
				self.wants_to_move = True
			self.target_vel.x = 300
			self.sprite.set_direction(1)
			self.sprite.use_frames([1, 2])
		elif self.input.is_pressed(K_LEFT):
			if not self.wants_to_move:
				self.wants_to_move = True
			self.target_vel.x = -300
			self.sprite.set_direction(-1)
			self.sprite.use_frames([1, 2])

		if self.input.is_down(K_UP) and self.on_ground:
			self.vel.y = PLAYER_JUMP_FORCE
			PLAY_SOUND(self.sound_jump)
		
		# if we are in the automatic color changing mode
		# ignore the input from the user
		if self.change_color_mode:
			return

		if self.input.is_down(K_1):
			self.active_color = 'red'
			self.sprite.set_offset(0)

		elif self.input.is_down(K_2):
			self.active_color = 'green'
			self.sprite.set_offset(4)

		elif self.input.is_down(K_3):
			self.active_color = 'blue'
			self.sprite.set_offset(8)

	def play_land_sound(self):
		if self.sound_timer > self.sound_min_interval:
			PLAY_SOUND(self.sound_land.play())
			self.sound_timer = 0.0

	def on_collide_obj(self, obj):
		if isinstance(obj, ColorChangingBlock) or \
			isinstance(obj, MovingBlock) or \
			isinstance(obj, MovableBlock) or \
			isinstance(obj, ImpulseBlock):
			if obj.active_color != self.active_color:
				if self.vel.y > 1.0: 
					pass 
				return True
			return False
		elif isinstance(obj, LavaBlock):
			self.dead = True
		elif isinstance(obj, ExitBlock):
			return True if self.active_color != 'green' else False
		return True

	def on_collide_platform(self, platform):
		if platform.layer != self.active_color:
			if self.vel.y > 1.0: 
				pass
			return True
		return False

	def change_color(self):
		current_color_index = COLORS.index(self.active_color)
		next_color_index = (current_color_index + 1) % len(COLORS)
	
#.........这里部分代码省略.........
开发者ID:glhrmfrts,项目名称:rgb,代码行数:103,代码来源:play_scene.py


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