5. Removing Objects
1. Removing Objects
Open the editor for your main character.
Underneath the if statements for using the arrow keys is where we type the removal code.
If you have chosen a different collectible object, type the exact name of that class instead of Orange (e.g. Apples or Ants).
Press Run and try to grab all of your collectibles!
Removing Objects - Adding danger to your game
Time to code your main character to be removed if they are touched by the enemy objects!
The removal code is placed beneath the code you have already written.
Use the same code as you did earlier but change the class (instead of Orange.class I have chosen Sheep.class).
Press Run and try to avoid the enemies!
Go to the code of your enemy and add the line in red within your removal code.
This will stop the game if your main character is eaten.
Change Sheep.class to whatever your main character is.