Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pong paddles wont move
#3
omgomgomg thank you so much! the paddles are moving now, but now idk how to get the ball moving... ik this code looks alot like the code you showed me, sry for that, i'm still learning the basics of python/turtle
import turtle


class Paddle  (turtle.Turtle):
    def __init__(self, x, keys=None, color='white'):
        super().__init__()
        self.speed(3)
        self.shape('square')
        self.shapesize(stretch_wid=5, stretch_len=1)
        self.color(color)
        self.penup()
        self.goto(x, 0)
        if keys:
            wn.onkeypress(lambda: self.move_y(20), keys[0])
            wn.onkeypress(lambda: self.move_y(-20), keys[1])

    def move_y(self, step):
        self.sety(self.ycor()+step)


class Ball  (turtle.Turtle):
    def __init__(self, color='white', keys=None):
        super().__init__()
        self.speed(3)
        self.shape('circle')
        self.color(color)
        self.penup()
        self.goto(0, 0)


wn = turtle.Screen()
wn.setup(width=800, height=600)
paddles = (Paddle(-350, "ad"), Paddle(350, "jl"))
ball = Ball()
wn.bgcolor('yellow')
wn.title('pong')

wn.listen()
while True:
    wn.update()
Reply


Messages In This Thread
pong paddles wont move - by skullkat232 - Dec-29-2022, 07:42 PM
RE: pong paddles wont move - by deanhystad - Dec-29-2022, 11:20 PM
RE: pong paddles wont move - by skullkat232 - Dec-30-2022, 05:52 PM
RE: pong paddles wont move - by deanhystad - Dec-30-2022, 07:02 PM
RE: pong paddles wont move - by skullkat232 - Dec-30-2022, 08:02 PM
RE: pong paddles wont move - by Vadanane - Feb-13-2023, 03:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [PyGame] my pygame car wont move Erio85 1 1,215 Apr-24-2023, 04:52 PM
Last Post: Erio85
  Problem with my pong code Than999 3 3,637 Oct-22-2021, 08:50 AM
Last Post: Qanima
  Game “Pong” I have problems with the code BenBach18 2 3,640 Jan-10-2021, 05:16 PM
Last Post: michael1789
  [PyGame] Creating Pong in Pygame Russ_CW 2 2,926 Oct-11-2020, 11:56 AM
Last Post: Russ_CW
  Trying to make a simple pong game. kevindadmun 1 4,048 Aug-05-2019, 06:39 AM
Last Post: kevindadmun
  Smiley Pong Help Jasmineleroy 6 4,936 May-22-2019, 11:36 AM
Last Post: metulburr
  [PyGame] How do I add more balls to basic Pong game? JUtah 2 4,609 Apr-18-2019, 08:40 PM
Last Post: JUtah
  [PyGame] Pong game key.event problem erickDarko 2 4,318 Dec-12-2018, 03:17 PM
Last Post: erickDarko
  Text wont draw fierygaming 1 3,073 Jul-28-2018, 10:39 PM
Last Post: Windspar

Forum Jump:

User Panel Messages

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