Page 1 of 1

delete this post

Posted: Sun Apr 14, 2013 4:13 pm
by jajasuperman
delete this post

Re: How can i jump with löve?

Posted: Sun Apr 14, 2013 7:06 pm
by T-Bone
I'm not sure exactly what you want to do, but I imagine it's something like this:

Store the size of the square in a single variable. This means that if you want to change the size, you only need to change it in one place. It can be done like this:

Code: Select all

--in love.load()
player.size = 40
Then, for the check against the floor y, just do

Code: Select all

--in love.update()
if player.y + player.size > 440
instead of just player.y > 400. That way, the behaviour should be the same even if you change the size. Of course, if you want the square to actually look like its size, change the line in love.draw to

Code: Select all

--in love.draw()
love.graphics.rectangle("fill", player.x, player.y, player.size, player.size)

Re: How can i jump with löve?

Posted: Sun Apr 14, 2013 7:36 pm
by jajasuperman
delete this post

Re: How can i jump with löve?

Posted: Sun Apr 14, 2013 7:43 pm
by T-Bone
jajasuperman wrote:That's not what I want to do: S
Imagine you jump to the next platform and jump back to that platform. The jump of the two should be of the same height.
So, if I use player.y > 500 I can´t do that.
Sorry if I don´t explain well.
Myes. That's more tricky. It depends on how you store the two platforms.

Let's say each platform is a table containing x,y,width and height. Let the x and y coordinates show the upper left corner of the platform. All these platforms are stored in a table called "platforms". Then you could do something like

Code: Select all

if love.keybaord.isDown("up") --the user wants to jump
    --check if any platform is right below us. In that case, jump.
    for i = 1,#platforms do
        local platform = platforms[i]
        local dy = player.y - platform.y
        local dx = player.x - platform.x
        if dy > 0 and dy < 0.2 and dx > 0 and dx < platform.width then
              --you are above one of the platforms, so jump
              player.ySpeed = -20 --or whatever
        end
    end
end
I have not checked the code, you should get the idea. As I said, it depends on how you store all the platforms, and how you structure your code in general. This code is also very simplified, causing some strange behaviour if you jump right below a platform and stuff. But you should get the idea of how it can be done.