<p dir="ltr"><br>
On May 8, 2015 9:46 AM, "Tommy C" <<a href="mailto:tommyc168168@gmail.com">tommyc168168@gmail.com</a>> wrote:<br>
><br>
> I'm trying to apply OOP in this bouncing ball code in order to have multiple balls bouncing around the screen. The objective of this code is to create a method called settings, which controls all the settings for the screen and the bouncing behaviour of multiple balls, under the class Ball. However, I keep on getting errors related to attributes (e.g., speed). I'm new to OOP in Python so your help will be much appreciated. Thanks in advance.</p>
<p dir="ltr">As the error says, the attribute does not exist.<br></p>
<p dir="ltr">> class Ball:<br>
>     def __init__(self, X, Y):<br>
>         self.velocity = [1,1]</p>
<p dir="ltr">Here where you set it, you call it "velocity".</p>
<p dir="ltr">>         speed = self.velocity</p>
<p dir="ltr">Here you create a local variable called "speed", which you never use.</p>
<p dir="ltr">>                 if balls.ball_boundary.left < 0 or balls.ball_boundary.right > self.width:<br>
>                     balls.speed[0] = -balls.speed[0]</p>
<p dir="ltr">And here you look up an attribute of Ball called "speed", which doesn't match the name you used in __init__.</p>
<p dir="ltr">This is a muddled design overall. Your Ball class represents the individual balls bouncing around the screen. It should not also contain details about window size and the logic for the event loop. Use a separate class for that.</p>
<p dir="ltr">Similarly, if the purpose of your settings method is to manage settings, why does it also contain all the bouncing logic? These should probably be separate methods.</p>