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

2015/1/10

Help: is there any way to have a "dead spot" that actors can't enter?

decadence18 decadence18

2015/1/10

#
I'm playing around with some code, trying to learn (I'm new to Java), and I'm wondering if there is any way to code in a dead zone for actors that prevents them from entering?
danpost danpost

2015/1/10

#
If the shape of the "dead zone" is rectangular, it would be very easy to add an invisible actor obstacle with an image that covers the dead zone and use either the 'isTouching' or 'getOneIntersectingObject' method for your checks; or, if the dead zone was circular, you could use an invisible point actor and use the 'getObjectsInRange' method. If the area was rectangular and in a corner of the world window, it would be easy enough just to check the location coordinates -- that both do not exceed or are less than certain values (two checks, each of which could be more or less than the limit imposed, depending on the corner of the world window).
xFabi xFabi

2015/1/10

#
Non rect./Circle should work with Perfect Pixel detective, doesnt it?
danpost danpost

2015/1/10

#
If you use a transparent pixel sized object, the 'getObjectsInRange' method should be sufficient. You do not need Perfect Pixel detection.
decadence18 decadence18

2015/1/11

#
I'll try it now, thanks. I'll post back if I can get it work or if I need more help
decadence18 decadence18

2015/1/11

#
That does detect when Actors are entering the area, now is there a way to get the Actors to avoid that spot?
danpost danpost

2015/1/11

#
I will call the class that creates the spot -- the 'Spot' class. When the actors move in their act method, where you have 'move( some number )' -- that is, after the move statement, add an 'if' block something like the following:
1
2
3
4
5
if (!getObjectsInRange( /** some range */, Spot.class).isEmpty())
{
    move( - /** some number */ );
    /** turn command */
}
decadence18 decadence18

2015/1/11

#
When trying to use what code you gave me:
1
2
3
4
5
if ((!getObjectsInRange(1, InvisibleBarrier.class)).isEmpty())
        {
            turn(180);
            move(1);
        }
I get "Bad operand type java.util.List for unary operator '!'
decadence18 decadence18

2015/1/11

#
I got it to work. I had to use:
1
2
3
4
5
if (!(((getObjectsInRange(1, InvisibleBarrier.class)).isEmpty())))
        {
            turn(180);
            move(1);
        }
You need to login to post a reply.