import pygame
import random
# 1.loading 初始化
pygame.init()
# 2.窗口 dis分开 play玩 ----》 展示
screen_width = 960
screen_height = 540
screen = pygame.display.set_mode((screen_width, screen_height ))
# 3.游戏名字 caption标题
pygame.display.set_caption("接小球游戏")
ballx1 = 350
bally1 =300
color1 = (200,200,200)
r1 = 50
ban_x, ban_y,ban_width,ban_height = 400,screen_height-50,220,100
score = 0 # f分数
live = 3
font = pygame.font.Font("ziti.ttf", 24)
# 1.加载图片 image
qiu = pygame.image.load("cai.png")
qiu2 = pygame.image.load("qiu.jpg")
beijing=pygame.image.load('bg3.jpg')
# 速度
speed = 1
# 事件
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
# 4.退出
pygame.quit()
elif event.type == pygame.MOUSEMOTION:
ban_x, a = event.pos # pos ---> position 位置
# 填充屏幕颜色
# screen.fill((255, 255, 255)) # rgb 三基色red green blue
screen.blit(beijing, (0, 0))
bally1 += speed
# ballx1 += 1
if bally1>screen_height:
live = live -1
bally1=0
ballx1=random.randint(0,screen_width)
color1 = (random.randint(0,255),random.randint(0,255),random.randint(0,255))
r1 = random.randint(20,40)
if speed>1:
speed=speed-1
# 判断生命值是否用完
if live<=0:
pygame.quit()
# 判断常伴接到小球 撤销 ctrl + z
if ban_x<ballx1<ban_x+ban_width and ban_y<bally1<ban_y+ban_height:
score = score+1
speed=speed+1
bally1 = 0
ballx1 = random.randint(0, screen_width-100)
score_text = font.render("分数:%d"%score,True,(255,255,255) )
screen.blit(score_text,(10,10))
live_text = font.render("生命值:%d" % live, True, (255, 255, 255))
screen.blit(live_text, (10, 40))
# 画圆
# pygame.draw.circle(screen,color1,(ballx1, bally1),r1)
if score<10:
screen.blit(qiu,(ballx1, bally1))
else:
screen.blit(qiu2,(ballx1,bally1))
# 画长方形 rect
pygame.draw.rect(screen,(240,197,105),(ban_x, ban_y,ban_width,ban_height ) )
# 3.刷新
pygame.display.update()
kewin -接小球终极版
最新推荐文章于 2020-01-12 14:45:13 发布