Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pong game
#1
I am trying to build a pong game for practice and I am haviing trouble with my LeftPaddle and RightPaddle methods. I am gettting this error when I run the code:
Traceback (most recent call last):
File "main.py", line 292, in <module>
Game()
File "main.py", line 256, in __init__
self.left_paddle = LeftPaddle()
File "main.py", line 242, in __init__
Paddle.__init__(self, x, y)
File "main.py", line 234, in __init__
turtle.Turtle.__init__(self)
File "/usr/lib/python3.8/turtle.py", line 3813, in __init__
RawTurtle.__init__(self, Turtle._screen,
File "/usr/lib/python3.8/turtle.py", line 2541, in __init__
TNavigator.__init__(self, screen.mode())
File "/usr/lib/python3.8/turtle.py", line 1523, in __init__
self._angleOffset = self.DEFAULT_ANGLEOFFSET
AttributeError: 'LeftPaddle' object has no attribute 'DEFAULT_ANGLEOFFSET'

I am not sure hoow to fix the issue here. I am by no means done, but I am stuck here. Here is my code so far:

import turtle
import random
import math
class Ball(turtle.Turtle):
def __init__(self, x, y, x_vel, y_vel):
turtle.Turtle.__init__(self)
self.x = x
self.y = y
self.vx = x_vel
self.vy = y_vel
self.penup()
self.speed(0)
self.setpos(x, y)

class Paddle:
def __init__(self, x, y):
turtle.Turtle.__init__(self)
self.x = x
self.y = y
self.penup()
self.setpos(x, y)

class LeftPaddle(Paddle):
def __init__(self, x, y):
Paddle.__init__(self, x, y)

class RightPaddle(Paddle):
def __init__(self, x, y):
Paddle.__init__(self, x, y)

class Game:
def __init__(self):
turtle.setworldcoordinates(0, 0, 1000, 1000)
turtle.delay(0)
self.ball = Ball(random.uniform(50, 950), random.uniform(50, 950), random.choice([-5,5]), random.uniform(5, -5))
self.ball.turtlesize(1)
self.ball.shape('circle')
self.ball.color('blue')
self.left_paddle = LeftPaddle(5, 500)
self.left_paddle.turtlesize(1)
self.left_paddle.color('black')
self.left_paddle.shape("square")
self.left_paddle.shapesize(stretch_wid=6, stretch_len=2)
self.score = 0
self.gameloop()
# turtle.onkeypress(self.player.thrust, 'Up')
turtle.listen()
turtle.mainloop()

def move(self):
self.ball.setx(self.ball.xcor()+self.ball.vx)
self.ball.sety(self.ball.ycor()+self.ball.vy)
if self.ball.xcor() <= 0:
self.ball.setx(0)
self.ball.vx *= -1

if self.ball.xcor() >= 1000:
self.ball.setx(1000)
self.ball.vx *= -1

if self.ball.ycor() <= 0:
self.ball.sety(0)
self.ball.vy *= -1

if self.ball.ycor() >= 1000:
self.ball.sety(1000)
self.ball.vy *= -1

# self.ball.setpos(new_x, new_y)

def gameloop(self):
self.move()
turtle.Screen().ontimer(self.gameloop, 30)

Game()
Reply


Messages In This Thread
Pong game - by buss0140 - Dec-22-2020, 02:19 AM
RE: Pong game - by bowlofred - Dec-22-2020, 03:57 AM
RE: Pong game - by buss0140 - Dec-22-2020, 07:28 AM
RE: Pong game - by buss0140 - Dec-22-2020, 07:44 AM
RE: Pong game - by buss0140 - Dec-26-2020, 05:51 PM
RE: Pong game - by MK_CodingSpace - Dec-26-2020, 10:24 PM
RE: Pong game - by buss0140 - Dec-27-2020, 02:00 AM
RE: Pong game - by ndc85430 - Dec-27-2020, 07:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to send a pong on websocket-client tomtom 0 3,744 Aug-15-2022, 05:58 AM
Last Post: tomtom
  Problem with my pong game code Than999 8 3,890 May-15-2022, 06:40 AM
Last Post: deanhystad
  scoring issues in pong wildbill 1 2,230 Aug-05-2019, 01:48 AM
Last Post: metulburr
  PING PONG GAME akea 0 5,719 May-08-2019, 04:30 PM
Last Post: akea
  Python project "pong" without any makefile sylas 5 5,037 Nov-28-2017, 05:55 PM
Last Post: Larz60+
  ping and pong run both well sylas 1 3,196 Sep-24-2017, 05:14 PM
Last Post: sylas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020