猫史档案馆


【Python作品分享】fire【作品秀】

用户:耐心的胆小菇N_vj耐心的胆小菇N_vj查看:0 回复:1 评论:0 创建时间:2021-07-12T11:32:27


【作品展示】

center_image

 

【作品介绍】

利用pygame让方块移动,各位拿去用

 

【作品源代码】

import pygame
import sys
import random
import time


# 绘制
rect_x = 40
rect_y = 40
x_rect1 = 40
y_rect1 = 40
x_rect2 = 420
y_rect2 = 420
fire1 = x_rect1+5, y_rect1, 10, 10
fire2 = x_rect2+5, y_rect2, 10, 10
No_1 = (12*rect_x), (12*rect_y)
food_math = 0
score = 0
# 初始化
pygame.init()

def fire_a():

    pygame.draw.rect(screen_no_1, (200, 200, 200),(fire1), (00))

def fire_b():

    pygame.draw.rect(screen_no_1, (200, 200, 200),(fire2), (00))

def wall():

    pygame.draw.rect(screen_no_1, (255, 0, 0),(360, 360, 40, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(80, 80, 40, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 40, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 80, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 120, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 160, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 200, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 240, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 280, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 320, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 360, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 400, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 440, 3, 40), (00))
    # #####################
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 0, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 40, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 80, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 120, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 160, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 200, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 240, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 280, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 320, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 360, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 400, 3, 40), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(478, 440, 3, 40), (00))
    # #######################
    pygame.draw.rect(screen_no_1, (255, 0, 0),(40, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(80, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(120, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(160, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(200, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(240, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(280, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(320, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(360, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(400, 478, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(440, 478, 40, 3), (00))
    # ###################
    pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(40, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(80, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(120, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(160, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(200, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(240, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(280, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(320, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(360, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(400, 0, 40, 3), (00))
    pygame.draw.rect(screen_no_1, (255, 0, 0),(440, 0, 40, 3), (00))

myfont = pygame.font.Font(None, 60)
screen_no_1 = pygame.display.set_mode(No_1)
darw_rect = pygame.display.set_caption('the fire')
# 绘制图形

def puzzle_b():

    pygame.draw.rect(screen_no_1, (255, 255, 0),(x_rect1, y_rect1, 20, 20), (00))

def player_b():

    pygame.draw.rect(screen_no_1, (0, 0, 200),(x_rect2, y_rect2, 20, 20), (00))

starttime = time.time()
puzzle_b()
player_b()
wall()
clock = pygame.time.Clock()
quit = True
pygame.draw.rect(screen_no_1, (255, 0, 0),(0, 0, 3, 40), (00))
while quit:
    print('计时: ', round((time.time() - starttime), 0), '秒', end = '"\r"')
    for event in pygame.event.get():
        if (event.type == pygame.QUIT):
            quit = False
            pygame.quit()
            #
        if (event.type == pygame.KEYDOWN):
            #
            if (event.key == pygame.K_ESCAPE):
                sys.exit()
            if (event.key == pygame.K_d):
                pygame.draw.rect(screen_no_1, (0, 0, 0),(x_rect1, y_rect1, 20, 20), (00))
                x_rect1 += 20
                puzzle_b()
            if (event.key == pygame.K_a):
                pygame.draw.rect(screen_no_1, (0, 0, 0),(x_rect1, y_rect1, 20, 20), (00))
                x_rect1 -= 20
                puzzle_b()
            if (event.key == pygame.K_w):
                pygame.draw.rect(screen_no_1, (0, 0, 0),(x_rect1, y_rect1, 20, 20), (00))
                y_rect1 -= 20
                puzzle_b()
            if (event.key == pygame.K_s):
                pygame.draw.rect(screen_no_1, (0, 0, 0),(x_rect1, y_rect1, 20, 20), (00))
                y_rect1 += 20
                puzzle_b()
                #
            if (event.key == pygame.K_RIGHT):
                pygame.draw.rect(screen_no_1, (0, 0, 0),(x_rect2, y_rect2, 20, 20), (00))
                x_rect2 += 20
                player_b()
            if (event.key == pygame.K_LEFT):
                pygame.draw.rect(screen_no_1, (0, 0, 0),(x_rect2, y_rect2, 20, 20), (00))
                x_rect2 -= 20
                player_b()
            if (event.key == pygame.K_UP):
                pygame.draw.rect(screen_no_1, (0, 0, 0),(x_rect2, y_rect2, 20, 20), (00))
                y_rect2 -= 20
                player_b()
            if (event.key == pygame.K_DOWN):
                pygame.draw.rect(screen_no_1, (0, 0, 0),(x_rect2, y_rect2, 20, 20), (00))
                y_rect2 += 20
                player_b()
    if (x_rect1 == 80 and y_rect1 == 80):
        x_rect1 -= 20
        pygame.display.update()
    if (x_rect2 == 360 and y_rect2 == 360):
        x_rect2 += 20
        pygame.display.update()
    wall()
    fire_a()
    fire_b()
    clock.tick(30)
    pygame.display.update()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
耐心的胆小菇N_vj耐心的胆小菇N_vj

emotion_编程猫_翻白眼

点赞0


评论