|
|
|
|
|
|
|
|
|
|
Finishing up Rocketship (continued)
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.
Conclusion 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 alan@ajw.com.
[ Prev ]
|
|
|
|
|
|
-- Advertisement --
ONLINE GROUP CALENDAR - FOR UP TO 100 OF YOUR CLOSEST FRIENDS
Stay organized and in control with 24/7 access to all of your important events, projects and files --whether you're at work, at home or on the road.
You can share your calendar, projects and files so everyone in your office is up to date. Plus, search your entire group to find times when everyone is available to meet, manage company resources and much more.
Organize your entire team for as low as $9.95 per year (and yes, that's where the decimal place is supposed to be!)
Tap here to get started right away. |
-- Advertisement --
SECURE YOUR SITE WITH AN IRONCLAD SSL CERTIFICATE
An IronClad SSL Certificate helps you build an impenetrable fortress around your customer's credit card information. IronClad SSL Certificates are:
- Fully validated
- Up to 256-bit encryption
- Up to 10 years validity
- Stringent authentication
- Around-the-clock customer support
Build trust. Protect your customers. Grow your online business.
Tap here now and be IronClad with SSL tonight. |
|
|
|
|
|
|