我发现我只能有一种按键输入方法。贝娄我有两种方法(movementsprite和movementspritevert)我发现我只能做一个工作。如果我同时启动两者,第一个运行,第二个什么都不做。有没有解决的办法?难道我做错了什么?
原创节目
----运动档案-----
import pygame
import os, sys
from itertools import *
from oryxsprites import *
from oryxdisplay import *
spritex = 320
spritey = 320
screen = pygame.display.set_mode((640, 640))
def movementsprite():
global spritex
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
if spritex == 576:
spritex += 0
else:
spritex += 32
elif event.key == pygame.K_LEFT:
if spritex == 32:
spritex -= 0
else:
spritex -= 32
return spritex
def movementspritevert():
global spritey
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
if spritey == 576:
spritey += 0
else:
spritey += 32
elif event.key == pygame.K_UP:
if spritey == 32:
spritey -= 0
else:
spritey -= 32
return spritey
--------主文件------]
running = True
while running:
backgroundmain()
pygame.display.set_caption('OryxGame')
#pygame.display.set_icon(grasstile)
movementsprite()
movementspritevert()
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
------显示文件----
def backgroundmain():
spritex = movementsprite()
spritey = movementspritevert()
backdrop = pygame.Rect(0, 0, 640, 640)
screen.fill((50,50,50))
playingfeildwidth = (32, 608)
playingfeildheight = (32, 608)
screen.blit(warrior1, (spritex, spritey))
------可能的解决方案 -------------
-主文件----
while running:
backgroundmain()
pygame.display.set_caption('OryxGame')
#pygame.display.set_icon(grasstile)
movementsprite(events)
movementspritevert(events)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
------显示文件-----
def backgroundmain():
events = pygame.event.get()
spritex = movementsprite(events)
spritey = movementspritevert(events)
backdrop = pygame.Rect(0, 0, 640, 640)
screen.fill((50,50,50))
playingfeildwidth = (32, 608)
playingfeildheight = (32, 608)
------键输入文件------------
spritex = 320
spritey = 320
screen = pygame.display.set_mode((640, 640))
def movementsprite(events):
global spritex
keys = pygame.key.get_pressed()
for event in events:
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
if spritex == 576:
spritex += 0
else:
spritex += 32
elif event.key == pygame.K_LEFT:
if spritex == 32:
spritex -= 0
else:
spritex -= 32
return spritex
def movementspritevert(events):
global spritey
keys = pygame.key.get_pressed()
for event in events:
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
if spritey == 576:
spritey += 0
else:
spritey += 32
elif event.key == pygame.K_UP:
if spritey == 32:
spritey -= 0
else:
spritey -= 32
return spritey
- -错误 - -
Traceback (most recent call last):
File "C:\Users\Eric\Dropbox\oryxgame\oryxgame.py", line 12, in <module>
backgroundmain()
File "C:\Users\Eric\Dropbox\oryxgame\oryxdisplay.py", line 11, in backgroundmain
spritey = movementspritevert(events)
TypeError: movementspritevert() takes no arguments (1 given)
----完整代码----