The Game Elements

What's left are the actual game objects. Those are dependent on our pixel-to-world unit mappings, as discussed earlier. To make the creation of those as easy as possible, I used a little trick: I started each drawing with a grid of 32x32 pixels per cell. All the objects are centered in one or more such cells, so that they correspond easily with the physical sizes they have in our world. Let's start with Bob, depicted in Figure 9-9.

Figure 9-9. Bob and his five animation frames.

Figure 9-9. Bob and his five animation frames.

Figure 9-9 shows two frames for jumping, two frames for falling, and one frame for being dead. The image is 160x32 pixels in size, and each animation frame is 32x32 pixels in size. The background pixels are transparent.

Bob can be in three states: jumping, falling, and being dead. We have animation frames for each of these states. Granted, the difference between the two jumping frames is minor—only his forelock is wiggling. We'll create an Animation instance for each of the three animations of Bob and use them for rendering according to his current state. We also don't have duplicate frames for Bob heading left. As with the arrow button, we'll just specify a negative width with the SpriteBatcher.drawSprite() call to flip Bob's image horizontally.

Figure 9-10 depicts the evil squirrel. We have two animation frames again, so the squirrel appears to by flapping its evil wings.

Figure 9-10. An evil flying squirrel and its two animation frames.

The image in figure 9-10 is 64x32 pixels, and each frame is 32x32 pixels.

The coin animation in Figure 9-11 is special. Our keyframe sequence will not be 1, 2, 3, 1, but 1, 2, 3, 2, 1. Otherwise the coin would go from its collapsed state in frame 3 to its fully extended state in frame 1. We can conserve a little space by reusing the second frame.

Figure 9-11. The coin and its animation frames.

The image in figure 9-11 is 96x32 pixels, and each frame is 32x32 pixels.

Not a lot has to be said about the spring image in Figure 9-12. The spring just sits there happily in the center of the image.

Figure 9-12. The spring. The image is 32x32 pixels.

The castle in Figure 9-13 is also not animated. It is bigger than the other objects (64x64 pixels).

Figure 9-13. The castle

The platform in Figure 9-14 (64x64 pixels) has four animation frames. According to our game mechanics, some platforms will be pulverized when Bob hits them. We'll play back the full animation of the platform in that case once. For static platforms we'll just use the first frame.

Figure 9-14. The platform and its animation frames.
0 0

Post a comment