self.radius = 10
def ballready(self):
#设置球的初始位置、
self.ball_x = self.mouse_x
self.ball_y = self.window_wide-self.rect_wide-self.radius
#绘制球,设置反弹触发条件
pygame.draw.circle(self.game_window,self.ball_color,(self.ball_x,self.ball_y),self.radius)
def ballmove(self):
#绘制球,设置反弹触发条件
pygame.draw.circle(self.game_window,self.ball_color,(self.ball_x,self.ball_y),self.radius)
self.ball_x += self.move_x
self.ball_y -= self.move_y
#调用碰撞检测函数
self.ball_window()
self.ball_rect()
#每接5次球球速增加一倍
if self.distance < self.radius:
self.frequency += 1
if self.frequency == 5:
self.frequency = 0
self.move_x += self.move_x
self.move_y += self.move_y
self.point += self.point
#设置游戏失败条件
if self.ball_y > 520:
self.gameover = self.over_font.render("Game Over",False,(0,0,0))
self.game_window.blit(self.gameover,(100,130))
self.over_sign = 1
class Rect(object):
'''创建球拍类'''
def __init__(self,*args,**kw):
#设置球拍颜色参数
self.rect_color = (255,0,0)
self.rect_length = 100
self.rect_wide = 10
def rectmove(self):
#获取鼠标位置参数
self.mouse_x,self.mouse_y = pygame.mouse.get_pos()
#绘制球拍,限定横向边界
if self.mouse_x >= self.window_length-self.rect_length//2:
self.mouse_x = self.window_length-self.rect_length//2
if self.mouse_x <= self.rect_length//2:
self.mouse_x = self.rect_length//2
pygame.draw.rect(self.game_window,self.rect_color,((self.mouse_x-self.rect_length//2),(self.window_wide-self.rect_wide),self.rect_length,self.rect_wide))
class Brick(object):
def __init__(self,*args,**kw):
#设置砖块颜色参数
self.brick_color = (139,126,102)
self.brick_list = [[1,1,1,1,1,1],[1,1,1,1,1,1],[1,1,1,1,1,1],[1,1,1,1,1,1],[1,1,1,1,1,1]]
self.brick_length = 80
self.brick_wide = 20
def brickarrange(self):
for i in range(5):
for j in range(6):
self.brick_x = j*(self.brick_length+24)
self.brick_y = i*(self.brick_wide+20)+40
if self.brick_list[i][j] == 1:
#绘制砖块
pygame.draw.rect(self.game_window,self.brick_color,(self.brick_x,self.brick_y,self.brick_length,self.brick_wide))
#调用碰撞检测函数
self.ball_brick()
if self.distanceb < self.radius:
self.brick_list[i][j] = 0
self.score += self.point
#设置游戏胜利条件
if self.brick_list == [[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]]:
self.win = self.win_font.render("You Win",False,(0,0,0))
self.game_window.blit(self.win,(100,130))
self.win_sign = 1
class Score(object):
'''创建分数类'''
def __init__(self,*args,**kw):
#设置初始分数
self.score = 0