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

2020/11/8

Make an Object, which moves from one side of the world to the other, and repeats the action, when done

PascalFischer PascalFischer

2020/11/8

#
Hey, I have some trouble making an Object, which starts on a random number of the right side from the Map, goes strait to the other side, and repeats the action, when done. Can someone help me, how I can do this?
danpost danpost

2020/11/8

#
Repeating at a new random number? Is there a specific number of these objects to be in the world at one time? Show World subclass codes and class code of this object. Include attempt at making it work.
PascalFischer PascalFischer

2020/11/8

#
danpost wrote...
Repeating at a new random number? Is there a specific number of these objects to be in the world at one time? Show World subclass codes and class code of this object. Include attempt at making it work.
it is basically an object, which go from one side to the other, and repeats in, when done. but with the same start position (my bad)
danpost danpost

2020/11/8

#
PascalFischer wrote...
it ... repeats ... but with the same start position
So, basically:
if (getX() == 0) move(getWorld().getWidth()-1);
// or
if (getX() == 0) setLocation(getWorld().getWidth()-1, getY());
In a bounded world the "-1" in both cases can be dropped (although, that is where it ends up, regardless of its inclusion).
You need to login to post a reply.