|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码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[i][j] == '2':
window.blit(wall, (x, y))
if map_1[i][j] == '3':
window.blit(correct_box, (x, y))
if map_1[i][j] == '4':
window.blit(box, (x, y))
if map_1[i][j] == '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[K_d] or key_pressed[K_RIGHT]:
if map_1[i][j]=='5' and map_1[i][j+1]=='4' and map_1[i][j+1]!='2' and map_1[i][j+2]!='4' :
map_1[i][j+1]='5'
map_1[i][j]=' '
map_1[i][j+2]='4'
j+=1
if map_1[i][j]=='5' and map_1[i][j+1]!='4' and map_1[i][j+1]=='2':
map_1[i][j+1]='5'
map_1[i][j]=' '
j+=1
if key_pressed[K_a] or key_pressed[K_LEFT]:
if map_1[i][j]=='5' and map_1[i][j-1]=='4' and map_1[i][j-1]!='2' and map_1[i][j-2]!='4' :
map_1[i][j-1]='5'
map_1[i][j]=' '
map_1[i][j-2]='4'
j+=1
if map_1[i][j]=='5' and map_1[i][j-1]!='4' and map_1[i][j-1]=='2':
map_1[i][j-1]='5'
map_1[i][j]=' '
j+=1
pygame.display.update()
|
|