We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This is returning the error that "global name 'playerOne' is not defined. how can i fix it?
from Paddle import Paddle from Ball import Ball
def setup(): global playerOne, ball size(500, 500) background(0)
playerOne = Paddle(250, 450, 20, 100, False, False)
ball = Ball(250, 0, 0, -5, 10)
def draw(): global playerOne, ball
background(0)
playerOne.display()
ball.display()
print(playerOne.x)
def keyPressed(): if key == CODED: if keyCode == LEFT: playerOne.moveLeft = True elif keyCode == RIGHT: playerOne.moveRight = True
def keyReleased(): if key == CODED: if keyCode == LEFT: playerOne.moveLeft = False elif keyCode == RIGHT: playerOne.moveRight = False
class Ball(): x = 0 y = 0 xDiff = 0 yDiff = 0 bSize = 0
def __init__(self, _x, _y, _xDiff, _yDiff, _bSize):
self.x = _x
self.y = _y
self.xDiff = _xDiff
self.yDiff = _yDiff
self.bSize = _bSize
def display(self):
if -10 <= (playerOne.y - self.y) - (playerOne.pHeight / 2) - (bSize /2) <= 0:
if x > (playerOne.x - ((playerOne.pWidth / 2) + (bSize / 2))) and x < (playerOne.x + (playerOne.pWidth / 2) + (bSize / 2)):
yDiff *= -1
xDiff = -1 * int((playerOne.x - self.x) /10)
ellipseMode(CENTER)
ellipse(self.x, self.y, self.bSize, self.bSize)
class Paddle: """Description""" x = 0 y = 0 pHeight = 0 pWidth = 0 moveLeft = False moveRight = False
def __init__(self, _x, _y, _pHeight, _pWidth, _moveRight, _moveLeft):
self.x = _x
self.y = _y
self.pHeight = _pHeight
self.pWidth = _pWidth
self.moveRight = _moveLeft
self.moveLeft = _moveLeft
def display(self):
if self.moveLeft == True:
if self.x >= 0 + self.pWidth/2:
self.x -= 5
elif self.moveRight == True:
if self.x <= 500 - self.pWidth/2:
self.x += 5
fill(255)
rectMode(CENTER)
rect(int(self.x), int(self.y), self.pWidth, self.pHeight)
Answers
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Never mind, figured it out
please don't answer unnecessary