I am trying to create the game, Pong. I have 2 paddles, a left & a right, that should be positioned in the middle of the left and right sides of the window. When I run the game the right paddle does not display the same as the left paddle. I am unsure as to why that is. This is what it looks like currently:
The right paddle is pushed off screen, while the left paddle seems to be normal. Except that it is pushed off the edge to the right by a few.
Paddle Code:
import pygame
class Paddle:
def __init__(self, screen, h, w, left):
self.screen = screen
self.width = w
self.y = h / 2
self.pad_width = 10
self.pad_height = 100
if left:
self.x = self.pad_width / 2
else:
self.x = self.width - self.pad_width / 2
def show(self):
WHITE = (255, 255, 255)
rect = pygame.Rect(self.x, self.y, self.pad_width, self.pad_height)
pygame.draw.rect(self.screen, WHITE, rect)
I create 2 instances of the paddle like this:
# create 2 paddles
left = Paddle(screen, HEIGHT, WIDTH, True)
right = Paddle(screen, HEIGHT, WIDTH, False)
# show the paddles
left.show()
right.show()
Where screen is screen = pygame.display.set_mode((WIDTH, HEIGHT)).
HEIGHT is 400 and WIDTH is 600.
EDIT:
With self.x = self.width - self.pad_width * 2 it shows: