delete this post
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 16
- Joined: Wed Feb 20, 2013 7:16 pm
delete this post
delete this post
Last edited by jajasuperman on Sun Dec 08, 2019 9:48 pm, edited 1 time in total.
Re: How can i jump with löve?
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:
Then, for the check against the floor y, just do
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
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
Code: Select all
--in love.update()
if player.y + player.size > 440
Code: Select all
--in love.draw()
love.graphics.rectangle("fill", player.x, player.y, player.size, player.size)
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
-
- Prole
- Posts: 16
- Joined: Wed Feb 20, 2013 7:16 pm
Re: How can i jump with löve?
delete this post
Last edited by jajasuperman on Sun Dec 08, 2019 9:48 pm, edited 1 time in total.
Re: How can i jump with löve?
Myes. That's more tricky. It depends on how you store the two platforms.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.
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
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Who is online
Users browsing this forum: Bing [Bot] and 3 guests