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.
Pong game cs50g paddles dont respond to keyboard.isdown('w')
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Pong game cs50g paddles dont respond to keyboard.isdown('w')
- Attachments
-
- main.love
- (2.32 KiB) Downloaded 97 times
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')
Thats not how you create a .love file.
Zip your entire project and post again.
Zip your entire project and post again.
obey
Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')
oh kk, re-posting this.
Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')
Agree with Brot, but from what I can tell of your code, your issue is here:
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:
Not sure what the video looks like, so it might be slightly off
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)
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)
Dragon
Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')
Hi thanks for ur answer.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:
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, 30, 5, 20) --right paddle love.graphics.rectangle('fill', VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 50, 5, 20)
Not sure what the video looks like, so it might be slightly offCode: Select all
--left paddle love.graphics.rectangle('fill', 10, player1Y, 5, 20) --right paddle love.graphics.rectangle('fill', VIRTUAL_WIDTH - 15, player2Y, 5, 20)
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')
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..
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')
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.
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
Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')
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?
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?
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Pong game cs50g paddles dont respond to keyboard.isdown('w')
For this case, just do
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.
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)
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
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests