-2

I'm building a flappy bird clone i LOVE 2D and all i have is the bird flapping, with the background behind it. I would like to make it so when the bird touches the ground the game ends,or shows a game over screen. And i cant seem to find a good way to do this without using external libraries though. Is there a solution to this? I have the ground as separate image if that helps or matters. I'm using the latest LOVE 2D framework version.

Thanks! I know someone will give me the answer i need!

  • 1
    How do you save the bird's position? It should be reasonably easy to just compare the current y-coordinate with the ground's y-coordinate. If the bird is at the same or a higher coordinate (that is, below the ground), you should transition to your end screen. Or is your problem that you don't know how to transition to another screen? Can you show us what you've tried so far? What did and didn't work? – Henrik Ilgen Jan 18 '16 at 06:09

2 Answers2

1

I'm using rects in my games.

if (bird.x <= tube.x and bird.y <= tube.y and bird.x + bird.width >= tube.x and bird.y + bird.height >= tube.y) then
   {...code...}

if (bird.x <= tube.x and bird.y >= tube.y and bird.x + bird.width >= tube.x and bird.y <= tube.y + tube.height) then
   {...code...}

 if (bird.x >= tube.x and bird.y <= tube.y and bird.x <= tube.x + tube.width and bird.y + bird.height >= tube.y) then
   {...code...}

if (bird.x >= tube.x and bird.y >= tube.y and bird.x <= tube.x + tube.width and bird.y <= tube.y + tube.height) then
   {...code...}
IOD
  • 32
  • 4
1

I use this simple code partially taken from the love2d forums. Here's the code and under the function is how you use it. (can be reused for many objects)

-----------------------Code-------------------------
function colMulti(x1, y1, w1, h1,  x2, y2, w2, h2)
    return  x1 < x2+w2 and
            x2 < x1+w1 and
            y1 < y2+h2 and
            y2 < y1+h1
end

-----------------------Usage-------------------------
x1, y1, w1, h1 = bird.x, bird.y, bird.img:getWidth(), bird.img:getHeight()
x2, y2, w2, h2 = ground.x, ground.y, ground.img:getWidth(), ground.img:getHeight()

if colMulti(x1, y1, w1, h1,  x2, y2, w2, h2) then
    —Execute bird death here
end

There is a much longer, complicated, and more efficient method for collision detection, but you have to learn a ton about the built in physics engine for love2d. (Doesn't seem like you need it thou.)

More info on other way: https://love2d.org/wiki/love.physics