本文整理汇总了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
示例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()
示例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
示例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
示例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
示例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
示例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()
示例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)