Pong game cs50g paddles dont respond to keyboard.isdown('w')

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
seblank
Prole
Posts: 5
Joined: Mon Oct 02, 2023 2:43 pm

Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by seblank »

Im working on the pong game of cs50g course. I can't seem to get my paddles to respond to the keyboard.isdown('w') function. Nothing happens.
I've been following the video thoroughly so it's very confusing to me.

All help is appreciated. Thanks.

Edit: Also it should be mentioned that it does respond to the

function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end

that's called when you press escape to quit the game.
Attachments
main.love
(2.32 KiB) Downloaded 92 times
User avatar
BrotSagtMist
Party member
Posts: 655
Joined: Fri Aug 06, 2021 10:30 pm

Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by BrotSagtMist »

Thats not how you create a .love file.
Zip your entire project and post again.
obey
seblank
Prole
Posts: 5
Joined: Mon Oct 02, 2023 2:43 pm

Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by seblank »

oh kk, re-posting this.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by Bobble68 »

Agree with Brot, but from what I can tell of your code, your issue is here:

Code: Select all

--left paddle
    love.graphics.rectangle('fill', 10, 30, 5, 20)

    --right paddle
    love.graphics.rectangle('fill', VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 50, 5, 20)
Your controls are working fine, they just aren't being displayed correctly, neither of the player's Y values are being used in the love.draw(). My best guess is that you want it to look something like this:

Code: Select all

    --left paddle
    love.graphics.rectangle('fill', 10, player1Y, 5, 20)

    --right paddle
    love.graphics.rectangle('fill', VIRTUAL_WIDTH - 15, player2Y, 5, 20)
Not sure what the video looks like, so it might be slightly off
Dragon
seblank
Prole
Posts: 5
Joined: Mon Oct 02, 2023 2:43 pm

Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by seblank »

Bobble68 wrote: Mon Oct 02, 2023 7:07 pm Agree with Brot, but from what I can tell of your code, your issue is here:

Code: Select all

--left paddle
    love.graphics.rectangle('fill', 10, 30, 5, 20)

    --right paddle
    love.graphics.rectangle('fill', VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 50, 5, 20)
Your controls are working fine, they just aren't being displayed correctly, neither of the player's Y values are being used in the love.draw(). My best guess is that you want it to look something like this:

Code: Select all

    --left paddle
    love.graphics.rectangle('fill', 10, player1Y, 5, 20)

    --right paddle
    love.graphics.rectangle('fill', VIRTUAL_WIDTH - 15, player2Y, 5, 20)
Not sure what the video looks like, so it might be slightly off
Hi thanks for ur answer.

I tried your suggestion but it still won't react to neither up/down or w/s.. I tried hardcoding it and called for it to play a sound when pressing the keys to see if there was any issue with the keyboard inputs and that worked fine, I got sound from all the key inputs..
seblank
Prole
Posts: 5
Joined: Mon Oct 02, 2023 2:43 pm

Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by seblank »

I did notice however that you're right about the fact that player1Y had to be added to the draw section, I just noticed I had totally missed that part from the video..
User avatar
BrotSagtMist
Party member
Posts: 655
Joined: Fri Aug 06, 2021 10:30 pm

Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by BrotSagtMist »

But please repost in the SAME thread.
Also still not how you make a .love, you need to zip the INSIDE of your working folder not the folder itself.

Bobble is right here i guess, you are changing your player values with these buttons but you dont use these values at all.
If you are unsure about your values, just slam a print() in there and observe them while you hit on the buttons, your player Y changes but noone of the values you use to render the paddle does change.
obey
seblank
Prole
Posts: 5
Joined: Mon Oct 02, 2023 2:43 pm

Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by seblank »

Solved! Thank for the help and sorry for the spam thread lol..

Btw, could you explain the process of calling print() if im unsure about the values? Like in this case, where would I place print() to get a clue if my values are being used correct?
User avatar
BrotSagtMist
Party member
Posts: 655
Joined: Fri Aug 06, 2021 10:30 pm

Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')

Post by BrotSagtMist »

For this case, just do

Code: Select all

     print( 'fill', VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 50, 5, 20 )
    love.graphics.rectangle('fill', VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 50, 5, 20)
for a quick dirty debug.
I mean you already use print above, you just have to connect the dots.
If the text doesnt change, neither will the position of the rectangle is the logic here.
And have of course another print whitin the button press to veryfie this also works.
obey
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests