Hello!
I apologize for making this my first post, but I need help with this problem I can't seem to figure out!
What I am trying to make is a classic ping pong game, and I am having a problem with whenever the left bar touches the top or the bottom of the screen the right bar seem to fail the check.
I will appreciate any kind of help, also feel free to tell me if you can see anything that I can improve upon or change.
Thanks.
Y collision check fails
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 5
- Joined: Mon Dec 05, 2011 7:29 pm
Y collision check fails
- Attachments
-
- test.love
- (1.27 KiB) Downloaded 127 times
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Y collision check fails
Change line 41:
to this:
Code: Select all
elseif p2y <= 5 then
Code: Select all
end
if p2y <= 5 then
Kurosuke needs beta testers
-
- Prole
- Posts: 5
- Joined: Mon Dec 05, 2011 7:29 pm
Re: Y collision check fails
Thanks! I appreciate your help.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Y collision check fails
Just a suggestion, but your code would be simpler and cleaner if you do the minimum/maximum checks inside of the isDown statements.
Code: Select all
-- GAME START
p1x, p1y = 70, 300 -- P1 start pos
p2x, p2y = 730, 300 -- P2 start pos
mx, my = 0, 0 -- Default mouse val
function love.draw()
love.graphics.print("Mx: " .. mx .. "\n" .. "My: " .. my, 700, 20) -- X,Y Info
p1 = love.graphics.rectangle("fill", p1x, p1y, 10, 85) -- P1 entity
p2 = love.graphics.rectangle("fill", p2x, p2y, 10, 85) -- P2 entity
end
function love.update(dt)
mx, my = love.mouse.getPosition()
local p1yc, p2yc = p1y + 65, p2y + 65
-- Controls P1
if love.keyboard.isDown("w") then
p1y = p1y - 5
if p1y < 5 then
p1y = 5
end
elseif love.keyboard.isDown("s") then
p1y = p1y + 5
if p1y > 510 then
p1y = 510
end
end
-- Controls P2
if love.keyboard.isDown("up") then
p2y = p2y - 5
if p2y < 5 then
p2y = 5
end
elseif love.keyboard.isDown("down") then
p2y = p2y + 5
if p2y > 510 then
p2y = 510
end
end
end
Kurosuke needs beta testers
-
- Prole
- Posts: 5
- Joined: Mon Dec 05, 2011 7:29 pm
Re: Y collision check fails
That's more effective, I've implented that instead now. I thank you again for your help!
Who is online
Users browsing this forum: Google [Bot] and 4 guests