本文整理汇总了Python中Ball.Ball.moveBall方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.moveBall方法的具体用法?Python Ball.moveBall怎么用?Python Ball.moveBall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ball.Ball
的用法示例。
在下文中一共展示了Ball.moveBall方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from Ball import Ball [as 别名]
# 或者: from Ball.Ball import moveBall [as 别名]
def run(self):
pygame.init()
pygame.display.set_caption("Greek Pong")
margin = 50
self.player1.reinit(margin, self.gameHeight, self.width)
self.player2.reinit(margin, self.gameHeight, self.width)
player1 = self.player1
player2 = self.player2
ball = Ball(self.width, self.gameHeight, self.screen, self)
black = pygame.Color(0,0,0)
counter = 0
runGame = True
while runGame and self.play:
for event in pygame.event.get():
if (event.type == QUIT):
self.play = False
self.state = False
runGame = False
break
pygame.event.pump()
keys = pygame.key.get_pressed()
mouse = pygame.mouse.get_pressed()
ball.moveBall(self.width, self.gameHeight, player1, player2, self)
player1.movePaddle(keys, self.gameHeight, self.width, ball, self)
player2.movePaddle(keys, self.gameHeight, self.width, ball, self)
player1.useWeaponRack(keys, ball, player2, self)
player2.useWeaponRack(keys, ball, player1, self)
self.checkInstruction(keys)
if counter == 400:
counter = 0
self.redrawAll(player1, player2, ball, counter)
counter += 1
if (self.checkWin(player1, player2)):
runGame = False
break
示例2: __init__
# 需要导入模块: from Ball import Ball [as 别名]
# 或者: from Ball.Ball import moveBall [as 别名]
#.........这里部分代码省略.........
sleep(3)
self.tier.undraw()
self.wow.undraw()
return True
else:
return False
def gameOver(self):
# If the ball goes past the paddle, the game is over and the user is asked to play again
xCenter = self.b.getCenter().getX()
xBallLeft = xCenter - self.b.getRadius()
xCenter2 = self.b.getCenter2().getX()
xBallLeft2 = xCenter2 - self.b.getRadius2()
xMiddle = self.p.getMiddle().getX()
xPadRight = xMiddle + 5
if (xBallLeft > xPadRight) or (xBallLeft2 > xPadRight):
loser = Text(Point(250, 150), "GAME OVER!")
loser.setSize(25)
loser.setTextColor("red")
again = Text(Point(250, 200), "PLAY AGAIN?")
again.setSize(25)
again.setTextColor("red")
loser.draw(self.pWin)
again.draw(self.pWin)
return True
def restart(self):
# If the player types 'yes', the game will restart completely
restart = input("\nWould You Like To Restart (yes/no)? ")
if restart.lower() == "yes":
self.pWin.close()
newGame = Pong()
print("WARNING!! IN SHRINKING MODE, PADDLE RESETS TO MIDDLE AFTER EACH LEVEL")
game = input("Which version would you like to play: 'shrinking mode' (s), 'multiple mode' (m), or 'normal mode' (n)? ")
newGame.play(game)
else:
self.pWin.close()
def play(self, ans):
# The user will be given 3 seconds after asked to play until the game begins
sleep(1)
self.ready = Text(Point(250, 81), "Are You Ready?")
self.ready.setSize(30)
self.ready.setTextColor("red")
self.ready.draw(self.pWin)
self.three = Text(Point(250, 200), "THREE")
self.three.setSize(35)
self.three.setTextColor("white")
self.three.draw(self.pWin)
sleep(1)
self.three.undraw()
self.two = Text(Point(250, 200), "TWO")
self.two.setSize(35)
self.two.setTextColor("white")
self.two.draw(self.pWin)
sleep(1)
self.two.undraw()
self.one = Text(Point(250, 200), "ONE")
self.one.setSize(35)
self.one.setTextColor("white")
self.one.draw(self.pWin)
sleep(1)
self.one.undraw()
self.ready.undraw()
while True:
click = self.pWin.checkMouse()
if click != None:
self.p.movePad(click)
if ans.lower() == 's':
if self.checkContactShrink():
self.b.reverseX()
elif ans.lower() == 'm':
if self.checkContactBallA():
self.b.reverseX()
if self.checkContactBallB():
self.b.reverse2X()
self.b.moveBall2(self.pWin)
elif ans.lower() == 'n':
if self.checkContact():
self.b.reverseX()
else:
print("\nOh Well, I Didn't Want To Play With You Anyway!")
self.b.moveBall(self.pWin)
if self.gameOver():
self.restart()