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


Python Scene.refresh方法代码示例

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


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

示例1: __init__

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import refresh [as 别名]
class Game:
	max_health = 10
	ship_space = 15
	screens = 3

	def __init__(self, player, boss):
		self.p1 = player
		self.p2 = boss

		p1_status = Scene(max(len(self.p1.name), self.max_health) + 1, 3)
		p1_status.modify_background(self.p1.name)
		p2_status = Scene(max(len(self.p2.name), self.max_health) + 1, 3)
		p2_status.modify_background(self.p2.name)

		self.p1.health = HealthBar(self.max_health)
		p1_status.add_object(self.p1.health, 0, 2)
		self.p1.status_win = p1_status
		self.p1.thruster = Thruster(self.p1)
		self.p1.thruster.switch_direction()
		self.p1.thruster.set_color(curses.COLOR_CYAN)

		self.p2.health = HealthBar(self.max_health)
		p2_status.add_object(self.p2.health, 0, 2)
		self.p2.status_win = p2_status

		width, height = Scene.max_view(0, 7)
		width *= self.screens
		self.main_win = Scene(width, height)
		self.main_win.modify_background(self.generate_starfield(width, height))

	def intro(self):
		self.midpoint_x = round(
			self.main_win.width * (self.screens - 0.5)/self.screens
		)
		midpoint_y = self.main_win.height // 2
		outline = Outline(self.p2)
		self.main_win.add_object(
			outline,
			self.midpoint_x + self.ship_space - 1,
			midpoint_y - self.p2.height // 2 - 1
		)
		outline = Outline(self.p1)
		self.main_win.add_object(
			outline,
			self.midpoint_x - self.ship_space - self.p1.width,
			midpoint_y - self.p1.height // 2 - 1
		)
		self.main_win.add_object(
			self.p2,
			self.midpoint_x + self.ship_space,
			midpoint_y - self.p2.height // 2
		)
		self.main_win.add_object(
			self.p1,
			4,
			midpoint_y - self.p1.height // 2
		)
		self.main_win.add_object(
			self.p1.thruster,
			2,
			midpoint_y + 1
		)
		self.main_win.display(0, 7)

		self.main_win.auto_refresh = False
		position = self.p1.scene.objects[self.p1.stacking_order]
		distance = self.midpoint_x - self.ship_space - position.x2
		speed = 0.04
		while distance > 0:
			self.main_win.move_relative(self.p1, x=1)
			self.main_win.move_relative(self.p1.thruster, x=1)
			self.p1.thruster.update()
			self.main_win.pan(x=1)
			self.main_win.refresh()
			time.sleep(speed)
			if distance == 40:
				self.main_win.hide(self.p1.thruster)
			if distance < 40:
				speed += 0.005
			distance -= 1

		msg = Alert('!!! WARNING !!!\nENEMY WEAPONS LOCKED')
		msg.show(self.main_win)
		self.main_win.refresh()
		time.sleep(3)
		msg.hide()
		self.main_win.refresh()


	def play(self):
		self.p1.status_win.display(
			curses.COLS // 2 - self.ship_space - self.max_health,
			2
		)
		self.p2.status_win.display(
			curses.COLS // 2 + self.ship_space,
			2
		)

		if self.p1.scene.objects[self.p1.stacking_order].x2 != self.midpoint_x - self.ship_space:
#.........这里部分代码省略.........
开发者ID:restouffer,项目名称:spacebattle,代码行数:103,代码来源:game.py


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