Python Game Programming Tutorial: Pong Part 3 Moving the Paddles

preview_player
Показать описание
NEED HELP?

❤️❤️ SHOW SOME LOVE AND SUPPORT THE CHANNEL ❤️❤️

Click Join and Become a Channel Member Today!
Channel members can get preferential comment replies, early access to new content, members only live streams, and access to my private Discord.

Amazon Affiliate Links

Other Affiliate Links

LINKS

LEARN MORE PYTHON

LEARN MORE JAVA

#Python #Tutorial #Beginner
Рекомендации по теме
Комментарии
Автор

Great tutorial!
If you want to restrict your paddles so they don't go off the screen, add this to your main game loop:
if paddle_a.ycor() >= 250:
paddle_a.sety(250)

if paddle_a.ycor() <= -250:
paddle_a.sety(-250)

if paddle_b.ycor() >= 250:
paddle_b.sety(250)

if paddle_b.ycor() <= -250:
paddle_b.sety(-250)

Sondre
Автор

This video is amazing, explained everything perfectly.

GizaVAL
Автор

Appreciate being thorough, I'm a 15 year old kid, so a lot of the things that are probably common sense, aren't for me. So giving a lot of details really helped. thanks!

Lodus_beatbox
Автор

Awesome! Loved it! What's the next best thing to do after this? Especially to get some income, even if it's a low key thing/project

axion
Автор

I've ran into a small bug when running this code. I've noticed that when paddle A holds down W or S, the paddle will move. However, this is interrupted when paddle B is given a command (Up or Down). This causes paddle A to stop moving. Is there a way around this?

jake.
Автор

Hi Christian, I have a problem.
when pressing "w" nothing moves.

I'm using Python 3, here is the code:


import turtle

wn = turtle.Screen()
wn.title("Pong by QuadriProject")
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0)

#paletta A

paddle_a = turtle.Turtle()
paddle_a.speed(0)
paddle_a.shape("square")
paddle_a.color("white")
paddle_a.shapesize(stretch_wid=5, stretch_len=1)
paddle_a.penup()
paddle_a.goto(-350, 0)


#paletta B

paddle_b = turtle.Turtle()
paddle_b.speed(0)
paddle_b.shape("square")
paddle_b.color("white")
paddle_b.shapesize(stretch_wid=5, stretch_len=1)
paddle_b.penup()
paddle_b.goto(350, 0)



#palla

ball = turtle.Turtle()
ball.speed(0)
ball.shape("square")
ball.color("white")
ball.penup()
ball.goto(0, 0)


#Funzione Move

def paddle_a_up():
y = paddle_a.ycor()
y += 20
paddle_a.sety(y)

#Keyboard chiamata

wn.listen()
wn.onkeypress(paddle_a_up(), "w")




#main game loop

while True:
wn.update()

AlbertoQuadriProject
Автор

Is there a way to make the paddle_a move while holding either "w" or "s"? Right now, I have to keep clicking to move paddle_a where with paddle_b ("Up" and "Down" arrows) I can just hold and paddle_b moves continuously. I solved this problem by switching the arrow keys to another letter bound but I would like to know if its possible to get the letter keys to move the paddles on hold?

crazyaznub
Автор

What interpreter do you use? Has such a clean look and I love the auto-completion

JD-ojhr
Автор

How can I make the two paddles move at the same time?(I'm on windows) thanks very much. Here's my incomplete code:


import turtle

wn = turtle.Screen()#The window
wn.title("Pong by @Salai Hung")#The title of the window
wn.bgcolor("black")#The color of the window
wn.setup(width=800, height=600)#The setup of the window
wn.tracer(0)

# Paddle A
paddle_a = turtle.Turtle()
paddle_a.speed(0)#The speed of the projectile or item
paddle_a.shape("square")#The shape or silohoutte of the projectile
paddle_a.color("white")#The color of the projectile or shape
paddle_a.shapesize(stretch_wid=5, stretch_len=1)#Where it can go
paddle_a.penup()
paddle_a.goto(-350, 0)#Lets coders skip a variety of information

# Paddle B
paddle_b = turtle.Turtle()
paddle_b.speed(0)#The speed of the projectile or item
paddle_b.shape("square")#The shape or silohoutte of an/the object
paddle_b.color("white")#The color of the, shape or item
paddle_b.shapesize(stretch_wid=5, stretch_len=1)#Where it can go
paddle_b.penup()
paddle_b.goto(350, 0)#Lets coders skip a variety of information

# Ball
ball = turtle.Turtle()
ball.speed(0)#The speed of the projectile or item
ball.shape("square")#The shape or silohoutte of the projectile
ball.color("white")#The color of the projectile or shape
ball.penup()
ball.goto(0, 0)#Lets coders skip a variety of information

# Function
def paddle_a_up():
y = paddle_a.ycor()
y += 20
paddle_a.sety(y)

def paddle_a_down():
y = paddle_a.ycor()
y -= 20
paddle_a.sety(y)

def paddle_b_up():
y = paddle_b.ycor()
y += 20
paddle_b.sety(y)

def paddle_b_down():
y = paddle_b.ycor()
y -= 20
paddle_b.sety(y)

# Keyboard binding
wn.listen()#Listen to a certain line a code
wn.onkeypress(paddle_a_up, "w")#To make a keyboard input
wn.onkeypress(paddle_a_down, "s")#To make a keyboard input
wn.onkeypress(paddle_b_up, "Up")#To make a keyboard input
wn.onkeypress(paddle_b_down, "Down")#To make a keyboard input

# Main game loop
while True:# A true or false statement in which different events can happen in either false or true
wn.update()#Gives updates if a event that was programmed to happen

zerosquadml
Автор

I need some help... both paddles can move up and down with no problem, but they can not move at the same time. Paddle A would need to stop moving so that paddle b can start moving. How would I be able to make both of them move at the same time?

checklist
Автор

during the keyboard bindings, what do you type if you want to us arrows

dominionbalogun
Автор

so much help thx a lot ceap up the good vids

joe-rkmx
Автор

it says
"Traceback (most recent call last):
File "C:/Users/USER/PycharmProjects/pong1/pong.py", line 66, in <module>
wn.onkeypress(paddle_b_down, "Down")
NameError: name 'paddle_b_down' is not defined
"

liqinxie
Автор

So i tried to import turtle. It loads upad and everything but my paddles wont display. I tried copying you exact code into my IDLE/atom and launched it but the paddles still dont appear

dannynguyen
Автор

Hi, i had some issues when making the paddles move up and down. The paddles are growing longer rather than moving, I hope you can help me :)

AyoBambino
Автор

I'm using classes for this, and so far so good up until this error :
AttributeError: 'Paddles' object has no attribute 'ycor'


It will spit out this error whenever I press w to make it go up. Any ideas?

cweasegaming
Автор

It doesn't work in using raspberry pi and the program won't work i press w and nothing happens

kakalak
Автор

i have an error: it said: ('_Screen' object has no attribute 'onkeypress')
can you fix this, i'm using python 3.7, windows 10 pro

trollface
Автор

This is the first tutorial that explained to me what the frick ycor and xcor mean.

ibrahimabdalla
Автор

Why pressing "s", the paddle_a can move continuously but pressing "w" doesn't?

yuen
visit shbcf.ru