

In this example, the Home object is added to the world at the arbitrary position 480, 250 (you can position the portal anywhere you like within the world).

for (start condition, test condition, incrementor) First, let's look at the structure of a loop to see how we can use it to draw our walls. It will be your job to draw the three inner walls (see illustration above). Part of the maze has already been drawn using this method, and you can look at the world class's constructor for examples of the loops that created the existing outer wall structure.

The World: Drawing walls with loops Rather than draw the maze walls directly onto the world's background, we create a rectangular (20px by 20px) block object (wallRect), and using “for” loops, we draw a series of blocks to create a wall. In order to successfully complete this scenario, you will need to complete the maze walls and add motion and behavior to your bug that will allow it to safely find its way through the maze without passing through walls. The scenario includes a partly completed maze, a bug character whose motions must be added, and an enemy lizard that the bug must avoid.
#Greenfoot getoneintersectingobject how to
This handout will demonstrate how you draw the walls of you maze using “for” loops, how to code character motions so that they cannot pass through walls, and how to invoke the methods of an object from within an object of another class. Because this handout only covers the basics (motion, collisions, player controls), there is plenty more that you can add to your project in order to make it a rich and entertaining game, earning you the respect and admiration of your friends and family. This handout describes the basic mechanics of a maze game, to be used as a guide when making your very own custom game using Greenfoot.
