Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python _u_init中的参数太多___Python_Pygame - Fatal编程技术网

Python _u_init中的参数太多__

Python _u_init中的参数太多__,python,pygame,Python,Pygame,我目前正在youtube上的视频“kidscancode”的帮助下编写一个platformer游戏。到目前为止一切进展顺利,我收到了以下错误: 回溯(最近一次呼叫最后一次): 文件“D:\College\CS Project\Python-Coding For Project New\Main.py”,第290行,在 g、 新的() 文件“D:\College\CS Project\Python-Coding For Project New\Main.py”,第84行,新版本 平台(自身,*平台

我目前正在youtube上的视频“kidscancode”的帮助下编写一个platformer游戏。到目前为止一切进展顺利,我收到了以下错误:

回溯(最近一次呼叫最后一次):
文件“D:\College\CS Project\Python-Coding For Project New\Main.py”,第290行,在
g、 新的()
文件“D:\College\CS Project\Python-Coding For Project New\Main.py”,第84行,新版本
平台(自身,*平台)
TypeError:\uuuu init\uuuuuu()接受4个位置参数,但给出了6个
这是我的代码(分为3页,主要、精灵和设置):

主要

我注意到,当我从中删除
self
参数时
平台列表
平台(自身,*plat)

错误会变成这样一个事实,即只有5个参数(而不是6个),其中只能有4个。

您必须将参数
(game,x,y)
传递给
平台
构造函数

*plat
似乎是四个元素,而不是
(x,y)
对,因此您的错误是6

  • self
    (默认通过)
  • 游戏
  • 再加上4个元素

这是相关代码

# (x, y, Width, Height)
PLATFORM_LIST = [
                # Floor platforms
                (0, HEIGHT - 40, WIDTH + 500, 40),
    ...
]

...

class Platform(pg.sprite.Sprite):
    def __init__(self, game, x, y):
        # ...

...        

for plat in PLATFORM_LIST:
    Platform(self, *plat)

您必须将参数
(游戏,x,y)
传递给
平台
构造函数

*plat
似乎是四个元素,而不是
(x,y)
对,因此您的错误是6

  • self
    (默认通过)
  • 游戏
  • 再加上4个元素

这是相关代码

# (x, y, Width, Height)
PLATFORM_LIST = [
                # Floor platforms
                (0, HEIGHT - 40, WIDTH + 500, 40),
    ...
]

...

class Platform(pg.sprite.Sprite):
    def __init__(self, game, x, y):
        # ...

...        

for plat in PLATFORM_LIST:
    Platform(self, *plat)

请阅读关于创建a的内容。请阅读关于创建a的内容。我现在已经修复了此错误,花了一些时间来解决它(新的编码),但是我接受了您所说的内容,并且对您有所帮助,因此非常感谢。很高兴听到此消息。您可以通过以下方式表示感谢。我现在已经修复了这个错误,花了一些时间来解决它(新的编码),但是我接受了您所说的,并且它对我有帮助,所以非常感谢。很高兴听到这个消息。你可以用英语表达你的谢意。
>TITLE = "Survival Game"
WIDTH = 1000
HEIGHT = 800
FPS = 60

HS_FILE = "highscore.txt"


PLAYER_ACC = 0.5
PLAYER_FRICTION = -0.12


PLAYER_GRAV = 0.3
PLAYER_JUMP = 10
FONT_NAME = 'Echelon'
SPRITESHEET = "spritesheet_jumper.png"

# Starting platforms
# The following list includes all the platforms I am going to be using in my game, and each platform takes in four values each. The x and y coordinates, and also the height and width of the platforms themselves.
# (x, y, Width, Height)
PLATFORM_LIST = [
                # Floor platforms
                (0, HEIGHT - 40, WIDTH + 500, 40),
                (2200, HEIGHT - 40, WIDTH + 100, 40),
                (4000, HEIGHT - 40, WIDTH + 100, 40),
                (6000, HEIGHT - 40, WIDTH + 100, 40),

                # Starting 3 platforms
                 (650, HEIGHT - 125, WIDTH - 600, 20),
                 (650, HEIGHT - 250, WIDTH - 600, 20),
                 (650, HEIGHT - 375, WIDTH - 600, 20),
                 # Middle Layer of short platforms
                 (1100, HEIGHT - 250, WIDTH - 800, 30),
                 (1500, HEIGHT - 250, WIDTH - 800, 30),
                 (2000, HEIGHT - 250, WIDTH - 800, 30),
                 (2500, HEIGHT - 250, WIDTH - 800, 30),
                 (3000, HEIGHT - 250, WIDTH - 800, 30),
                 (3500, HEIGHT - 250, WIDTH - 800, 30),

                 # Lower Layer of short platforms
                 (1175, HEIGHT - 180, WIDTH - 800, 30),
                 (1575, HEIGHT - 180, WIDTH - 800, 30),
                 (2075, HEIGHT - 180, WIDTH - 800, 30),
                 (2575, HEIGHT - 180, WIDTH - 800, 30),
                 (3075, HEIGHT - 180, WIDTH - 800, 30),
                 (3575, HEIGHT - 180, WIDTH - 800, 30),

                 # Upper Layer of short platforms
                 (1150, HEIGHT - 320, WIDTH - 800, 30),
                 (1550, HEIGHT - 320, WIDTH - 800, 30),
                 (2050, HEIGHT - 320, WIDTH - 800, 30),
                 (2550, HEIGHT - 320, WIDTH - 800, 30),
                 (3050, HEIGHT - 320, WIDTH - 800, 30),
                 (3550, HEIGHT - 320, WIDTH - 800, 30),

                 # In between platforms (Lowest)
                 (1250, HEIGHT - 115, WIDTH - 800, 30),
                 (1750, HEIGHT - 115, WIDTH - 800, 30),
                 (2250, HEIGHT - 115, WIDTH - 800, 30),
                 (2750, HEIGHT - 115, WIDTH - 800, 30),
                 (3250, HEIGHT - 115, WIDTH - 800, 30),
                 (3750, HEIGHT - 115, WIDTH - 800, 30)

                 ]


WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
CYAN = (0, 255, 255)
BROWN = (200, 140, 101)
# (x, y, Width, Height)
PLATFORM_LIST = [
                # Floor platforms
                (0, HEIGHT - 40, WIDTH + 500, 40),
    ...
]

...

class Platform(pg.sprite.Sprite):
    def __init__(self, game, x, y):
        # ...

...        

for plat in PLATFORM_LIST:
    Platform(self, *plat)