用户:
群星_终章查看:0 回复:0 评论:0 创建时间:2023-08-11T18:15:36
【作品展示】

【作品介绍】
游戏的规则非常简单,逃跑者要收集四个线索打开大门逃出去,如果被抓捕者抓到就输了,输了就会退出。你听懂了吗?管你听没听懂,看就完了
【作品源代码】
import pygame
pygame.init()
time = 180
j=0
xs=0
x=0
y=0
x1=770
y1=590
font=pygame.font.SysFont('simhei',20,False,True)#创造笔
jishi=font.render('倒计时:'+str(time),True,(0,0,0))
xiansuo = font.render('线索:'+str(j), True, (0, 0, 0))
screen = pygame.display.set_mode((800, 600), pygame.RESIZABLE)
screen.fill((255,255,255))
screen.blit(jishi,(650,0))
screen.blit(xiansuo, (650, 20))
pygame.display.update()
tpz=pygame.Rect(x,y,10,10)
zbz=pygame.Rect(x1,y1,10,10)
t1=pygame.time.get_ticks()#标记时间点
pygame.key.set_repeat(100,10)#开启重复按按键
xs1 = pygame.Rect(350, 50, 10, 10)
xs2 = pygame.Rect(250, 320, 10, 10)
xs3 = pygame.Rect(530, 20, 10, 10)
xs4 = pygame.Rect(430, 450, 10, 10)
dm = pygame.Rect(790, 590, 10, 10)
pygame.display.set_caption('他逃,他追,他插翅难飞')#窗口的名字
while True:
t2=pygame.time.get_ticks()#与第20行相连,创建另一个时间点,两个时间点相差如果大于或等于1000毫秒,代表过了1秒
if t2-t1>=1000:
time=time-1
t1=t2
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
a = pygame.key.get_pressed()#获取按键状态
if a[pygame.K_w]:
y = y-0.18
if a[pygame.K_s]:
y = y+0.18
if a[pygame.K_d]:
x = x+0.18
if a[pygame.K_a]:
x = x-0.18
if a[pygame.K_UP]:
y1 = y1-0.2
if a[pygame.K_DOWN]:
y1 = y1+0.2
if a[pygame.K_LEFT]:
x1 = x1-0.2
if a[pygame.K_RIGHT]:
x1 = x1+0.2
if tpz.colliderect(xs1):
j=j+1
xs1.center = (1000,1000)
if tpz.colliderect(xs2):
j = j+1
xs2.center = (1000, 1000)
if tpz.colliderect(xs3):
j = j+1
xs3.center = (1000, 1000)
if tpz.colliderect(xs4):
j = j+1
xs4.center = (1000, 1000)
if tpz.colliderect(zbz):
print('逃跑者失败,被抓捕者抓到了')
exit()
if tpz.colliderect(dm):
if j>=4:
print('抓捕者失败,逃跑者逃走了')
exit()
elif j<4:
pass
if time<=0:
print('抓捕者失败,FBI来了')
exit()
jishi = font.render('倒计时:'+str(time), True, (0, 0, 0))
xiansuo = font.render('线索:'+str(j), True, (0, 0, 0))
tpz = pygame.Rect(x, y, 10, 10)
zbz=pygame.Rect(x1,y1,10,10)
screen.fill((255, 255, 255))
pygame.draw.rect(screen, (255, 0, 0), tpz)
pygame.draw.rect(screen, (0, 0, 255), zbz)
pygame.draw.rect(screen, (96, 96, 96), xs1)
pygame.draw.rect(screen, (96, 96, 96), xs2)
pygame.draw.rect(screen, (96, 96, 96), xs3)
pygame.draw.rect(screen, (96, 96, 96), xs4)
pygame.draw.rect(screen, (0, 0, 0), dm)
screen.blit(jishi, (650, 0))
screen.blit(xiansuo, (650, 20))
pygame.display.update()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn