Report as inappropriate.
This code, freely available, shows an example of how to move multiple actors in greenfoot with the mouse, all at the same time, to different locations.
It uses the Bresenham's line algorithm to build a list of locations between where the actor currently is and where you have clicked on the world to go to.
The actor will then move to these, one act method at a time, unless you choose to move it somewhere else.
The world act method handles selecting and deselecting of actors.
A selected actor has an icon below it to show to you it is selected.
The images have almost no relation to the code itself. The only one is the distance to place the icon beneath the actor, and the size of the actor we respects to trying to left click on it. (For ease of clicking when you left click on the world, it looks "around" for an actor within a certain region).
Left click on an actor to select it, or left click and drag over any number of actors to select them all. Left clicking on the world we deselect all currently selected actors.
Right click anywhere will cause all currently selected actors to move there.
4122 views / 11 in the last 7 days
1 vote | 0 in the last 7 days
This scenario is a member of: Grand Designs
Want to leave a comment? You must first log in.