How to ensure the player doesn't go off screen

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
kurtss
Prole
Posts: 6
Joined: Wed Nov 23, 2011 4:37 pm

How to ensure the player doesn't go off screen

Post by kurtss »

I'm currently making my first game, a Pong clone. How would I make sure that the paddle doesn't go off screen? I tried an if player.y < gameHeight - 80 (gameHeight is love.graphics.getHeight()) but then the player isn't movable.

Thanks in advance!
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: How to ensure the player doesn't go off screen

Post by Ellohir »

The "y" coordinate starts from 0 at the top and increases as we go down. I think your code should look something like this:

Code: Select all

if player.y < gameHeight - 80 then
 --movement down
else
--nothing, it's the limit
end

Code: Select all

if player.y > 80 then
 --movement up
else
--nothing, it's the limit
end
Tell us if it worked! Good luck! :awesome:
kurtss
Prole
Posts: 6
Joined: Wed Nov 23, 2011 4:37 pm

Re: How to ensure the player doesn't go off screen

Post by kurtss »

Oh, wow! I didn't think of putting the up and down movements in seperate blocks. Thanks a ton!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests