Could you help me with my brick game? I am having a difficult time checking if the ball has collided with the panel and the bricks. so far I have
from visual import *
from __future__ import math *
scene.range=10
bricks = [box(pos=vector(i-5,9,0),lenght=1,height=1, width=0, color=color.white)for i in range(0,11)]
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(600)
ball.pos= ball.pos + ball.velocity*delta_t
if ball.y<10:
ball.velocity.y=-ball.velocity.y
if distance(ball.pos, panel.pos) <= 0.5:
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
Now, I had made a distance function earlier in my class:
x1 = int(raw_input("please enter your first x value "))
y1 = int(raw_input("please enter your first y value "))
x2 = int(raw_input("please enter your second x value "))
y2 = int(raw_input("please enter your second y value "))
def distance():
dx = x2 - x1 #Takes the x2 and subtracts the x1
dy = y2 - y1 #Takes the y2 and subtraces the y1
return math.sqrt(dx**2 + dy**2
however this is taking two points a user inputs. how would I get it to check the distance of the ball and panel. In theory, I want to make a function like this
dist(a,b):
returns a #
if dist(ball.pos,panel.pos)<= 0.5:
ball.velocity.y=-ball.velocity.y + ball.velocity.x
however, I am not sure exactly how to get it to check the panel, and the ball, then the ball and the bricks