This site requires JavaScript, please enable it in your browser!
Greenfoot back
ironphoenix20
ironphoenix20 wrote ...

2015/12/15

Removing Object

ironphoenix20 ironphoenix20

2015/12/15

#
How do I remove Object 3 when Object 1 is touching Object 2?
danpost danpost

2015/12/15

#
ironphoenix20 wrote...
How do I remove Object 3 when Object 1 is touching Object 2?
What are the name of the classes? How many of each could be in the world at any time? With the answers to the above, include which object number is which.
ironphoenix20 ironphoenix20

2015/12/16

#
The name of the classes are Hero(1), Monster(2), and Key(3). There can be as many of each object as you want in the world.
azzamali azzamali

2015/12/16

#
ironphoenix20 wrote...
The name of the classes are Hero(1), Monster(2), and Key(3). There can be as many of each object as you want in the world.
thnx
danpost danpost

2015/12/17

#
Okay -- if the hero touches a monster, you want one of the keys in the world to be removed. Unfortunately, it is not as simple and straightforward as it would seem with this:
if (heroTouchesMonster()) removeOneKey();
because the hero may be in contact with the same monster for several act cycles at a time, which could quickly remove all the keys from the world. So, if the monster touched is not removed from the world when found to be touching the hero, then you need to keep track of which monster is touching, so only one key is removed per monster touched (re-touching the same monster after separating from it counts as a new touch). In other words, you need to know when that first act cycle where a touch occurs happens. This requires that you hold the monster being touched in a field until you are not touching it (where you set the field to 'null'). If the field is 'null' and a monster is found to be touching, then it is first act cycle to be found touching and the monster is stored in the field and a random key removed from the world.
You need to login to post a reply.