 |
| |  |
Home In This Issue Email a Friend EasyPrint
 | |
|
PROGRAMMING POWER
Rocketship: writing a PalmPilot game
By Alan Jay Weiner
My son Daniel likes to play with the PalmPilot. As he's only three, most of the games are too advanced for him, although he does like DinkyPad and the "walking game" (Kyle's Quest).
This month we'll put together a small game for him. It's simple; we can expand it next month. Actually, it's not much of a game; more of a time-waster, but it's the structure for a game. We can expand on it another time.
Daniel's a typical boy; he likes motorcycles, spaceships, knights, and anything that can be turned into a gun (which he calls a "shoot gun"). At various times he either wants to be a policeman or a "bad guy." I think we'll use spaceships for this gameÉ And no shooting.
This month's version of "Daniel's Rocketship" starts with a rocket sitting on a launch pad, as shown in Figure A. When launched, it flies upward. The hardware buttons control movement left and right. As yet, there's no goal - the rocket takes off, flies to the top of the screen and the "game" is done. This is probably a bit simple, even for Daniel.
FIGURE A
Running in the emulator, our rocket has just launched. Note the smoke/fire effect.
Rocketship is based on the original "Hello, world" application I wrote in March; most of the code will be quite familiar. The new parts include using the hardware buttons and doing things as time elapses.
3É 2É 1É BLASTOFF! I use a simple technique for animating the rocket. There are four bitmaps: the rocket (shown in Figure B), the launchpad and gantry (shown in Figure C), a blank bitmap used to clear the rocket, and a bitmap of "smoke" as the rocket lifts off.
FIGURE B
The rocket is a simple bitmap. Click picture for a larger image.
FIGURE C
This simple set of perpendicular lines becomes the gantry when the rocket is overlayed upon it. Click picture for a larger image.
Initially, I draw (well, the program draws) the launchpad and gantry. Daniel launches the rocket by tapping anywhere on the screen or by pressing the "up" button. At launch, I draw the "smoke" bitmap. Then, each time a set time period goes by, I erase the rocket and re-draw it one pixel higher.
Instead of using a blank bitmap to erase the rocket, I could use WinEraseRectangle. This would make a slightly smaller program; there'd be no blank bitmap. For now, it's convenient to just draw the blank bitmap though.
Watching the clock PalmPilot programs go idle when nothing is happening. During this idle time, power usage is drastically reduced; this is key to extended battery life.
[ Next ]
|
|
Copyright © 1998-2008, ZATZ Publishing. All rights reserved worldwide.
|