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

Report as inappropriate.

plcs
plcs presents ...

2011/5/25

RTS Movement Example

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).

Basic Instructions:

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

Tags: demo with-source

This scenario is a member of: Grand Designs


open in greenfoot
Your browser does not support the canvas tag.

No Comments

Want to leave a comment? You must first log in.

Who likes this?

GameCode