猫史档案馆


【Python作品分享】方块闯关

用户:QinJerryQinJerry查看:4 回复:2 评论:4 创建时间:2019-08-11T19:22:21


【作品展示】

center_image

 

【作品介绍】

完成了3关。←,→键控制方块移动,如果碰到右边缘下一关,因为没有第4关所以第3关过了是第一关。每天更新!

 

【作品源代码】

#coding:utf-8
import pygame
from pygame.locals import*
bl = list()
pygame.init()
pygame.display.set_caption('方块闯关')
canvas = pygame.display.set_mode((1000,600))
u1 = pygame.font.Font(None,80)
No = 1
bks = 0
x,y,yu,yu2,yu3 = 0,420,0,0,0
text,duo,ui = pygame.font.SysFont('simhei',30),1,y-170
while 1:
    canvas.fi喵))
    pygame.draw.rect(canvas,(0,0,0),(0,450,1000,150))
    if No > 3:
        No = 1
    if No == 2:
        pygame.draw.rect(canvas,(255,255,255),(334,450,333,150))
        if x >= 334 and x < 637 and y >= 420:
            yu3 = -1
            duo = 0
            if y == 630:
                x,duo,yu3,y = 0,1,0,420
    elif No == 3:
        pygame.draw.rect(canvas,(255,0,0),(490,240,20,210))
        pygame.draw.rect(canvas,(0,255,0),(300,350,50,20))
        if x >= 460 and x <= 510 and y >= 210 and y <= 450:
            x = 0
        if y == 370 and x >= 270 and x<= 350:
            yu3 = -1
        elif y == 320 and x >= 270 and x<= 350 and yu3 == -1:
            yu3,bks = 0,1
        elif y == 320 and x < 270 and bks or y == 320 and x > 350 and bks:
            yu3,bks = -1,0
        if x > 270 and x < 301 and y > 320 and y < 370:
            duo = 0
        elif x > 319 and x < 350 and y > 320 and y < 370:
            duo = 0
        else:
            duo = 1
    pygame.draw.rect(canvas,(0,0,255),(x,y,30,30))
    canvas.blit(text.render('关卡'+str(No),1,(0,0,0)),(00,0))
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                yu = 1
            if event.key == K_RIGHT:
                yu2 = 1
            if event.key == K_SPACE and yu3 == 0:
                yu3 = 1
                ui = y-158
        elif event.type == 3:
            if event.key == K_LEFT:
                yu = 0
            if event.key == K_RIGHT:
                yu2 = 0
    if yu and x!=0 and duo:
        x -= 1
    if yu2 and duo:
        x += 1
    if x == 970:
        No += 1
        x = 0
    y -= yu3
    if y == ui:
        yu3 = -1
    elif y == 420:
        yu3 = 0
    pygame.display.update()
    pygame.time.delay(1)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
银天X银天X

哇塞,好厉害,我个py萌新看着痴迷

点赞0


评论


QinJerryQinJerry

更新版本:https://shequ.codemao.cn/community/189331

点赞0


评论