I have a game where you walk around picking up items. They are supposed to go into the next empty slot in your inventory, but when I pick up an item all the empty inventory spots get filled with it.
How can I only have the first empty one be filled by the item that is being picked up:
Here is my code:
for (int i = 0; i < c.toArray().length; i++) {
c.get(i).tick();
for (int i1 = 0; i1 < play.items.p.toArray().length;i1++) {
if (c.get(i).holdingid == 0) {
// check if the player walks onto the item which means it should
// be picked up:
if(play.items.p.get(i1).r.intersects(play.p.r)) {
// remove the item from the ground:
play.items.p.get(i1).remove = true;
// change the empty inventory spots to be filled with the item
// that has been picked up
c.get(i).holdingid = play.items.p.get(i1).holdingid;
}
}
}
}
The problem is it fills all the inventory spots how can I make it only fill the first inventory spot.
play.items.p.get(i1).r.intersects( play.p.r )
is really killing me, that's a very bad practice on writing code, especially if you're asking for help. Other people will not know your hierarchy. Take a step back to explain what you're doing first. – aslg Aug 13 at 10:20c
is the array of items you're holding, andplay.items.p
is an array of items on the world/floor? – aslg Aug 13 at 11:31