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


Python Sprite.set_offset方法代码示例

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


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

示例1: Player

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import set_offset [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.set_offset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。