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


Python Ball.update方法代碼示例

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


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

示例1: update

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import update [as 別名]
 def update(*args):
     self = args[0]
     width = args[1]
     height = args[2]
     Ball.update(self, width, height)
     self.animate()
     self.changed = False
開發者ID:KRHS-GameProgramming-2014,項目名稱:The-Dot-Eater,代碼行數:9,代碼來源:PlayerBall.py

示例2: loopGame

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import update [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

示例3: update

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import update [as 別名]
 def update(*args):
     self = args[0]
     width = args[1]
     height = args[2]
     playerPos = args[3]
     self.facePlayer(playerPos)
     Ball.update(self, width, height)
     self.animate()
     self.changed = False
開發者ID:KRHS-GameProgramming-2014,項目名稱:adventure-swag,代碼行數:11,代碼來源:Zombie.py

示例4: update

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import update [as 別名]
 def update(*args):
     self = args[0]
     width = args[1]
     height = args[2]
     Ball.update(self, width, height,)
     self.move()
     if self.life > 0:
         self.life -= 1
     else:
         self.living = False
開發者ID:KRHS-GameProgramming-2014,項目名稱:adventure-swag,代碼行數:12,代碼來源:Bullet.py

示例5: update

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import update [as 別名]
 def update(*args):
     self = args[0]
     width = args[1]
     height = args[2]
     Ball.update(self, width, height)
     self.move()
     self.animate()
     self.changed = False
     #print self.gun.coolDown
     if self.gun.coolDown > 0:
         if self.gun.coolDown < self.gun.coolDownMax:
             self.gun.coolDown += 1
         else:
             self.gun.coolDown = 0
     if self.hurtTimer > 0:
         self.hurtTimer -= 1
         self.invincible = True
     else:
         self.invincible = False
開發者ID:KRHS-GameProgramming-2014,項目名稱:adventure-swag,代碼行數:21,代碼來源:Player.py

示例6: update

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import update [as 別名]
	def update(self, width, height):
		Ball.update(self, width, height)
		self.animate()
		self.changed = False
開發者ID:KRHS-GameProgramming-2014,項目名稱:SUPER-AWESOME-NINJA-GAME,代碼行數:6,代碼來源:Ninja.py

示例7: Breakout

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import update [as 別名]
class Breakout(object):
    def __init__(self):
        # Initilaize pygame and the display/window
        pygame.init()
        self.width, self.height = 600, 800
        self.screen = pygame.display.set_mode((self.width, self.height)) #, pygame.FULLSCREEN)
        pygame.display.set_caption('Breakout')
        # background = pygame.image.load("PiInvaders/background.png").convert();

        # Create the game objects
        self.ball = Ball(self.width / 2, self.height - 32)
        self.paddle = Paddle(self.width / 2, self.height - 16, 80, 16)

    def new_game(self):
        """Start a new game of Breakout

        Resets all game level parameters, and starts a new round."""
        self.game_over = False
        self.round = 0

        self.new_round()

    def new_round(self):
        """Start a new round in a Breakout game

        Resets all round level parameters, increments the round counter, and
        puts the ball on the paddle, centering both."""
        self.round += 1
        self.ball_is_moving = False
        self.ball.x_velocity = random.randint(-3, 3)
        self.paddle.x = self.width / 2
        self.ball.y = self.height - 32

    def play(self):
        """Start Breakout game

        New game is started and game loop is entered.
        The game loop checks for events, updates all objects, and then
        draws all the objects."""
        self.new_game()
        while not self.game_over:           # Game loop
            for event in pygame.event.get():
                if event.type == pygame.QUIT or event.type == pygame.MOUSEBUTTONDOWN:
                    self.game_over = True
                    break
                if event.type == pygame.KEYDOWN:
                    if not self.ball_is_moving and event.key == pygame.K_SPACE:
                        self.ball_is_moving = True
                    if event.key == pygame.K_LEFT:
                        self.paddle.x_velocity = -4
                    elif event.key == pygame.K_RIGHT:
                        self.paddle.x_velocity = 4

                    # This starts a new round, it's only here for debugging purposes
                    if event.key == pygame.K_r:
                        self.new_round()
                    # This starts a new game, it's only here for debugging purposes
                    if event.key == pygame.K_g:
                        self.new_game()
                if event.type == pygame.KEYUP:
                    if event.key == pygame.K_LEFT and self.paddle.x_velocity < 0:
                        self.paddle.x_velocity = 0
                    if event.key == pygame.K_RIGHT and self.paddle.x_velocity > 0:
                        self.paddle.x_velocity = 0
            else:
                self.paddle.update()
                if self.ball_is_moving:
                    self.ball.update()
                else:
                    self.ball.x = self.paddle.x

                self.screen.fill((0, 0, 0))
                self.paddle.draw(pygame, self.screen)
                self.ball.draw(pygame, self.screen)
                
                pygame.display.flip()

        pygame.quit()
開發者ID:artlogic,項目名稱:breakout,代碼行數:80,代碼來源:breakout.py

示例8: __init__

# 需要導入模塊: from Ball import Ball [as 別名]
# 或者: from Ball.Ball import update [as 別名]
class BrickBreakGame:
	def __init__(self, w=800, h=600):
		if platform.system() == 'Windows':
		    os.environ['SDL_VIDEODRIVER'] = 'windib'
		os.environ['SDL_VIDEO_WINDOW_POS'] = "100,100"
		pygame.init()
		self.clock = pygame.time.Clock()
		self.window = pygame.display.set_mode((w, h), pygame.DOUBLEBUF|pygame.HWSURFACE)
		pygame.display.set_caption('Brick Break!')

		self.ship = Ship(w/2, h-14)
		self.ball = Ball((self.ship.x, self.ship.y-self.ship.height/2), (400., 0.))
		self.backgroundColor = pygame.Color(255,255,255)

		pygame.mouse.set_visible(False)
		pygame.mouse.set_pos(100+w/2, 100+h/2)

		self.blocks = BlockArray(16,11) 
		self.shipx = pygame.mouse.get_pos()[0]
		self.goLeft = self.goRight = False


	def run(self):
		while True:
			self.mainLoop()

	def mainLoop(self):
		#EVENTS
		for event in pygame.event.get():
			if event.type == MOUSEMOTION:
				self.shipx = event.pos[0]
			elif event.type == KEYDOWN:
				if event.key == K_LEFT:
					self.goLeft = True
				elif event.key == K_RIGHT:
					self.goRight = True
				elif event.key == K_ESCAPE:
					pygame.event.post(pygame.event.Event(QUIT))
			elif event.type == KEYUP:
				if event.key == K_LEFT:
					self.goLeft = False
				elif event.key == K_RIGHT:
					self.goRight = False
			elif event.type == QUIT:
				pygame.quit()
				sys.exit(0)

		if self.goLeft:
			self.shipx -= self.clock.get_time()*2/3
		elif self.goRight:
			self.shipx += self.clock.get_time()*2/3

		#LOGIC
		self.ball.update(self.clock.get_time()/1000., self.window)
		self.ship.update(self.shipx)
		self.blocks.update(self.ball)
		self.ship.checkBallCollision(self.ball)

		if self.ball.y > self.window.get_height():
			pygame.event.post(pygame.event.Event(QUIT))

		#DRAW
		self.window.fill(self.backgroundColor)
		self.blocks.draw(self.window)
		self.ship.draw(self.window)
		self.ball.draw(self.window)

		pygame.display.update()
		self.clock.tick(60)
開發者ID:rhaps0dy,項目名稱:pyBrickBreak,代碼行數:71,代碼來源:brickbreak.py


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