我正在尝试制作我的第一款游戏,它类似于与自行车的tron游戏,到目前为止我已经创建了一个自行车类和几个功能来帮助.但是当它运行如下时,当我尝试用速度声明一个Bike对象时,我得到一个错误,它说:
类Vector正好取三个参数,两个由what_direction函数给出.
这对我来说是个问题,因为我创建了一个用于改变方向的2x2矩阵和一个用向量乘以矩阵的函数.我该怎么做才能解决这个错误?
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 = []
Run Code Online (Sandbox Code Playgroud) python ×1