Making a supernova movie -- Greenfoot programming lesson
Find other posts in the same category: | | |

Long description

This is a great example of what a 10-year-old can do in Greenfoot.
A ten-year-old made this by himself after watching the Greenfoot video tutorial on explosions.
(He has watched almost all of the other tutorials, and he already knows how to program in Scratch)
The Greenfoot tutorial shows a gray rock exploding into 40 pieces.

Here are the modifications made by the ten-year-old. (The only help he got was finding the syntax error in the statement to place a rock in the original.
1) change number of fragments to 4000
2) change gravity to 0
3) change force to 0
4) set background image to space
5) made the world start with a rock in place

Here is the code for the Rock

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

* Write a description of class Rock here.
* @author (your name)
* @version (a version number or a date)
public class Rock extends Actor
private static final int NUM_FRAGMENTS = 4000;

* Act - do whatever the Rock wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
public void act()
// Add your action code here.

public void explode()
placeDebris (getX(), getY(), NUM_FRAGMENTS);

private void placeDebris(int x, int y, int numFragments)
for (int i=0; i < numFragments; i++) {
getWorld().addObject ( new Debris(),x, y );



Next page

To see articles on the same topic, click the links below the name of the author at the top of this page.