The Astral Trespassers Game
Astral Trespassers is a simple shoot-em-up space game. When executed, it generates a self-contained SWF file that implements the game shown in Figure 9-1. The player uses the mouse to control a gun positioned at the bottom of the screen—if the mouse button is clicked within the frame, a photon bullet is fired. The player is responsible for destroying a phalanx of aliens (represented by primitive blue SWF::Shape objects) that advance down the screen. This example will illustrate the use of the Ming API to create simple shapes, attach ActionScript to buttons and frames, and manipulate multiple Sprites. It also provides a rough template for your own interactive applications.
The document is created in five stages:
Create the SWF::Shape objects that are used to build the Sprites for the gun, aliens, and photon bullet.
Assemble the Shapes into Sprites.
Assemble the Sprites on the main timeline of the SWF::Movie object.
Attach ActionScript to individual Sprites and the main timeline. The ActionScript is interpreted by the Flash player and controls the movement of sprites on the Stage and user interaction when the movie is played back.
Write the Movie to a file (or STDOUT) formatted as SWF data.
The SWF document (we’ll call it astral_trespassers.swf) is about 2k in size. The following ...
Get Perl Graphics Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.