delete this post

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
jajasuperman
Prole
Posts: 16
Joined: Wed Feb 20, 2013 7:16 pm

delete this post

Post by jajasuperman »

delete this post
Last edited by jajasuperman on Sun Dec 08, 2019 9:48 pm, edited 1 time in total.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: How can i jump with löve?

Post 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)
jajasuperman
Prole
Posts: 16
Joined: Wed Feb 20, 2013 7:16 pm

Re: How can i jump with löve?

Post by jajasuperman »

delete this post
Last edited by jajasuperman on Sun Dec 08, 2019 9:48 pm, edited 1 time in total.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: How can i jump with löve?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 73 guests