Итак, я делал игру в стиле понг в Python с Pygame и наткнулся на кое-что. Он сказал, что 'function' object has no attribute 'x'
. Классы, которые я использовал, здесь. Пожалуйста, помогите мне, потому что я не использовал Python в течение длительного времени, и я не знаю, что означает эта ошибка.
from math import pi, sin, cos
class Vector:
def __init__ (self, x = 0, y = 0):
self.x = x
self.y = y
@classmethod
def random ():
angle = random(0, 2 * pi)
x = cos(angle)
y = sin(angle)
return Vector(x, y)
from Vector import Vector
class Ball:
def __init__ (self, size):
self.position = Vector(size[0] / 2, size[1] / 2)
self.velocity = Vector.random
self.scale = Vector(100, 100)
import pygame
from Ball import Ball
def main ():
pygame.init()
size = (1600, 900)
window = pygame.display.set_mode(size)
pygame.display.set_caption("Pong")
ball = Ball(size)
frameRate = 60
run = True
while run:
pygame.time.delay(int(frameRate / 1000))
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
window.fill((0, 0, 0))
pygame.draw.rect(window, (255, 255, 255), (ball.position.x, ball.position.y, ball.scale.x, ball.scale.y))
pygame.display.update()
# This is where the error happened.
ball.position.x += ball.velocity.x
ball.position.y += ball.velocity.y
pygame.quit()
if __name__ == "__main__":
main()