Im making a game in LWJGL 2
and Slick2d
. Im trying to add an item to my inventory by releasing a key (the inventory system works properly, the part where I have to see if the button was RELEASED is difficult). Right now when I do...
if (Keyboard.getEventKey() == Keyboard.KEY_L) {
if(Keyboard.getEventKeyState() == false){
Inventory.addItem(1);
}
}
... In my update method, Instead of it only calling the 2nd if statement once, ( because you can only release a key once) It just keeps going because the getEventKeyState
variable stays false, but if Ive already released it once it should switch back to the opposite. Although I can do it by making it add an item when i hold the key, I cant exactly make it add only the 1 item, it keeps adding items while I hold it.
public static void addItem(int id){
for(InventorySlot s : inventoryslots){
if(s.getItem() == -1){
s.setItem(id);
System.out.println("Added item " + id + "!");
break;
}
}
}
Thats the addItem method, and if I would approach this by making it add the item while holding, I would have to make it so that it adds it only once. Any suggestions please? Thank you