We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I got this from the: https://gist.github.com/dc74089/4094da7928839063ae06
This is from the processing for java. I cannot seem to get it to bounce against the paddle. Some of the changes might not be right. My code below:
x=0
y=0
speedX=20
speedY=20
diam = 10
rectSize = 200
def setup():
fullScreen()
fill(0, 255, 0)
reset()
def reset():
x = width/2
y = height/2
speedX = random(3, 5)
speedY = random(3, 5)
def draw():
background(0)
global x,y
global speedX, speedY
fill(166)
ellipse(x, y, diam, diam)
fill(255,255,0)
rect(0, 0, 20, height)
rect(width-30, mouseY-rectSize/2, 10, rectSize)
x = x + speedX
y = y + speedY
#if ball hits movable bar, invert X direction
if ( x > width-30 and x < width -20 and y > mouseY-rectSize/2 and y < mouseY+rectSize/2 ):
speedX = speedX * -1
# if ball hits wall, change direction of X
if (x < 25):
speedX *= -1.1
speedY *= 1.1
x += speedX
#if ball hits up or down, change direction of Y
if ( y > height or y < 0 ):
speedY *= -1
def mousePressed():
reset()
Answers
Can you explain what you did please and thank you.
http://py.Processing.org/reference/globals.html
P.S.:
if
in Python doesn't need()
. ;)ok, what about the width>>1, height>>1 - I have never seen that before. I am familiar with globals.
>>1
is the same as/2
: :ar!http://py.Processing.org/reference/rightshift.html
Ok, thank you for being so helpful. I am just trying to parse my way through the code to figure out how it bounces and the collision detection.