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


Python Ship.collision方法代码示例

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


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

示例1: Asteroids

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import collision [as 别名]
class Asteroids(Game):
	def __init__(self):
		Game.__init__(self, config.TITLE, config.SCREEN_X, config.SCREEN_Y)
		self.title = config.TITLE
		self.screen_x = config.SCREEN_X
		self.screen_y = config.SCREEN_Y
		self.level = 1
		self.asteroid_count = 0
		self.ship = Ship()
		self.rocks = []
		self.stars = []
		self.bullet = Bullet()
		self.bullet2 = Bullet()
		self.bullet3 = Bullet()
		self.nuke = Nuke()
		self.score = 0
		pygame.init()
		self.name = ''
		pygame.mixer.init(44100, -16, 2, 512)
		self.star_trek = pygame.mixer.Sound("Star Trek Theme Song.wav")
		self.star_trek.play(-1)
		self.ship_explosion_sfx = pygame.mixer.Sound("explosion.ogg")
		self.astroid_explosion_sfx = pygame.mixer.Sound("explosion.ogg")
		for i in range(config.ASTEROID_COUNT):
			self.rocks.append(Rock())
			self.asteroid_count += 1
		for i in range(config.STAR_COUNT):
			self.stars.append(Stars())
		for i in self.rocks:
			if i.active == False:
				self.asteroid_count -= 1
		self.high_count = 10
		self.high_score = []
		try:
			f = open("score.txt", 'r')
			for score in f:
				score.rstrip("\n")
				self.high_score.append(score)
			f.close()
			print self.high_score
		except:
			self.highscore = 0
		self.rock_dead = []

	def reset(self, position, rotation, pull):
		Game.__init__(self, config.TITLE, config.SCREEN_X, config.SCREEN_Y)
		self.ship = Ship()
		self.ship.position = position
		self.ship.rotation = rotation
		self.ship.pull = pull
		self.rocks = []
		self.stars = []
		self.asteroid_count = 0
		self.bullet = Bullet()
		self.bullet2 = Bullet()
		self.bullet3 = Bullet()
		self.nuke = Nuke()
		pygame.init()
		pygame.mixer.init(44100, -16, 2, 512)
		self.star_trek = pygame.mixer.Sound("Star Trek Theme Song.wav")
		self.star_trek.play(-1)
		self.ship_explosion_sfx = pygame.mixer.Sound("explosion.ogg")
		self.astroid_explosion_sfx = pygame.mixer.Sound("explosion.ogg")
		for i in range(config.ASTEROID_COUNT + (self.level + 1)):
			self.rocks.append(Rock())
			self.asteroid_count += 1
		for i in range(config.STAR_COUNT):
			self.stars.append(Stars())
		for i in self.rocks:
			if i.active == False:
				self.asteroid_count -= 1
		self.high_count = 10
		self.high_score = []
		try:
			f = open("score.txt", 'r')
			for score in f:
				score.rstrip()
				self.high_score.append(score)
			f.close()
		except:
			self.highscore = 0
		self.rock_dead = []



	def game_logic(self, keys, newkeys, surface):
		self.ship.game_logic(keys, newkeys,self.bullet, self.nuke)
		self.bullet.game_logic(keys, newkeys)
		self.nuke.game_logic(keys, newkeys)
		for rock in self.rocks:
			if rock.active == True:
				rock.game_logic(keys, newkeys)

				if self.bullet.collision(rock) and self.bullet.active:
					self.astroid_explosion_sfx.play()
					self.rock_dead.append(rock)
					rock.active = False
					self.asteroid_count -= 1
					self.score = self.score + 100

#.........这里部分代码省略.........
开发者ID:majormoses,项目名称:asteroids,代码行数:103,代码来源:asteroids.py


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