New bitmap functions
I added three new bitmap functions:
- GetBitmapPtr gets the bitmap resource and locks it down;
- ReleaseBitmapPtr unlocks and releases the resource;
- DrawBitmapPtr draws it on the screen.
Using GetBitmapPtr, I open the bitmaps when the application starts. The bitmaps remain open until Rocketship exits.
Random number generator
When the game begins, a docking bay descends and moves back and forth, finally stopping at a random position.
To position the docking bay, I call SysRandom to get a random number. SysRandom returns a number ranging from 0 to 32767 (0x7FFF). This upper number is defined as sysRandomMax in the SysUtils.h header file.
For the rest of game play, I set a different random number generator seed when the program begins. I simply use the time in ticks.
Pausing for menus
When a user pops up the menu, the game should pause while he works the menu. This is now accomplished by checking which window we're in. When we start a game, the program remembers the main screen's window handle. When it goes to do background activity, it checks that the handle of the current window is that same main screen handle. As long as it is, we know the user hasn't changed anything -- he didn't raise the menu, go to the "about" screen, or whatever. Consequently, if the window handle had changed, we'd know something had changed, so we should pause the game.
When the main form is opened (at the frmOpenEvent in MainFormHandleEvent) we call WinGetActiveWindow to get the main form's window handle. When a nilEvent comes in (which we use for timing) we again call WinGetActiveWindow to see if we're still on the main window.
Avoiding flicker in animation
I took a short cut when displaying bitmaps in Rocketship. Because I have so little movement on the screen, it was suitable to simply erase the old bitmap and display the new one. Normally that would cause flickering. Ideally, we'd draw the screen update to an off-screen window, and then copy that window into the real display. The technique is more than I can explain right now, but there's a document on Palm's web site which does explain it. You'll find that document in the developer's section at http://www.palm.com/devzone/docs/animation/animate.html.
This will be it for Rocketship for now. There's lots of other great Programming Power topics to get into. Next month I'll start in on the serial port.
Alan Jay Weiner writes software for PalmPilots. His email address is firstname.lastname@example.org.