Y collision check fails

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
PurpleDrain
Prole
Posts: 5
Joined: Mon Dec 05, 2011 7:29 pm

Y collision check fails

Post by PurpleDrain »

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.
Attachments
test.love
(1.27 KiB) Downloaded 127 times
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Y collision check fails

Post by tentus »

Change line 41:

Code: Select all

elseif p2y <= 5 then
to this:

Code: Select all

end
if p2y <= 5 then
Kurosuke needs beta testers
PurpleDrain
Prole
Posts: 5
Joined: Mon Dec 05, 2011 7:29 pm

Re: Y collision check fails

Post by PurpleDrain »

Thanks! I appreciate your help.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Y collision check fails

Post by tentus »

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
PurpleDrain
Prole
Posts: 5
Joined: Mon Dec 05, 2011 7:29 pm

Re: Y collision check fails

Post by PurpleDrain »

That's more effective, I've implented that instead now. I thank you again for your help!
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests