#πŸ”’ Missing paddle

79 messages Β· Page 1 of 1 (latest)

sullen brook
#

Python version: 3.13.0
SDL (don't know what this is) version: 2.28.4
Pygame version: 2.6.1

First of all, here's the code (of interest because the entire code is too big):

Paddle class:

class paddle():
def __init__(self):
self.height = 10
self.width = int(screen_width / cols)
self.x = int((screen_width / 2) - (self.width / 2))
self.y = screen_height * (self.height * 2)
self.speed = 10
self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
self.direction = 0

def move(self):
self.direction = 0
key = pygame.key.get_pressed()
if key[pygame.K_a] and self.rect.left > 0:
self.rect.x -= self.speed
self.direction = -1
if key[pygame.K_d] and self.rect.right < screen_width:
self.rect.x += self.speed
self.direction = 1

def draw(self):
pygame.draw.rect(screen, paddle_color, self.rect)
pygame.draw.rect(screen, paddle_outline, self.rect, 3)

Paddle instance:

player_paddle = paddle()

Game loop:

run = True
while run:

screen.fill(bg_color)

wall.draw_wall()

player_paddle.draw()
player_paddle.move()

for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False

pygame.display.update()

pygame.quit()

This game is supposed to be very similar to Breakout, but the paddle doesn't show up on the screen. I tried removing the code that prevents it from moving if it's outside of the screen and changing the x and y positions and none of that worked, the result is always the same. For the record, the color of the paddle and the background are different.

summer hareBOT
#

@sullen brook

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

past briar
#

wha

#

can you put a print on the draw function?

sullen brook
#

what?

past briar
#

there's no reason for it not to draw, and that's weird, you said you even checked for the position and the color

#

you could try other various stuff as well

sullen brook
#

any ideas?

past briar
#
        pygame.draw.rect(screen, paddle_color, self.rect)
        pygame.draw.rect(screen, paddle_outline, self.rect, 3)

like switching this up

#

because I dont know how are you gonna outline something drawing it in front of the thing it outlines

#

but overall, something should be drawn

sullen brook
#

yeah

#

I'll try anyways

past briar
#

so put prints everywhere to check which part is not executing correctly

sullen brook
#

didn't work, I'll try putting print commands

#

the weird thing is that it doesn't give any error message

past briar
#

that's more like the only normal thing about your error

sullen brook
#

oh dear

#

So...

#

I don't know how to describe what happened

past briar
#

that sounds like you got something

sullen brook
#

You can see the console printing the messages about the paddle class

#

It prints the first one and loops through the second and third one

#

but

past briar
#

print screen

sullen brook
#

I couldn't capture it but, the "Paddle drawn successfully" apears last and start flickering

#

wait

#

what if I put the draw and move functions outside the game loop?

past briar
#

what

sullen brook
#

like I did with the brik wall

past briar
#

wdym "outside the game loop"

#

your player_paddle.draw() is exactly the line before wall.draw_wall()

#

can you send the code to wall.draw_wall?

#

or

#

!paste

summer hareBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

sullen brook
#

the red part is inside the game loop, everything else is outside

past briar
sullen brook
#

hold up

sullen brook
past briar
sullen brook
#

so that it makes an outline for the brik wall

#

Without it the briks appear glued together

past briar
#

then space the walls out

#

like, when calculating the coords add some padding at each step

#

it's weird what you try to do

sullen brook
#

I'm a rookie man

past briar
#

wel, yeah but it's just row * self.width + padding and col * self.height + padding though

#

if you added padding, you wouldnt need separation

sullen brook
#

ok

past briar
#

and I bet you're trying to do something similar with the paddle, am I right?

sullen brook
#

no

#

it doesn't need that because there's only one paddle

past briar
#

can you set paddle_color to (255, 255, 255) and execute it?

sullen brook
#

same thing

past briar
#

then start commenting lines to see what is drawing on top of the paddle

sullen brook
#

hold on I got an idea

#

didn't work

#

the paddle is being draw on top of every thing and I doesn't show up

past briar
#

change the color, the outline, comment some lines, give somthing on another lines

#

try stuff until something starts pointing to what is the problem

sullen brook
#

ok

#

here's the new color scheme

#

here's how the game looks like

#

the padding didn't exactly worked

past briar
#

comment the screen.fill line and test again

soft rapids
#

@Lockheed In your code to draw() the paddle, print out the value of self.rect. This line in your init() method:

    self.y = screen_height * (self.height * 2)

Looks suspicious. Looks like it will generate a value off the bottom of the window.

errant locust
#

I think you're setting the paddle.y way too high. Like if your screen_height is 800 and your paddle.height is 10 then the expression is 800 * (10 * 2) or 800 * 20 which is well outside the height of your screen

past briar
#

changing the x and y positions and none of that worked, the result is always the same. For the record, the color of the paddle and the background are different.

#

but yeah, could be that

soft rapids
#

Actually too low. That gives you a large integer, which is below the window.

errant locust
#

The value is too high, making the rect too low, so both

summer hareBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.