Page 3 of 3
Re: [Solved]Platformer movement with [Bump]
Posted: Sat Oct 04, 2014 10:31 am
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
Re: [Solved]Platformer movement with [Bump]
Posted: Sat Oct 04, 2014 11:02 am
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.
Re: [Solved]Platformer movement with [Bump]
Posted: Sat Oct 04, 2014 11:26 am
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.
Re: [Solved]Platformer movement with [Bump]
Posted: Sat Oct 04, 2014 2:15 pm
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
Re: [Solved]Platformer movement with [Bump]
Posted: Mon May 30, 2016 9:13 am
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.
P.S. I am really sorry for necroposting
Re: [Solved]Platformer movement with [Bump]
Posted: Mon May 30, 2016 9:59 am
by kikito
4aiman wrote:However, after updating that project to a newest bump, the bug cease to happen.
Fiu! Thanks for reporting this.