import pygame
import random
def qiu(bally,speedy,ballx,speedx,r,g,b ):
bally = bally + speedy
ballx = ballx + speedx
if bally < 0:
speedy = 1
if ballx >= chuang_kou_kuan:
speedx = -1
if ballx <= 0:
speedx = 1
if bally >= chuang_kou_gao:
ballx = random.randint(10,590)
bally = 0
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
pygame.draw.circle(chuang_kou, (r, g, b), (ballx, bally), bai_jing)
return bally,speedy,ballx,speedx,r,g,b
r=random.randint(0,255)
g=random.randint(0,255)
b=random.randint(0,255)
ballx=200
bally=0
pygame.init()
chuang_kou_kuan = 600
chuang_kou_gao = 700
chuang_kou=pygame.display.set_mode((chuang_kou_kuan,chuang_kou_gao))
bai_jing=random.randint(20,50)
speedy = 1
speedx = 1
rect_gao=10
rect_kuan=150
banx=300
bany=650
# 设置每多少毫秒电脑响应识别多少次
pygame.key.set_repeat(100,1)
# 文字1.0 设置文字的字体和大小 font
wz1 = pygame.font.SysFont("SimHei",40)
fen_shu=0
while 1>0:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
banx = banx-20
elif event.key == pygame.K_d:
banx = banx+20
elif event.type == pygame.MOUSEMOTION:
banx,bany=event.pos
chuang_kou.fill((1,1,1))
bally,speedy,ballx,speedx,r,g,b = qiu(bally,speedy,ballx,speedx ,r,g,b)
# 板的空气墙
if banx<-40:
banx=5
elif banx>460:
banx=450
# 判断接到小球?
if banx<ballx<banx+rect_kuan and bany<bally<bany+rect_gao:
bally = bany-1
speedy=-1
fen_shu = fen_shu + 1
# 画一个长方形:rect
pygame.draw.rect(chuang_kou,(255,255,255),(banx,bany,rect_kuan,rect_gao))
# 文字2.0 设置字体内容和颜色
wz2 = wz1.render("分数%d"%fen_shu, True, (255,255,255))
# 文字3.0 设置文字位置
chuang_kou.blit(wz2, (400,50))
pygame.display.update()
junjie -接小球游戏3.0
最新推荐文章于 2022-11-07 21:47:41 发布