Hi, Im trying to make a brick game, im only allowed to use vpython, not pygame. I am having trouble getting the ball to change direction and to bounce off the bricks, could you look over my code, and lemme me know? if you could email me at <EMAIL SNIPPED>

from visual import*

scene.title = 'brick'
scene.range=10

brick1=box(pos=(-5,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick2=box(pos=(-4,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick3=box(pos=(-3,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick4=box(pos=(-2,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick5=box(pos=(-1,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick6=box(pos=(0,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick7=box(pos=(1,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick8=box(pos=(2,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick9=box(pos=(3,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick10=box(pos=(4,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick11=box(pos=(5,9,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick12=box(pos=(-4,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick13=box(pos=(-3,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick14=box(pos=(-2,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick15=box(pos=(-1,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick16=box(pos=(0,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick17=box(pos=(1,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick18=box(pos=(2,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick19=box(pos=(3,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)
brick20=box(pos=(4,8,0), length=1, height=1, width=1, color=color.white, material=materials.marble)




ball=sphere(color=color.cyan, pos=vector(0,0,0), radius=0.2)

ball.velocity = vector(0,-1,0)

delta_t= 0.01

panel=box(pos=(0,-9,0), length=2, height=0.5, width=0, color=color.white)
panel.velocity = vector(1,0,0)
while True:
    rate(300)
    ball.pos= ball.pos + ball.velocity*delta_t

    if ball.y<10:
        ball.velocity.y=-ball.velocity.y
    if ball.y >= panel.y +.5 and ball.x<= panel.x+1 and ball.x >= panel.x-1 :
        ball.velocity.y= -ball.velocity.y


    
    if scene.kb.keys:
        s=scene.kb.getkey()
        if s == 'right':
            panel.pos.x = panel.pos.x + 0.2
        if s == 'left':
            panel.pos.x = panel.pos.x - 0.2
    if ball.y >= 7 and ball.x >.5 and ball.x <.5:
        ball.velocity.y=-ball.velocity.y
     
    if ball.y <= -10:
        break
        print "Game Over"

Edited 5 Years Ago by peter_budo: Keep It Organized - Do not ask anyone (member or moderator) for help by email or PM

I do not know exactly how to do that, my teacher has not fully taught us how to do that. although I do know what a for loop is, im not sure where to incorporate that

This article has been dead for over six months. Start a new discussion instead.