Answer the question
In order to leave comments, you need to log in
The program does not work, everything seems to be written correctly, but it gives an error?
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import (
NumericProperty, ReferenceListProperty, ObjectProperty
)
from kivy.vector import Vector
from kivy.clock import Clock
from random import randint
class PongBall(Widget):
# Speed movement of our ball along two axes
velocity_x = NumericProperty(0)
velocity_y = NumericProperty(0)
# Create a conditional vector
velocity = ReferenceListProperty(velocity_x, velocity_y)
# Make the ball move
def move(self):
self.pos = Vector(*self.velocity ) + self.pos
class PongGame(Widget):
ball = ObjectProperty(None) # this will be our relation to the ball object
def serve_ball(self):
self.ball.center = self.center
self.ball.velocity = Vector(4, 0).rotate(randint(0, 360) )
def update(self, dt):
self.ball.move() # move the ball on every screen update
# bounce the ball along the y axis
if(self.ball.y < 0) or (self.ball.top > self.height ):
self.ball.velocity_y *= -1 # invert current y speed
# bounce ball on x
if(self.ball.x < 0) or (self.ball.right > self.widht):
self.ball .velocity_x *= -1 # invert current x speed
class PongApp(App):
def build(self):
game = PongGame()
game.serve_ball()
Clock.schedule_interval(game.update, 1.0/60) # FPS
return game
if __name__ == '__main__':
PongApp().run()
Error: AttributeError: 'NoneType' object has no attribute ' move'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question