Greenfoot - Use and Programming Model

Use and Programming Model

public void act { setLocation (getX + 4, getY); setRotation (getRotation + 2); }
An example of a simple act method in Greenfoot
Actor a = getOneIntersectingObject(Asteroid.class); if (a != null) { // we have hit an asteroid! explode; }
An example of simple collision detection

The Greenfoot programming model consists of a World class (represented by a rectangular screen area) and any number of actor objects that are present in the world and can be programmed to act independently. The world and actors are represented by Java objects and defined by Java classes. Greenfoot offers methods to easily program these actors, including method for movement, rotation, changes of appearance, collision detection, etc.

Programming in Greenfoot at its most basic consists of subclassing two built-in classes, World and Actor. An instance of the world subclass represents the world in which Greenfoot execution will occur. Actor subclasses are objects that can exist and act in the world. An instance of the world subclass is automatically created by the environment.

Execution in Greenfoot consists of a built-in main loop that repeatedly invokes each actor's act method. Programming a scenario, therefore, consists mainly of implementing act methods for the scenario's actors. Implementation is done in standard Java. Greenfoot offers API methods for a range of common tasks, such as animation, sound, randomisation, and image manipulation. All standard Java libraries can be used as well, and sophisticated functionality can be achieved.

Read more about this topic:  Greenfoot

Famous quotes containing the words programming and/or model:

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)

    The Battle of Waterloo is a work of art with tension and drama with its unceasing change from hope to fear and back again, change which suddenly dissolves into a moment of extreme catastrophe, a model tragedy because the fate of Europe was determined within this individual fate.
    Stefan Zweig (18811942)