Page 1 of 1

Using BUMP, need a little help. Should be easy?

Posted: Tue May 19, 2015 2:53 am
by hiccupface
Hi LÖVElies,

So I've been working on a game for a few weeks and and it has to have grown to the point where bump.lua might be the best collision manager for me. So lately I've been trying to update the code to make use of bump.

I've stripped down my code to help with testing/integrating this, so hopefully it can make sense to you. Right now the player character - the placeholder Crusader sprite - can walk around and bump into rectangles. If you hit the 'spacebar' key, it should generate a homing sprite that I would like to have destroyed on impact with the player character. That is, destroy the projectile, not the player character.

I can destroy the sprite if my crusader walks into the projectile, but if he/she stands still, the two will just slide up to each other, and the projectile will not destroy itself.

I think it would help to change the collision type to touch instead of slide, but I can't seem to figure it out in the bump documentation. Pardon the noobness! Does this make sense? Care to take a look? I've attached the code and it should work.

Re: Using BUMP, need a little help. Should be easy?

Posted: Tue May 19, 2015 7:06 am
by kikito
There is some confusion on this code.

The variable lobsters is sometimes used as if it was a list of objects. For example here:

Code: Select all

for i,newlobster in ipairs(lobsters) do
  table.remove(lobsters, i)
end
But other times it is used as a single object. For example on its declaration:

Code: Select all

local lobsters = {
    x = 250,
    y = 250,
    w = 20,
    h = 20,
    speed = 30,
    img = love.graphics.newImage('enemy.png')
}
You have to remove this confusion. You can't have both a list of items and a single item on the same variable. That's the first thing you have to decide (I recommend using lobsters as a list - that means it would start empty, and you would add a new lobster to it every time space was pressed).

If you end up using lobsters as a "list of items", you will have to do a loop every time you want to use it. For example, if you want to "draw all the lobsters" you have to do a loop over the lobsters variable, drawing one lobster on every iteration.

Also, you can add a list of items (lobsters) to bump and expect i to know that it is a list. bump does not work like that. You have to enter every lobster individually, calling world:add with a loop. Similarly, to update all the lobsters, you will have to call world:move once for each lobster that you have.

Re: Using BUMP, need a little help. Should be easy?

Posted: Tue May 19, 2015 1:54 pm
by hiccupface
Thank you Kikito. I appreciate the reply!

Sadly, I think my noob brain can't handle this at the moment, haha. My game is mostly complete and trying to integrate bump into my own mess is more of a headache than I can endure.

In my own game I'm using lists as you suggested, but for the life of me can't seem to be able to get it to work with bump. Damn. I will stick with baby steps for now, as I'm incredibly new to not only LÖVE but also Lua.