本文整理汇总了Python中ball.Ball.render方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.render方法的具体用法?Python Ball.render怎么用?Python Ball.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ball.Ball
的用法示例。
在下文中一共展示了Ball.render方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import render [as 别名]
class Game(BaseLoop):
def __init__(self, screen: pygame.Surface):
super(Game, self).__init__(screen)
self.FPSCLOCK = None
self.racket_p1 = Racket(self.screen)
self.racket_p2 = None
self.ball = Ball(self.screen)
def setup(self):
super(Game, self).setup()
pygame.key.set_repeat(100, 20)
self.FPSCLOCK = pygame.time.Clock()
self.racket_p1 = Racket(self.screen)
self.ball = Ball(self.screen)
self.racket_p2 = Racket(self.screen, mode='auto')
def update_screen(self):
super(Game, self).update_screen()
pygame.draw.rect(self.screen, WHITE, ((self.screen.get_width() // 2) - 1, 0, 2,
self.screen.get_height()))
self.racket_p1.render()
self.racket_p2.render()
self.ball.render()
def process_event(self, event: pygame.event):
if event.type == KEYDOWN:
if event.key == CONTROLS[UP]:
self.racket_p1.move(UP)
elif event.key == CONTROLS[DOWN]:
self.racket_p1.move(DOWN)
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
self.LOOP_RUN = False
print('Ending the game...')
def start(self, game_type="one_player"):
print('Starting the game...')
self.game_type = game_type
super(Game, self).start()
while self.LOOP_RUN:
for event in pygame.event.get():
self.process_event(event)
self.update_screen()
self.ball.move(self.racket_p1, self.racket_p2)
self.racket_p2.auto_move(self.ball)
pygame.display.flip()
self.FPSCLOCK.tick(FPS)
示例2:
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import render [as 别名]
if ( leftPaddle.left() < (ball.x + ball.radius) and leftPaddle.right() > (ball.x - ball.radius) ) and ( leftPaddle.top() < (ball.y + ball.radius) and leftPaddle.bottom() > (ball.y - ball.radius) ):
ball.bounce( leftPaddle.top(), leftPaddle.bottom(), leftPaddle.height )
#render half-field line
pygame.draw.line( SURFACE, WHITE, ( WIDTH/2, 0 ), ( WIDTH/2, HEIGHT ) )
#render the paddles
leftPaddle.render(SURFACE)
rightPaddle.render(SURFACE)
#render the ball
ball.update( ball.xspeed, ball.yspeed )
if scored:
pygame.time.wait(2000)
scored = False
ball.render(SURFACE)
#display players score
rightScoreDisplay = font.render( "{0}".format(leftScore), 1, WHITE )
leftScoreDisplay = font.render( "{0}".format(rightScore), 1, WHITE )
SURFACE.blit( rightScoreDisplay, ( 450, 50 ) )
SURFACE.blit( leftScoreDisplay, ( 780, 50 ) )
clock.tick(FPS)
pygame.display.update()
###########end of game loop#############
pygame.quit()
sys.exit()
示例3: Pong
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import render [as 别名]
class Pong(object):
def __init__(self, file1=None, file2=None):
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
self.fps = pygame.time.Clock()
flag = DOUBLEBUF
self.board = pygame.display.set_mode(screenRect, flag)
pygame.display.set_caption('[ --- Pong --- ]')
self.state = 1 # 1 - run, 0 - exit
self.track = Tracking(file1, file2)
self.sound = Sound()
self.p1 = Paddle(self.board, (200,100,100),screenRect)
self.p1.setInitialPostition(0,screenHeight/2)
self.p2 = Paddle(self.board, (100,200,100),screenRect)
self.p2.setInitialPostition(screenWidth-self.p2.get()['width'],screenHeight/2)
self.ball = Ball(self.board, (50,50,250), screenRect, self.sound)
self.ball.setInitialPostition(screenWidth/2,screenHeight/2)
self.arena = Arena(self.board, screenRect)
self.referee = Referee(self.ball, self.p1, self.p2, screenRect, self.sound)
self.t = Thread(target=self.track.run)
#self.track.run()
self.t.start()
self.p1_pos = 0
self.p2_pos = 0
self.loop()
def movep1(self, diry):
'''Player1 moves support'''
self.p1.move(diry)
def movep2(self, diry):
'''Player2 moves support'''
self.p2.move(diry)
def game_exit(self):
exit()
def loop(self):
flaga = 1
while self.state==1:
for event in pygame.event.get():
if event.type==QUIT or (event.type==KEYDOWN and event.key==K_ESCAPE):
self.state=0
keys = pygame.key.get_pressed()
dirp1 = copysign(1, self.track.p1_position - self.p1_pos)
dirp2 = copysign(1, self.track.p2_position - self.p2_pos)
self.p1_pos += dirp1
self.p2_pos += dirp2
self.p1.set(self.track.p1_position+45)
self.p2.set(self.track.p2_position+45)
if keys[K_f]:
pygame.display.toggle_fullscreen()
self.arena.render(self.track.frame)
font = pygame.font.Font("gfx/ATARCC__.TTF",40)
text1 = font.render('P1={}'.format(self.p1.getScore()), True,(200,200,200))
text2 = font.render('P2={}'.format(self.p2.getScore()), True,(200,200,200))
quartWidth = screenWidth/4
self.board.blit(text1,(quartWidth * 1 - quartWidth/2,10))
self.board.blit(text2,(quartWidth * 3 - quartWidth/2,10))
self.p1.render()
self.p2.render()
self.ball.render()
self.referee.judge()
pygame.display.flip() # wyswietlamy obrazki
self.fps.tick(80)
self.track.running = False
self.game_exit()
示例4: __init__
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import render [as 别名]
class Pong:
def __init__(self, width=640, height=480, title="Prog Workshop - Pong!"):
pygame.init()
# Sets key repeat to a max of once every 5 ms
#pygame.key.set_repeat(5, 5)
self.screen = pygame.display.set_mode((width, height))
pygame.display.set_caption(title)
self.clock = pygame.time.Clock()
self.screen = pygame.display.get_surface()
self._running = True
self.player1 = Paddle(0,0,20,100,self)
self.player2 = Paddle(width-20,0,20,100,self)
self.ball = Ball(width/2,height/2,20,20,self)
self.ball.setSpeed(random.random()*14-7, random.random()*14-7)
self.balls = []
self.score = Scoreboard(self, 36)
def handle_event(self, event):
if event.type == pygame.QUIT:
self._running = False
if event.type == pygame.MOUSEBUTTONDOWN:
ball = Ball(self.screen.get_width()/2,self.screen.get_height()/2,20,20,self)
ball.setSpeed(random.random()*14-7, random.random()*14-7)
self.balls.append(ball)
def update_game(self):
keys_pressed = pygame.key.get_pressed()
if keys_pressed[pygame.K_UP]:
self.player2.moveUp()
if keys_pressed[pygame.K_DOWN]:
self.player2.moveDown()
if keys_pressed[pygame.K_w]:
self.player1.moveUp()
if keys_pressed[pygame.K_s]:
self.player1.moveDown()
self.ball.update()
for ball in self.balls:
ball.update()
def render(self):
background = pygame.Surface(self.screen.get_size()).convert()
background.fill((250, 250, 250))
self.screen.blit(background, (0,0))
self.player1.render()
self.player2.render()
self.ball.render()
for ball in self.balls:
ball.render()
self.score.renderScore()
pygame.display.flip()
def start(self):
while self._running:
self.clock.tick(60) # Limit to 60 fps
# Handle events
for event in pygame.event.get():
self.handle_event(event)
# Handle game logic
self.update_game()
# Handle rendering
self.render()
pygame.quit()