I would like to create an inventory where if a clue is clicked in the scenario, it will be added to the inventory. The inventory should show all the items inside it by pressing 'x' and (if it's not possible to hide the items by pressing x again) hide the items by clicking the inventory object.
This is a very rough code I made to create it:
It doesn't exactly work, and it only shows the object CaramelApple because I've already set it as true. If I were to have another object that I didn't set manually as true, it wouldn't show up. Is there any way I can create a proper inventory?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | boolean CaramelApple = true ; public void act() { inventory(); } public void inventory() { if (Greenfoot.isKeyDown( "x" )) { if (CaramelApple) { CaramelApple apple = new CaramelApple(); getWorld().addObject(apple, 105 , 361 ); } } if (Greenfoot.mouseClicked( this )) { if (getWorld().getObjectsAt( 105 , 361 , Props. class ) != null ) { getWorld().removeObjects(getWorld().getObjectsAt( 105 , 361 , Props. class )); } } } |