Learning Greenfoot -- make a simple wombat crosses creek game
Find other posts in the same category: | | |

Long description

This is supposed to be the first game in a series to teach Greenfoot programming. This game uses two for loops to generate the turtles and the bricks.

Use the up, down, right, and left arrow keys to get the wombat across the creek by on the red stones.

This game illustrates
1) how to create a new world that already has objects
2) how to use a for loop
3) how to accept keyboard input to move an actor around

In a later version, the wombat will fall into the creek if it is not on a red stone.

The move code is from one of the Greenfoot video tutorials http://www.kidslike.info/code_for_a_penguin_that_jumps_greenfoot_program...

This is the code from the World sub-class scene

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.Random;
/**
* Write a description of class scene here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class scene extends World
{
public int width;
public int depth = 330;
// width = getWidth();
// depth = getHeight();
public int x = 1;

public scene()
{
super(600, 400, 1);
makeOcean();
makeBricks();
addAnimals();
}


public void makeOcean()
{
for (int i=1; i< 100; i++)
{
addObject(new water(),x,depth);
addObject(new water(),x+15,depth+30);
x = x + 30;
}
}

public void makeBricks()
{
x = 0;
for (int i=1; i< 100; i++)
{
addObject(new Ground(),x,depth - 30);
addObject(new Ground(),x + 10,depth - 30);
addObject(new Ground(),x + 20,depth - 30);
x = x + 90;
}
}

public void addAnimals()
{
addObject(new Wombat(),10,depth - 30);

}

}


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