pygame
time
random
SCREEN_WIDTH=SCREEN_HEIGHT=BG_COLOR=pygame.Color()
TEXT_COLOR=pygame.Color()
MainGame():
window=my_tank=enemyTanklist=[]
enemyTankCount=Bullet_list=[]
():
():
pygame.display.init()
MainGame.window = pygame.display.set_mode([SCREEN_WIDTHSCREEN_HEIGHT])
MainGame.my_tank=Tank()
.createEnemyTank()
pygame.display.set_caption()
:
time.sleep()
MainGame.window.fill(BG_COLOR)
.getEvent()
MainGame.window.blit(.getTextSurface(%(MainGame.enemyTanklist))())
MainGame.my_tank.displayTank()
.blitEnemyTank()
MainGame.my_tank.stop:
MainGame.my_tank.move()
.blitBullet()
pygame.display.update()
():
top=i (MainGame.enemyTankCount):
left = random.randint()
speed = random.randint()
enemy=EnemyTank(lefttopspeed)
MainGame.enemyTanklist.append(enemy)
():
enemyTank MainGame.enemyTanklist:
enemyTank.displayTank()
enemyTank.move()
enemyTank.randMove()
():
bullet MainGame.Bullet_list:
bullet.displyBullet()
():
()
()
(text):
pygame.font.init()
font = pygame.font.SysFont()
textSurface = font.render(textTEXT_COLOR)
textSurface
():
eventList = pygame.event.get()
event eventList:
event.type == pygame.QUIT:
.endGame()
event.type == pygame.KEYDOWN:
event.key == pygame.K_LEFT:
MainGame.my_tank.direction=MainGame.my_tank.stop=()
event.key == pygame.K_RIGHT:
MainGame.my_tank.direction = MainGame.my_tank.stop = ()
event.key == pygame.K_UP:
MainGame.my_tank.direction = MainGame.my_tank.stop = ()
event.key == pygame.K_DOWN:
MainGame.my_tank.direction = MainGame.my_tank.stop = ()
event.key ==pygame.K_SPACE:
()
m = Bullet(MainGame.my_tank)
MainGame.Bullet_list.append(m)
event.type==pygame.KEYUP:
event.key ==pygame.K_UP event.key==pygame.K_LEFT event.key==pygame.K_DOWN event.key==pygame.K_RIGHT:
MainGame.my_tank.stop=Tank():
(lefttop):
.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
.speed=.stop=():
.direction ==:
.rect.left > :
.rect.left-=.speed
.direction ==:
.rect.top>:
.rect.top-=.speed
.direction ==:
.rect.top+.rect.height<SCREEN_HEIGHT:
.rect.top+=.speed
.direction ==:
.rect.left+.rect.height < SCREEN_WIDTH:
.rect.left+=.speed
():
Bullet()
():
.image=.images[.direction]
MainGame.window.blit(.image.rect)
MyTank(Tank):
():
EnemyTank(Tank):
(lefttopspeed):
.images={
: pygame.image.load(): pygame.image.load(): pygame.image.load(): pygame.image.load()
}
.direction=.randomDirection()
.image=.images[.direction]
.rect=.image.get_rect()
.rect.left=left
.rect.top=top
.speed=speed
.flag=.step = ():
num=random.randint()
num==:
num==:
num==:
num==:
():
.step <=:
.direction=.randomDirection()
.step=random.randint()
:
.move()
.step-=Bullet():
():
.image = pygame.image.load()
.direction = tank.direction
.rect = .image.get_rect()
.direction == :
.rect.left = tank.left + tank.rect.width / - .rect.width / .rect.top = tank.top - .rect.height
.direction == :
.rect.left = tank.rect.left - .rect.width / - .rect.width / .rect.top = tank.rect.top + tank.rect.width / - .rect.width / .direction == :
.rect.left = tank.rect.left + tank.rect.width / - .rect.width / .rect.top = tank.rect.top + tank.rect.height
.direction == :
.rect.left = tank.rect.left + tank.rect.width
.rect.top = tank.rect.top + tank.rect.width / - .rect.width / .speed = random.randint(())
():
():
MainGame.window.blit(.image.self.rect)
Wall():
():
():
Explode():
():
():
Music():
():
():
__name__== :
MainGame().startGame()
F:\Python\pythonProject\Tank\venv\Scripts\python.exe F:/Python/pythonProject/Tank/13.py
pygame 2.0.1 (SDL 2.0.14, Python 3.9.1)
Hello from the pygame community. https://www.pygame.org/contribute.html
发射子弹
Traceback (most recent call last):
File "F:\Python\pythonProject\Tank\13.py", line 329, in <module>
MainGame().startGame()
File "F:\Python\pythonProject\Tank\13.py", line 52, in startGame
self.getEvent()
File "F:\Python\pythonProject\Tank\13.py", line 143, in getEvent
m = Bullet(MainGame.my_tank)
TypeError: __init__() takes 1 positional argument but 2 were given
Process finished with exit code 1
请问老师我哪里多给参数了?