[BugRunner PIC] Chapter 11.   Sprites


A game's active entities are often encoded as sprites. A sprite is a moving graphical object, which may represent the player (and so respond to key presses and mouse actions) or be driven by 'intelligent' code in the game.

The Sprite class developed in this chapter holds a sprite's position, its speed (coded as incremental steps in the x- and y- directions), and uses the image classes (ImagesLoader, ImagesPlayer) from Chapters 5-6 to manage its graphical presence. Sprite's subclasses add user and environmental interactions, and audio effects. The coding of these classes is greatly helped by specifying them first with UML statecharts.

Many elements are utilized from earlier chapters: the animation framework of chapters 2 and 3, the image loader classes of chapter 6, and the audio loaders of chapter 8.

The BugRunner application contains an ant sprite which can be moved left and right across the base of the gaming pane to stop falling ball sprites from hitting the floor. The image at the top of this page shows BugRunner in action.




Dr. Andrew Davison
E-mail: ad@fivedots.coe.psu.ac.th
Back to my home page