pygame,time
random
_display=pygame.display
COLOR_BLACK=pygame.Color(,,)
COLOR_RED=pygame.Color(,,)
():
window=TANK_P1=SCREEN_HEIGHT=SCREEN_WIDTH=EnemyTank_list=[]
EnemyTank_count=():
():
_display.init()
MainGame.window=_display.set_mode([MainGame.SCREEN_WIDTH,MainGame.SCREEN_HEIGHT])
MainGame.TANK_P1 = Tank(, )
.createEnemyTank()
_display.set_caption()
:
time.sleep()
MainGame.window.fill(COLOR_BLACK)
.getEvent()
MainGame.window.blit(.getTextface(%),(,))
MainGame.TANK_P1.displayTank()
.displayEnemyTank()
MainGame.TANK_P1.stop == :
MainGame.TANK_P1.move()
_display.update()
():
top = i (MainGame.EnemyTank_count):
left = random.randint(, )
speed = random.randint(, )
eTank = EnemyTank(left, top, speed)
MainGame.EnemyTank_list.append(eTank)
():
eTank MainGame.EnemyTank_list:
eTank.displayTank()
eTank.randMove()
():
()
()
(,text):
pygame.font.init()
font=pygame.font.SysFont(,)
textSurface=font.render(text,,COLOR_RED)
textSurface
():
eventList=pygame.event.get()
event eventList:
event.type==pygame.QUIT:
.endGame()
event.type==pygame.KEYDOWN:
event.key==pygame.K_LEFT:
()
MainGame.TANK_P1.direction=MainGame.TANK_P1.stop=event.key==pygame.K_RIGHT:
()
MainGame.TANK_P1.direction=MainGame.TANK_P1.stop=event.key == pygame.K_UP:
()
MainGame.TANK_P1.direction = MainGame.TANK_P1.stop = event.key == pygame.K_DOWN:
()
MainGame.TANK_P1.direction = MainGame.TANK_P1.stop = event.key==pygame.K_SPACE:
()
event.type==pygame.KEYUP:
event.key==pygame.K_LEFT event.key==pygame.K_RIGHT \
event.key == pygame.K_UP event.key==pygame.K_DOWN:
MainGame.TANK_P1.stop=():
(,left,top):
.images={
:pygame.image.load(),
: pygame.image.load(),
: pygame.image.load(),
: pygame.image.load()
}
.direction=.image=.images[.direction]
.rect=.image.get_rect()
.rect.left=left
.rect.top=top
.stop = .speed=():
.image=.images[.direction]
MainGame.window.blit(.image,.rect)
():
.direction==:
.rect.left>:
.rect.left-=.speed
.direction==:
.rect.left+.rect.width<MainGame.SCREEN_WIDTH:
.rect.left+=.speed
.direction==:
.rect.top > :
.rect.top-=.speed
.direction==:
.rect.top + .rect.height< MainGame.SCREEN_HEIGHT:
.rect.top += .speed
():
():
():
(Tank):
():
():
(Tank):
(,left,top,speed):
.images={
:pygame.image.load(),
:pygame.image.load(),
:pygame.image.load(),
:pygame.image.load()
}
.direction=.randDirection()
.image=.images[.direction]
.rect=.image.get_rect()
.rect.left=left
.rect.top=top
.speed=speed
.stop=.step=():
num=random.randint(,)
num==:
num == :
num == :
num == :
():
.step<=:
.direction=.randDirection()
.step=:
.move()
.step-=():
():
():
():
():
():
():
():
():
():
():
():
():
():
():
():
():
__name__==:
MainGame().startGame()
报错
"C:\Program Files (x86)\Python36-32\python.exe" C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py
pygame 2.0.1 (SDL 2.0.14, Python 3.6.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py", line 284, in <module>
MainGame().startGame()
File "C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py", line 28, in startGame
self.createEnemyTank()
File "C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py", line 59, in createEnemyTank
eTank = EnemyTank(left, top, speed)
File "C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py", line 208, in __init__
self.image=self.images[self.direction]
KeyError: None
Process finished with exit code 1
老师,帮我看看是什么原因