Game Development Reference
In-Depth Information
You convert the character to lowercase so the instruction works for both normal and boxed
penguins. To complete the Animal class, you add a few convenient methods to check whether
you're dealing with a special case such as a multicolored penguin, an empty box, or a seal. For the
complete Animal class, see the example program PenguinPairs4 belonging to this chapter.
Finally, you also have sharks in the Penguin Pairs game. Sharks are relatively simple animals, and
they can't be controlled by the player (very much as in real life!). Therefore, rather than the Animal
class, you use SpriteGameObject for them, which contains everything you need. You follow a
procedure similar to that for the penguins. You create a tile and a shark, and store the sharks in an
array so you can easily find them later:
t = new Tile(sprites.field);
t.sheetIndex = row + col % 2;
tileField.addAt(t, col, row);
var s = new SpriteGameObject(sprites.shark, ID.layer_objects_1);
s.position = t.position.copy();
playingField.add(s);
this.sharks.push(s);
break;
Now that you've dealt with all these different cases in the switch instruction, you can load each level.
Have a look at the Level class in the example to see the complete level-creation process.
Figure 21-2 shows a screenshot of one of the levels after it's been loaded.
 
Search WWH ::




Custom Search