用户:
QinJerry查看:0 回复:0 评论:0 创建时间:2019-07-11T14:03:49
【作品展示】

【作品介绍】
鼠标控制,把球给弹回去!
【作品源代码】
#coding:utf-8
#参考:https://blog.csdn.net/Hubz131/article/details/86749253
import pygame,sys,random
from pygame.locals import*
pygame.init()
canvas = pygame.display.set_mode([1000,600])
pygame.display.set_caption('弹弹球(鼠标控制)')
x,y = 0,0
p,why,life=1,0,3
oo,number,number1,oo3,score = pygame.font.SysFont('simhei',17),2,8,1,0
while 1:
oo1 = oo.render('生命:'+str(life),1,(0,0,0))
if life != 0:
x1,y1 = pygame.mouse.get_pos()
pygame.draw.rect(canvas,(255,255,255),[0,0,1000,600])
if p:
pp = number
pp1=pp
p-=1
if y > 600-5:
why = 1
if y<=0+5:
why = 0
if why:
y -= pp+oo3
else:
y+=pp+oo3
if x<=5:
p = 1
x = x+pp1
if x+5>=750 and y > y1-65 and y< y1 + 130:
pp1 = -pp1
number1 +=1
score +=1
if number1%9==0:
number+=1
if life<1:
pp,pp1,oo3 = 0,0,0
canvas.blit(pygame.font.SysFont('微软雅黑',100).render('Game over',1,(0,0,0)),(299,208))
if x>=755:
if life != 0:
life -= 1
if life > 0:
x,y,p = 0,0,1
pygame.draw.rect(canvas,(0,0,0),[755,y1-65,25,130])
pygame.draw.line(canvas,[0,0,0], (500,40), (500,540), 1)
pygame.draw.circle(canvas,[131,95,184],[x,y],10)
canvas.blit(oo1,[0,0])
canvas.blit(oo.render('分数(按右键5分换1血):'+str(score),1,[0,0,0]),[0,17])
for event in pygame.event.get():
if event.type == 12:
sys.exit()
elif event.type == MOUSEBUTTONDOWN and event.button == 1 and score > 4 and life > 0:
score -= 5
life += 1
if event.type == MOUSEBUTTONDOWN and event.button == 3 and life == 0:
x,y,life,score,oo3,number = 0,0,3,0,1,2
pygame.display.update()
pygame.time.delay(4)
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn