import pygame as pg
import sys
import random
a,b=2,2
pg.init()
size=width,height=1500,900
bg=(0,0,0)
count=0
screen=pg.display.set_mode(size)
pg.display.set_caption("接球")
image=pg.image.load('.//img//3.png').convert_alpha()
font=pg.font.SysFont('SimHei',60)
text=font.render("你输了", True, (0,255,0))
position=image.get_rect(centerx=600,centery=200)
color=(255,0,0)
while True:
for event in pg.event.get():
if event.type==pg.QUIT:
sys.exit()
posx=pg.mouse.get_pos()[0]-200
screen.fill(bg)
if 0<posx<=width-400:
pos=[posx,870,400,30]
rect=pg.draw.rect(screen,color,pos)
position=position.move(a,b)
if position.right>width:
a=-random.randint(5,15)
# a=-a
elif position.left<0:
a=random.randint(5,15)
if position.top<0:
b=random.randint(5,15)
# flag=pg.Rect.collidelistall(position,rect)
flag= pg.Rect.colliderect(position,rect)
if flag and 872<position.bottom<900:
count+=100
b=-random.randint(5,15)
elif position.bottom>=900:
screen.blit(text,(650,350))
text2 = font.render("分数:%d" % count, True, (0, 255, 0))
screen.blit(text2, (1200, 0))
# if position.bottom
# if position.bottom>=900:
screen.blit(image,position)
pg.display.flip()
pg.time.delay(5)