當前位置: 首頁>>代碼示例>>Python>>正文


Python Ball.speed[1]方法代碼示例

本文整理匯總了Python中Ball.Ball.speed[1]方法的典型用法代碼示例。如果您正苦於以下問題:Python Ball.speed[1]方法的具體用法?Python Ball.speed[1]怎麽用?Python Ball.speed[1]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Ball.Ball的用法示例。


在下文中一共展示了Ball.speed[1]方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: loopGame

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import speed[1] [as 別名]
  def loopGame(self):
		clock = pygame.time.Clock()
		ball = Ball([100,100])
		paddle = Paddle([width/2,395])
		font = pygame.font.Font(None, 25)
		sound_collision = pygame.mixer.Sound("music/tick.mp3")
		vector = []
		posRectx = 90
		posRecty = 60
		score = 0
		for i in range(0, 50):
			if(i%5==0):
				posRecty = posRecty + 20
				posRectx = 80
			else:
				posRectx = posRectx + 80
				rectColid = RectColid([posRectx,posRecty])
				vector.append(rectColid)

		running_game = True
		while running_game:
			clock.tick(120)

			textoScore = font.render("Score: %d" % score, True, white)

			for event in pygame.event.get():
				if event.type==QUIT:
					running_game = False

			keys = pygame.key.get_pressed()

			if keys[K_a]:
				paddle.imagerect.centerx -= 5
			if keys[K_d]:
				paddle.imagerect.centerx += 5

			if paddle.imagerect.colliderect(ball.imagerect):
				if ball.speed[1] > 0:
					ball.speed[1] = -ball.speed[1]

			for rect in vector:
				if rect.imagerect.colliderect(ball.imagerect):
					vector.remove(rect)
					ball.speed[1] = -ball.speed[1]
					sound_collision.play(1)
					score += 1

			ball.update()
			paddle.update()

			screen.fill(black)
			screen.blit(ball.image, ball.imagerect)
			screen.blit(paddle.image, paddle.imagerect)
			#Coloca os objetos na tela
			for rect in vector:
				screen.blit(rect.image, rect.imagerect)
			screen.blit(textoScore, [10, 10])

			pygame.display.flip()
開發者ID:ruiter,項目名稱:game,代碼行數:61,代碼來源:Game.py


注:本文中的Ball.Ball.speed[1]方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。