我正在尝试制作我的第一款游戏,它类似于自行车上的tron游戏,到目前为止我已经创建了一个自行车类和几个帮助功能。然而,当它运行下面我得到一个错误,当我尝试声明自行车物体的速度,它说的是:类只需要三个参数,两个给出
class Vector takes exactly three arguments and two are given by the what_direction function.
这对我来说是一个问题,因为我已经创建了一个2×2矩阵用于改变方向和用矢量乘以矩阵的功能。我能做些什么来解决这个错误?
import random, math, pygame, sys
class Vector(object):
""" |x| = [0]
|y| = [1] """
def __init__(self, x, y):
self.vec = [ x, y]
def what_direction():
x = random.uniform(0.0, 5.0)
y = math.sqrt(25-(x**2))
return x, y
class Bike(object):
def __init__(self):
self.position = [random.randint(0, 200), random.randint(0, 200)]
self.velocity = Vector(what_direction())
self.score = 0
self.path_traveled = []
你能在这里粘贴错误? – sihrc
呃。我认为这是某种元组对列表的事情,我不够聪明。 – Jiminion
一个问题是你需要:'Vector(* what_direction())' –