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


Python Ship.update方法代码示例

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


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

示例1: __init__

# 需要导入模块: import Ship [as 别名]
# 或者: from Ship import update [as 别名]

#.........这里部分代码省略.........
		if os.path.isfile("highscores.txt") == False:
			eightcrypt = EightCrypt()
			self.HIGHSCORES.append("Chuck Norris - 999999")
			self.HIGHSCORES.append("player 1 - 1001001")
			self.HIGHSCORES.append("bush - 2001")
			self.HIGHSCORES.append("John Cena - 10")
			self.HIGHSCORES.append("Liz Boese - 1")
			eightcrypt.write("highscores.txt", self.HIGHSCORES)
		else:
			eightcrypt = EightCrypt()
			self.HIGHSCORES = eightcrypt.read("highscores.txt")
			
			
	def explosivifySprite(self, sprite_rect, explosionCount=4): #Explode around a sprite, optional explosions count
		for i in range(0,explosionCount):
			x_pos = sprite_rect.x - int(.4 * sprite_rect.width)
			y_pos = sprite_rect.y - int(.4 * sprite_rect.height)
			offset_x = random.randint(0,sprite_rect.width + int(.4 * sprite_rect.width))
			offset_y = random.randint(0,sprite_rect.height + int(.4 * sprite_rect.height)) #40% increased explosion radius >:)
			self.explosion_sprites.add(Explosion(x_pos + offset_x, y_pos + offset_y))

	def LoadSprites(self):
		self.ship = Ship()
		self.ship_sprite = pygame.sprite.RenderPlain((self.ship))
		self.bullet_sprites = pygame.sprite.Group() #Make a group of bullets
		self.en_bullet_sprites = pygame.sprite.Group() 
		self.enemy_sprites = pygame.sprite.Group() #Groups enemies
		self.backgrounds = pygame.sprite.Group()
		self.explosion_sprites = pygame.sprite.Group()
		self.ship_lives_sprites = LivesGroup(self.LIVES)
		self.last_death_rect = self.ship.rect
		self.font = pygame.font.Font(None, Settings.FONT_SIZE) #No specific font, size
		
	def updateSprites(self):
		self.ship.update()
		self.bullet_sprites.update()
		self.en_bullet_sprites.update()
		self.backgrounds.update()
		self.enemy_sprites.update()
		for enemy in self.enemy_sprites: #Update player pos for all enemies
			enemy.setPlayerPos(self.ship.rect.x, self.ship.rect.y)
			if len(enemy.bullet_queue) > 0: #Move bullets from enemy bullet queue to render group
				for en_bullet in enemy.bullet_queue:
					self.en_bullet_sprites.add(en_bullet)
					enemy.bullet_queue.remove(en_bullet)
		self.explosion_sprites.update()
		
	def checkShoot(self):
		if self.shoot_ticker > 0:
				self.shoot_ticker -= 1
		if self.shooting and self.shoot_ticker == 0:
				tmp_bullet = Bullet(pygame.Rect(self.ship.rect.x + (self.ship.rect.width/2), self.ship.rect.y, 16, 4))
				tmp_bullet.rect.x = tmp_bullet.rect.x - tmp_bullet.rect.height/2 #center (.height cuz flipped)
				tmp_bullet.image = pygame.transform.rotate(tmp_bullet.image, 90)
				self.bullet_sprites.add(tmp_bullet)
				self.shoot_ticker = self.MAX_SHOOT_TICKER
				

	def spawnEnemies(self):
		#Wave 1
		if self.enemies_killed < Settings.WAVE1_PASS and self.wave1_pass == False:
			if self.spawn_ticker > 0:
				self.spawn_ticker -= 1
			elif self.spawn_ticker == 0:
				new_enemy = Enemy01()
				self.enemy_sprites.add(new_enemy)
开发者ID:spencer-hanson,项目名称:PythonGame,代码行数:70,代码来源:pygame_project.py

示例2:

# 需要导入模块: import Ship [as 别名]
# 或者: from Ship import update [as 别名]
		if event.type == KEYDOWN:
			if event.key == K_DOWN:
				moveDown = True
			if event.key == K_UP:
				 moveUp = True
			if event.key == K_LEFT:
				moveLeft = True
			if event.key == K_RIGHT:
				moveRight = True
				
	if moveUp:
		ship.moveUp(5,1)
	if moveDown:
		ship.moveDown(5,1)
	if moveLeft:
		ship.moveLeft(5,1)
	if moveRight:
		ship.moveRight(5,1)
		
	ship.update()
	windowSurface.fill(WHITE) # colors over everything in window in white
		
	''' Nothing is actually drawn to the screen unless you call blit or a draw command.  After you blit everything is put into a buffer.
		Once you call update the buffer is displayed on the screen'''

	pygame.draw.rect(tempSurface,RED,ship.playerRect) # draws a red rectangle at the top corner of the screen

	windowSurface = tempSurface # tempSurface is a background buffer.  using backgrounds buffers is a more efficient way to display sprites

	if playingGame:
		pygame.display.update() # displays everthing that was drawn to the screen
开发者ID:bjsmith01,项目名称:Hark-Upon-The-Gale,代码行数:33,代码来源:Main.py


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