我一直在和几个朋友一起测试pygame,而且我们遇到了一个问题,即当玩家踩到尖峰时加载的desthscreen就不会加载。 if语句肯定会触发,如果不在if语句中,则创建死亡屏幕的命令有效。我们不知道问题是什么。
如果你想让纹理在这里下载:
https://drive.google.com/folderview?id=0B57S6Qow33ZrYS02Rk5ZQnVzNFk&usp=sharing
以下是代码:
import pygame, sys, time, random
from pygame.locals import *
pygame.init()
#cloud position
cloudx = -600
cloudy = 0
fpsClock = pygame.time.Clock()
#Dimensions
TILESIZE=40
SCREENWIDTH=15
SCREENHEIGHT=12
#Display Surface
Screen = pygame.display.set_mode((SCREENWIDTH*TILESIZE,SCREENHEIGHT*TILESIZE))
pygame.display.set_caption("Game")
#Player-controlled Character
PLAYER = pygame.image.load("Character1.png").convert_alpha()
PlayerPos = [8,6]
SPEED = 0.1
CanMove = True
pygame.key.set_repeat(1, 30)
#Materials
O = 0
RFLOOR1 = 1
RWUP1 = 2
RWDOWN1 = 3
RWLEFT1 = 4
RWRIGHT1 = 5
RWUPLEFT1 = 6
RWUPRIGHT1 = 7
RWDOWNLEFT1 = 8
RWDOWNRIGHT1 = 9
RFLOORDOOR1 = 10
RWUPDOOR1 = 11
RWDOWNDOOR1 = 12
RWLEFTDOOR1 = 13
RWRIGHTDOOR1 = 14
CLOUD = 15
SONIC = 16
DEATHSCREEN = 17
SPIKES = 18
#Textures
textures = {O : pygame.image.load("Black.png"),
RFLOOR1 : pygame.image.load("RockFloor1.png"),
RWUP1 : pygame.image.load("RockWallUp1.png"),
RWDOWN1 : pygame.image.load("RockWallDown1.png"),
RWLEFT1 : pygame.image.load("RockWallLeft1.png"),
RWRIGHT1 : pygame.image.load("RockWallRight1.png"),
RWUPLEFT1 : pygame.image.load("RockWallUpLeft1.png"),
RWUPRIGHT1 : pygame.image.load("RockWallUpRight1.png"),
RWDOWNLEFT1 : pygame.image.load("RockWallDownLeft1.png"),
RWDOWNRIGHT1 : pygame.image.load("RockWallDownRight1.png"),
RFLOORDOOR1 : pygame.image.load("RockFloorDoor1.png"),
RWUPDOOR1 : pygame.image.load("RockWallUpDoor1.png"),
RWDOWNDOOR1 : pygame.image.load("RockWallDownDoor1.png"),
RWLEFTDOOR1 : pygame.image.load("RockWallLeftDoor1.png"),
RWRIGHTDOOR1 : pygame.image.load("RockWallRightDoor1.png"),
CLOUD : pygame.image.load("cloud.png"),
SONIC : pygame.image.load("sonic.png"),
DEATHSCREEN : pygame.image.load("DeathScreen.png"),
SPIKES : pygame.image.load("Spikes.png")
}
#Room1
room1Tilemap = [[O, O, O, O, O, O, O, O, O, O, O, O, O, O, O],
[0, O, O, O, O, O, O, O, O, O, O, O, O, O, O],
[O, O, RWUPLEFT1, RWUP1, RWUP1, RWUP1, RWUP1, RWUPDOOR1, RWUP1, RWUP1, RWUP1, RWUP1, RWUPRIGHT1, O, O],
[O, O, RWLEFT1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RWRIGHT1, O, O],
[O, O, RWLEFT1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RWRIGHT1, O, O],
[O, O, RWLEFT1, RFLOOR1, SPIKES, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, SONIC, RFLOOR1, RWRIGHT1, O, O],
[O, O, RWLEFT1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RWRIGHT1, O, O],
[O, O, RWLEFT1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RWRIGHT1, O, O],
[O, O, RWLEFT1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RFLOOR1, RWRIGHT1, O, O],
[O, O, RWDOWNLEFT1, RWDOWN1, RWDOWN1, RWDOWN1, RWDOWN1, RWDOWN1, RWDOWN1, RWDOWN1, RWDOWN1, RWDOWN1, RWDOWNRIGHT1, O, O],
[O, O, O, O, O, O, O , O, O, O, O, O, O, O, O],
[O, O, O, O, O, O, O, O, O, O, O, O, O, O, O]]
room1UpBound = 2.5
room1DownBound = 8.5
room1LeftBound = 2.5
room1RightBound = 11.5
#Tilemap Settings
tilemap = room1Tilemap
UpBound = room1UpBound
DownBound = room1DownBound
LeftBound = room1LeftBound
RightBound = room1RightBound
#Main Loop
while True:
if (PlayerPos[1] > 5 and PlayerPos[1] <6 and PlayerPos[0] > 9 and PlayerPos[0] <10):
SPEED = 0.5
if (PlayerPos[1] > 5 and PlayerPos[1] <6 and PlayerPos[0] > 4 and PlayerPos[0] <5):
Screen.blit(textures[DEATHSCREEN],(0,0))
print (PlayerPos)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if CanMove == True:
keys = pygame.key.get_pressed()
if keys[K_w] and PlayerPos[1] > UpBound:
PlayerPos[1] -= SPEED
if keys[K_s] and PlayerPos[1] < DownBound:
PlayerPos[1] += SPEED
if keys[K_a] and PlayerPos[0] > LeftBound:
PlayerPos[0] -= SPEED
if keys[K_d] and PlayerPos[0] < RightBound:
PlayerPos[0] += SPEED
for row in range(SCREENHEIGHT):
for column in range(SCREENWIDTH):
Screen.blit(textures[tilemap[row][column]], (column*TILESIZE,row*TILESIZE))
Screen.blit(PLAYER,(PlayerPos[0]*TILESIZE,PlayerPos[1]*TILESIZE))
Screen.blit(textures[CLOUD].convert_alpha(),(cloudx,cloudy))
cloudx+=1
if cloudx > (0):
cloudx = -600
cloudy = 0
pygame.display.update()
fpsClock.tick(24)
答案 0 :(得分:0)
你只是用瓷砖透过你的屏幕。 只需在你的循环结束处的某个地方移动你的死屏幕blit,它就会起作用&#34;:
#...
Screen.blit(PLAYER,(PlayerPos[0]*TILESIZE,PlayerPos[1]*TILESIZE))
Screen.blit(textures[CLOUD].convert_alpha(),(cloudx,cloudy))
if (PlayerPos[1] > 5 and PlayerPos[1] <6 and PlayerPos[0] > 4 and PlayerPos[0] <5):
Screen.blit(textures[DEATHSCREEN],(0,0))
cloudx += 1
#...