Page 1 of 1

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

Posted: Mon Oct 02, 2023 2:49 pm
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.

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

Posted: Mon Oct 02, 2023 6:27 pm
by BrotSagtMist
Thats not how you create a .love file.
Zip your entire project and post again.

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

Posted: Mon Oct 02, 2023 7:02 pm
by seblank
oh kk, re-posting this.

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

Posted: Mon Oct 02, 2023 7:07 pm
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

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

Posted: Mon Oct 02, 2023 7:35 pm
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..

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

Posted: Mon Oct 02, 2023 7:38 pm
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..

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

Posted: Mon Oct 02, 2023 7:39 pm
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.

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

Posted: Mon Oct 02, 2023 8:27 pm
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?

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

Posted: Mon Oct 02, 2023 9:01 pm
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.