Where did I go wrong with this conversion from java to python??

edited August 2017 in Python Mode

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()
Tagged:

Answers

Sign In or Register to comment.