Pong game in vpython

Hey! I’m a highschool student and I need help on my coding project. Does anybody know how to make a ping pong game using python glowscript. My teacher is oddly specific and she doesn’t want me to use turtle or pygame. So I really need help starting.

Welcome to the forum @Diana_Jacobo ! :partying_face: This is a friendly place where you can ask help on levels, report bugs, or just chat with other coders! Don’t forget to read the guidelines if you haven’t yet. Have a great time!

Hmm.Do you know about Canvas and Tkinter?

Have you taken a look at the examples by GlowScriptDemos?

The VPython Intro doc could help as well. Except you would need to modify the sample code to your needs.

Does the ping pong game have to be one player or two player?

An improved pong code but still very buggy

GlowScript 3.2 VPython
                    
scene.caption = """Press any key to start"""

ball = sphere(pos=vector(0,0,0), radius=0.75,color=color.white, make_trail=False)

side = 5.0
thk = 0.3
s2 = 2*side - thk
s3 = 2*side + thk
wallB = box (pos=vector(0, -side, 0), size=vector(s3, thk, s3-3),  color = color.cyan)
wallT = box (pos=vector(0,  side, 0), size=vector(s3, thk, s3-3),  color = color.red)

paddleV= 5
ballVX = 3
ballVY = 25
ball.velocity = vector(ballVX,ballVY,0)
wallT.velocity = vector(paddleV,0,0)
deltat = 0.005
t = 0
ball.pos = ball.pos + ball.velocity*deltat

scene.autoscale = False 

scene.waitfor("keydown")

while t < 3e4:
    run = True
    rate(100)
    ballVX+=0.008
    ballVY+=0.01
    wallB.pos.x = scene.mouse.pos.x
    
    wallT.pos = wallT.pos + wallT.velocity*deltat
    
    if wallT.pos.x > 7:
        paddleV+=0.01
        wallT.velocity = vector(-paddleV, 0,0)
        
    if wallT.pos.x < -7:
        paddleV+=0.01
        wallT.velocity = vector(paddleV, 0,0)
        
    
    if ball.pos.y > wallT.pos.y and wallT.pos.x < 5 and wallT.pos.x > -5:
        ball.velocity.y = -ball.velocity.y
        
    if ball.pos.y <wallB.pos.y and wallB.pos.x < 7 and wallB.pos.x > -7:
        ball.velocity.y = -ball.velocity.y
        
    if ball.pos.x >11.5:
        ball.velocity = -ball.velocity
        
    if ball.pos.x<-11.5:
        ball.velocity = -ball.velocity
        
    ball.pos = ball.pos + ball.velocity*deltat
    wallT.pos = wallT.pos + wallT.velocity*deltat
    
    if ball.pos.y < -15 or ball.pos.y > 15:
        ball.visible = False
        ball.pos.y = 0
        ball.pos.x = 0
        ball.velocity = vector(ballVX,-ballVY,0)
        ball.visible = True
        
    t = t + deltat 

Yes, I’ve used one the bouncing ball code and I’ve modified it so the ball bounces of the walls in the ping pong game

I only know about Trinkets but not Canvas.

I checked out the could and I’m sorry I didn’t specify but I meant 2 players with a 4 wall frame around and 2 paddles. I have half of the code already, but I still need to figure out how to make the ball hit the paddle and recognize it’s also hitting a wall.