[Solved]Platformer movement with [Bump]

General discussion about LÖVE, Lua, game development, puns, and unicorns.
LXDominik
Prole
Posts: 26
Joined: Wed Oct 01, 2014 9:05 am

Re: [Solved]Platformer movement with [Bump]

Post by LXDominik »

kikito wrote:Hi there,

The error you are having happens because the "item" inside the filter function does not "survive" after the function is executed. You can't use it to remove it. Also, you forgot to include the kind on the enemies.

Here's what I would do:

Code: Select all

enemies = {}
-- changed this function to store enemies as keys instead of values in the enemies table (easier to remove later)
-- also, added the missing 'kind' attribute
function enemy_create(x, y, width, height)
  local enemy = {x=x,y=y,w = width, h = height, kind = 'Enemy'}
  enemies[enemy] = true
end
...

-- You can put this as a local inside the player.lua file; no need to declare it inside the player update loop
local collideWithEnemy = function(item) return item.kind == 'Enemy' end

...

local future_l, future_t = player.x + dx, player.y + dy

local cols, len = world:check(player, future_l, future_t, collideWithEnemy)
if len > 0 then
  local enemy = cols[1].other
  world:remove(enemy) -- removes enemy from the world
  enemies[enemy] = nil -- removes enemy from the list of enemies
end

Using the enemies as keys instead of as values in the enemies table is simpler because removing them can be done more easily (otherwise you would need to iterate over the enemies table with a loop every time you wanted to remove an enemy).

Regards!
But how to add "enemy" to the bump world? like this :?

Code: Select all

function enemy_create(x, y, width, height)
	local enemy = {x=x,y=y,w = width, h = height, kind = 'Enemy'}
  	enemies[enemy] = true
  	world:add(enemy, x,y,width,height)
end
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Solved]Platformer movement with [Bump]

Post by kikito »

Yes, you could add the enemy to the world there, or you could return the enemy and add it to the world in the place where you call to enemy_create.
When I write def I mean function.
LXDominik
Prole
Posts: 26
Joined: Wed Oct 01, 2014 9:05 am

Re: [Solved]Platformer movement with [Bump]

Post by LXDominik »

kikito wrote:Yes, you could add the enemy to the world there, or you could return the enemy and add it to the world in the place where you call to enemy_create.
Hmm... now i dont get how to manipulate this "enemies", how to move or draw them. :cry:
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Solved]Platformer movement with [Bump]

Post by kikito »

Before you probably did something like this:

Code: Select all

for i=1, #enemies do
  -- each enemy is on enemies[i]
  drawEnemy(enemies[i])
end

-- or

for i,enemy in ipairs(enemies) do
  -- each enemy is on the "enemy" variable
  drawEnemy(enemy)
end
Now you the enemies are on the keys, so you have to use pairs and the "k" instead of the "v":

Code: Select all

for enemy,_ in pairs(enemies) do
  -- each enemy is on the "enemy" variable
  drawEnemy(enemy)
end
When I write def I mean function.
User avatar
4aiman
Party member
Posts: 262
Joined: Sat Jan 16, 2016 10:30 am

Re: [Solved]Platformer movement with [Bump]

Post by 4aiman »

kikito wrote:Yes, that is one way to fix that, but in bump there is explicit code to handle the "getting stuck in corners" thing. I worked on it for a year :/ . You telling me that it happens in your computer is ... disturbing. It should not.
I know It's been a while and many Bump bugs were fixed since the date the message above was posted, but I can reproduce the bug mentioned with the latest love2d on Win7 x86 (0.10.1).

However, after updating that project to a newest bump, the bug cease to happen. :awesome:


P.S. I am really sorry for necroposting
Attachments
test-kikito.love
(55.3 KiB) Downloaded 107 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Solved]Platformer movement with [Bump]

Post by kikito »

4aiman wrote:However, after updating that project to a newest bump, the bug cease to happen. :awesome:
Fiu! Thanks for reporting this. :)
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 2 guests