日川钢板哟哟 发表于 2020-7-29 15:53:21

推箱子 控制移动衔接问题


代码while 后,控制箱子移动,人物移动不能实现,游戏关卡通过代码已经能实现了
人 :5   箱子: 4目的地:3墙:2   代码中1无实际意义


import pygame
import sys
from pygame.locals import*

pygame.init()
size=width,height=512,512
bg=(255, 255, 255)
window = pygame.display.set_mode(size)

pygame.display.set_caption('推箱子')
window.fill(bg)

wall = pygame.image.load('images/wall.png')
correct_box = pygame.image.load('images/finish.png')
player = pygame.image.load('images/top.png')
box = pygame.image.load('images/box.png')
beijin = pygame.image.load('images/bgg.png')
running=True


while running:
    map_1 = [
             '11222111',
             '11232111',
             '112 2222',
             '2224 432',
             '23 45222',
             '22224211',
             '11123211',
             '11122211'
             ]
   
#2:q 3;m 4;x 5 r
    for i in range(8):
      for j in range(8):

            x = 0 + j * 64
            y = 0 + i * 64

            if map_1 == '2':
                window.blit(wall, (x, y))

            if map_1 == '3':
                window.blit(correct_box, (x, y))

            if map_1 == '4':
                window.blit(box, (x, y))
            
            if map_1 == '5':
                window.blit(player,(x, y))
            

            
      for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            key_pressed = pygame.key.get_pressed()
            i=5
            j=5
            if key_pressed or key_pressed:
                if map_1=='5' and map_1=='4' and map_1!='2' and map_1!='4' :
                  map_1='5'
                  map_1=' '
                  map_1='4'
                  j+=1
                if map_1=='5' and map_1!='4' and map_1=='2':
                  map_1='5'
                  map_1=' '
                  j+=1
            if key_pressed or key_pressed:
                if map_1=='5' and map_1=='4' and map_1!='2' and map_1!='4' :
                  map_1='5'
                  map_1=' '
                  map_1='4'
                  j+=1
                  
                if map_1=='5' and map_1!='4' and map_1=='2':
                  map_1='5'
                  map_1=' '
                  j+=1
            
                           
                  
            

    pygame.display.update()

一抹心尘 发表于 2020-10-31 20:05:34

本帖最后由 一抹心尘 于 2020-10-31 20:07 编辑

我去帮你看看,刚刚我的pygame代码出问题了。
页: [1]
查看完整版本: 推箱子 控制移动衔接问题