diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..a44b38c --- /dev/null +++ b/AUTHORS @@ -0,0 +1,4 @@ +UPi +SAdam +DaniGM +Elio Blanca diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..34d49e4 --- /dev/null +++ b/Build.PL @@ -0,0 +1,32 @@ +use strict; +use warnings; +use Module::Build; + +my $build = Module::Build->new( + module_name => 'Games::PangZero', + all_from => 'lib/Games/PangZero.pm', + dist_abstract => 'a fast-paced action game about popping balloons with a harpoon', + dist_author => [ + 'UPi ', + 'SAdam ', + 'DaniGM ', + 'Elio Blanca ', + ], + license => 'gpl', + requires => { + 'File::ShareDir' => '0', + 'File::Spec' => '0', + 'Time::HiRes' => '0', + 'SDL' => '2.536', + }, + configure_requires => { + 'Module::Build' => '0.38', + }, + meta_merge => { + resources => { + bugtracker => 'http://github.com/kthakore/pangzero/issues', + repository => 'http://github.com/kthakore/pangzero' + } + }, + share_dir => 'data', +)->create_build_script(); diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..5b6e7c6 --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..b9f7fc4 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,479 @@ + +2012-03-12 19:42 FROGGS + * 1.4.1, fix for SDL's Joystick API + +2012-02-21 22:27 kthakore, FROGGS + * ChangeLog, VERSION, *.p[l/m]: Bumped version to 1.4, making pangzero + work with upstream release of SDL. Many fixes. + See http://cpansearch.perl.org/src/FROGGS/SDL-2.536/CHANGELOG + +2007-07-15 10:12 upi + + * bin/upipang.pl: Proper website launching for Windows. High level + table is now saved properly. + +2007-06-28 09:10 upi + + * ChangeLog, VERSION, bin/upipang.pl: Bumped version to 1.2. + +2007-06-28 09:10 upi + + * INSTALL: Basic installation instructions. + +2007-06-28 08:56 upi + + * bin/upipang.pl: Some minor tweaks. Balls smaller than level 3 no + longer have magic in them. Fixed a bug related to multiple slow + effects. Slow effect no longer survives in Challenge Mode. + Eliminated some SDL warning messages. Added TutorialGame (one on + one with a specific kind of ball). + +2007-06-28 08:47 upi + + * data/: Balls-Upside128.png, Balls-Upside64.png: Fixed background + green + +2007-06-28 08:46 upi + + * data/bonus.png: New bonus graphics + +2007-04-03 21:35 upi + + * bin/upipang.pl: Added UpsideDownBall, minor fixes. + +2007-04-03 21:33 upi + + * data/: Balls-Upside128.png, Balls-Upside16.png, + Balls-Upside32.png, Balls-Upside64.png, Balls-Upside96.png: Added + UpsideDownBall + +2007-01-04 10:38 upi + + * VERSION, bin/upipang.pl: Separate high score tables for Panic and + Challenge modes. More challenge levels. + +2007-01-03 23:31 upi + + * bin/upipang.pl: Show website at exit. + +2007-01-03 19:51 upi + + * bin/upipang.pl, data/bonus.png: Added "Matrix effect": slows the + game down for 15 sec. + +2007-01-01 09:52 upi + + * ChangeLog, VERSION: Bumped version number to 1.0 + +2007-01-01 09:50 upi + + * bin/upipang.pl: Quick fix for the Demo before 1.0 + +2006-12-31 16:32 upi + + * bin/upipang.pl: Added option for weapon durations. + +2006-12-31 15:49 upi + + * bin/upipang.pl: Some more fixes for Challenge mode. + +2006-12-31 10:54 upi + + * bin/upipang.pl: Fixes for challenge mode. Better scoreboard + layout for very small screen heights. + +2006-12-30 19:45 upi + + * bin/upipang.pl: Improved High Score table. Menu items now show + tool tips at the bottom of the screen. + +2006-12-30 12:33 upi + + * bin/upipang.pl: Player can choose Panic or Challenge game from + the menu. + +2006-12-30 10:38 upi + + * bin/upipang.pl: Bugfix for machine gun. + +2006-12-30 10:21 upi + + * bin/upipang.pl: Some speed improvements. Removed the Christmas + decor. + +2006-12-23 10:40 upi + + * bin/upipang.pl: Improved ball positioning in challenge mode. + +2006-12-20 14:16 upi + + * bin/upipang.pl, data/santa.png: Added flying Santa. + +2006-12-20 13:29 upi + + * VERSION, bin/upipang.pl, data/christmas_candle.jpg, + data/christmas_house.jpg, data/christmas_houses.jpg, + data/christmas_tree.jpg, data/christmas_trees.jpg, + data/guyChristmas.png, data/guy_r2.png: Graphics update for 0.19 + +2006-12-20 10:39 upi + + * bin/upipang.pl, data/glossyfont.png: Number of players moved to + "Player setup" menu. Several bugfixes (santa pixel bug, credits + bug, 200.000 points bonus life bug) Level display more prominent + in Challenge Game mode. Error is better reported if the program + dies. + +2006-12-16 21:41 upi + + * data/guyChristmas.png: Fix of minor graphics glitch. + +2006-12-16 21:23 upi + + * bin/upipang.pl: Minor bugfixes + +2006-12-16 14:42 upi + + * bin/upipang.pl: Bugfixing for credits screen. + +2006-12-16 09:43 upi + + * ChangeLog, VERSION, bin/upipang.pl, data/fireplace.jpg, + data/xmas-dawn.jpg, data/xmas-night.jpg: Updated version number. + Updated demo. New Christmas backgrounds. + +2006-12-15 23:33 upi + + * bin/upipang.pl, data/bonus.png: XmasBall now drops random weapon + or powerup. Hexa balls rotation is improved. + +2006-12-15 11:11 upi + + * bin/upipang.pl: Slippery floor can be toggled in the menu + +2006-12-15 09:55 upi + + * bin/upipang.pl: Added XmasBall. + +2006-12-15 09:54 upi + + * data/: Balls-Snow128.png, Balls-Snow16.png, Balls-Snow32.png, + Balls-Snow64.png, Balls-Snow96.png, Balls-XMAS128.png, + border-lighted-theme.png, border-xmas-theme.png: Updated + christmas graphics. + +2006-12-15 02:23 upi + + * bin/upipang.pl, data/Balls-Snow128.png, data/Balls-Snow16.png, + data/Balls-Snow32.png, data/Balls-Snow64.png, + data/Balls-Snow96.png, data/Balls-XMAS128.png, + data/border-lighted-theme.png, data/border-xmas-theme.png, + data/guyChristmas.png: Christmas edition graphics. Challenge + version added. + +2006-12-15 01:32 upi + + * ChangeLog, bin/upipang.pl, data/Balls-Fragile128.png, + data/Balls-Fragile16.png, data/Balls-Fragile32.png, + data/Balls-Fragile64.png, data/Balls-Fragile96.png: Minor code + refactoring. Added FragileBall. + +2006-12-04 14:00 upi + + * VERSION, bin/upipang.pl, data/bonus.png, data/border.png: + Improved border for 0.17 + +2006-12-01 15:06 upi + + * AUTHORS, ChangeLog, VERSION: Update for version 0.16 + +2006-12-01 15:06 upi + + * bin/upipang.pl: Better handling of music files. + +2006-12-01 15:05 upi + + * data/: Hexa-16.png, Hexa-32.png, Hexa-64.png: Background fixes + for Hexas. + +2006-12-01 11:16 upi + + * data/: Balls-Bouncy16.png, Balls-Bouncy32.png, + Balls-Bouncy64.png, Balls-Death64.png, Balls-EarthQ16.png, + Balls-EarthQ32.png, Balls-EarthQ64.png, Balls-Red128.png, + Balls-Red16.png, Balls-Red32.png, Balls-Red64.png, + Balls-Red96.png, Balls-Seeker32.png, Balls-Seeker64.png, + Balls-SuperClock64.png, Balls-SuperClock96.png, + Balls-SuperStar64.png, Balls-SuperStar96.png, Balls-Water16.png, + Balls-Water32.png, Balls-Water64.png, Balls-Water96.png, + Hexa-16.png, Hexa-32.png, Hexa-64.png, guy_danigm.png, + guy_pix.png, guy_pux.png, guy_r2.png, guy_sonic.png, l1.jpg, + l2.jpg, l3.jpg, l4.jpg, l5.jpg, l6.jpg, l7.jpg, l8.jpg, l9.jpg: + Data files updated + +2006-11-30 19:22 upi + + * bin/upipang.pl: New graphics, hopefully faster, too. High score + table. + +2006-10-08 00:39 upi + + * AUTHORS, ChangeLog, VERSION, bin/upipang.pl: Updated version and + credits for 0.15 + +2006-10-08 00:26 upi + + * bin/upipang.pl: Added FPS indicator. + +2006-10-07 23:47 upi + + * bin/upipang.pl: Players can now select character and color. + AlterPalette now uses display_format (hopefully faster). + +2006-10-07 23:43 upi + + * data/ball.png: New and improved ball + +2006-10-07 23:18 upi + + * data/: guy_danigm.png, guy_pix.png, guy_pux.png: Added selectable + characters. + +2006-10-05 15:07 upi + + * bin/upipang.pl: Fixed for the menu changes. + +2006-10-05 13:11 upi + + * bin/upipang.pl: Nifty menu animations. + +2006-10-05 08:47 upi + + * bin/upipang.pl: Added "ball mixer" to the menu. + +2006-09-06 10:57 upi + + * bin/upipang.pl, data/guy.png: More appealing death effect. + +2006-09-06 10:09 upi + + * data/harpoon.png: Added straight harpoon by eblanca76. + +2006-09-06 00:38 upi + + * bin/upipang.pl: More forgiving collision detection. + +2006-09-05 23:17 upi + + * bin/upipang.pl, data/harpoon.png: New harpoon graphics by + eblanca76 at sourceforge.net + +2006-09-05 18:16 upi + + * bin/upipang.pl, data/meltdown.png: Deathball Meltdown at 30+ + death balls. + +2006-09-05 15:46 upi + + * bin/upipang.pl: DeadGuy uses RotoZoom (funny effect). + +2006-09-05 13:45 upi + + * bin/upipang.pl: Fix for previous checkin. + +2006-09-05 13:44 upi + + * bin/upipang.pl: Workaround for SDL_perl 1.2.20 + +2006-09-04 22:21 upi + + * bin/upipang.pl, data/guy.png, data/level.png, + data/level_empty.png: Widescreen mode improvements, better + scoreboard. + +2006-08-21 14:10 upi + + * VERSION, ChangeLog: Updated for version 0.13 + +2006-08-21 14:08 upi + + * bin/upipang.pl: Minor graphics changes, max players set to 6 + +2006-08-21 14:05 upi + + * data/guy.png: Replaced graphics with free version by "DaniGM" + (panreyes@panreyes.com) + +2006-08-14 20:40 upi + + * bin/upipang.pl: Bugfix in background image zooming + +2006-08-14 19:01 upi + + * bin/upipang.pl: Widescreen mode. Some code cleanup. + +2006-08-07 11:38 upi + + * bin/upipang.pl: * Fixed SDL_perl 2.x compatibility issue * Added + Rewind capability to RecordGame + +2006-08-05 16:21 upi + + * bin/upipang.pl: New Demo (includes SeekerBall). Fix for SDL_perl + 2.x + +2006-08-04 20:53 upi + + * ChangeLog, VERSION: Updated for version 0.12 + +2006-08-04 20:34 upi + + * data/: bonus.png, harpoon.png: Adjusted for new weapons + +2006-08-04 20:30 upi + + * bin/upipang.pl: * Joysticks now work in the menu. * Added + "Credits" screen. * New ball type: "Seeker" ball. * Fullscreen + / window can be toggled in the menu * Refactoring: Rolled package + SpawningBall into Ball. * Refactoring: Removed individual "anim" + attributes and moved them to Game->{anim} * Made sure that the + GamePause is always on top. * Added Replay capability to normal + games. * Randomized bonus collection. * Visual enhancements * + Improved scoreboard layout * Added new difficulty level: "Miki" * + Split off "Options" menu * Controls menu now displays key names + +2006-07-28 06:17 upi + + * bin/upipang.pl: * Added new ball type: WaterBall * Added weapons + and weapon drops: MachineGun, PowerWire, HalfCutter * Code + cleanup * Uses Carp module * SuperBall now has its own BallDesc + (no extra parameter uglyness) * BallDesc now contains the package + name of the ball, so Ball::Create is cleaner * Fixed a bug which + caused GamePause to disappear sometimes. * Player lives + indicator now works for >3 lives. * Some minor fixes. + +2006-07-20 11:52 upi + + * bin/upipang.pl: Earthquake-ball related tweaks + +2006-07-20 11:37 upi + + * ChangeLog, VERSION: Updated for 0.11 + +2006-07-20 11:22 upi + + * bin/upipang.pl: Better joystick support + +2006-07-20 10:01 upi + + * bin/upipang.pl, data/gameover.png, data/paused.png: Game Over and + Paused messages + +2006-07-20 09:20 upi + + * bin/upipang.pl: New background every 10 levels + +2006-07-20 01:14 upi + + * bin/upipang.pl: Color the border red during death sequence + +2006-07-20 00:50 upi + + * bin/upipang.pl, data/bonus.png: Added pictograms for Earthquake + Balls and Death Balls + +2006-07-20 00:42 upi + + * data/quake.voc: Added Earthquake Balls + +2006-07-19 21:59 upi + + * bin/upipang.pl: Added Earthquake Balls + +2006-07-19 18:34 upi + + * bin/upipang.pl: The number of death balls spawned is now limited + to 2 + +2006-07-19 18:20 upi + + * bin/upipang.pl: Added demo / help + +2006-07-19 14:09 upi + + * bin/upipang.pl: Can take multiple screanshots with W key + +2006-07-18 12:36 upi + + * ChangeLog, VERSION: Updated for 0.10 + +2006-07-16 14:04 upi + + * bin/upipang.pl: Sound and music can be toggled on/off in main + menu + +2006-07-16 12:03 upi + + * bin/upipang.pl: Added difficulty levels. Split controls menu + from main menu. + +2006-07-15 13:34 upi + + * bin/upipang.pl: Renamed package to SpawningBall + +2006-07-15 13:06 upi + + * bin/upipang.pl: Factored the menu-related subs into a package + (more OOP!) + +2006-07-15 10:06 upi + + * bin/upipang.pl: Esc key now goes back to the menu instead of + quitting during game + +2006-07-14 23:16 upi + + * bin/upipang.pl: Added configuration loading and saving + +2006-07-13 22:53 upi + + * bin/upipang.pl: Factored apart Game and GameBase packages. + +2006-07-12 09:14 upi + + * AUTHORS, COPYING, ChangeLog, NEWS, README, TODO, VERSION: Import + of usual documentation files. + +2006-07-12 08:47 upi + + * bin/upipang.pl: Automatically find data directory (good for + autoconf) + +2006-07-12 08:14 upi + + * bin/upipang.pl: Main game loop now in the Game package. + +2006-07-11 13:31 upi + + * bin/upipang.pl: Factored many global methods and variables into + package Game. + +2006-07-10 05:55 upi + + * bin/upipang.pl: Better game balance, respawning players. + +2006-06-23 21:47 upi + + * data/: UPiPang.mid, UPiPang.mp3, ball.png, bonus.png, border.png, + brandybun3.png, desert2.png, font2.png, gun.voc, guy.png, + harpoon.png, hexa.png, level.voc, magic.voc, meow.voc, pop.voc, + pop3.voc, shoot.voc, super.voc: Initial import. + +2006-06-23 21:36 upi + + * bin/upipang.pl: Initial import + +2006-06-23 21:36 upi + + * bin/upipang.pl: Initial revision + diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..f40d45d --- /dev/null +++ b/INSTALL @@ -0,0 +1,11 @@ +Installation instuctions for Pang Zero +====================================== + +1. Download and unpack the archive + +2. Go to the unpacked directory + +3. ./configure + +4. make install + diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..75734e1 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,15 @@ +#!include_default +# Avoid configuration metadata file +^MYMETA\. + +# Avoid Module::Build generated and utility files. +\bBuild$ +\bBuild.bat$ +\b_build +\bBuild.COM$ +\bBUILD.COM$ +\bbuild.com$ +^MANIFEST\.SKIP + +# Avoid archives of this distribution +\bGames-PangZero-[\d\.\_]+ diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..29021b5 --- /dev/null +++ b/NEWS @@ -0,0 +1,5 @@ +Please visit our website at +http://apocalypse.rulez.org/pangzero + +To see what's new at the website, go to +http://apocalypse.rulez.org/pangzero/Recent_Changes diff --git a/README b/README new file mode 100644 index 0000000..af4cf59 --- /dev/null +++ b/README @@ -0,0 +1,10 @@ +Pang Zero README +================ + +Pang Zero is a clone of Super Pang, a fast-paced action game that involves +popping balloons with a harpoon. The intention of our effort is to create a +fun, open-source game that many (currently up to 6) people can play +together. + +For more info, please visit our website at +http://apocalypse.rulez.org/pangzero diff --git a/TODO b/TODO new file mode 100644 index 0000000..5b112ec --- /dev/null +++ b/TODO @@ -0,0 +1 @@ +See pangzero.pl for current TODO list. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..f923cbf --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +pangzero 1.3 diff --git a/bin/pangzero b/bin/pangzero new file mode 100755 index 0000000..cc3b51d --- /dev/null +++ b/bin/pangzero @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use lib 'lib'; +use Games::PangZero; + + +eval { + Games::PangZero::Initialize(); + #Games::PangZero::DoDemo() while 1; + #while (1) { Games::PangZero::DoRecordDemo(); $Games::PangZero::App->delay(2000); } + while (1) { + Games::PangZero::MainLoop(); + } +}; +if ($@) { + my $errorMessage = $@; + Games::PangZero::ShowErrorMessage($errorMessage); + die $errorMessage; +} diff --git a/data/Balls-Bouncy16.png b/data/Balls-Bouncy16.png new file mode 100644 index 0000000..9afd528 Binary files /dev/null and b/data/Balls-Bouncy16.png differ diff --git a/data/Balls-Bouncy32.png b/data/Balls-Bouncy32.png new file mode 100644 index 0000000..c8d9a53 Binary files /dev/null and b/data/Balls-Bouncy32.png differ diff --git a/data/Balls-Bouncy64.png b/data/Balls-Bouncy64.png new file mode 100644 index 0000000..3960dd8 Binary files /dev/null and b/data/Balls-Bouncy64.png differ diff --git a/data/Balls-Death64.png b/data/Balls-Death64.png new file mode 100644 index 0000000..38545a7 Binary files /dev/null and b/data/Balls-Death64.png differ diff --git a/data/Balls-EarthQ16.png b/data/Balls-EarthQ16.png new file mode 100644 index 0000000..68935b6 Binary files /dev/null and b/data/Balls-EarthQ16.png differ diff --git a/data/Balls-EarthQ32.png b/data/Balls-EarthQ32.png new file mode 100644 index 0000000..0e2784c Binary files /dev/null and b/data/Balls-EarthQ32.png differ diff --git a/data/Balls-EarthQ64.png b/data/Balls-EarthQ64.png new file mode 100644 index 0000000..9ed7550 Binary files /dev/null and b/data/Balls-EarthQ64.png differ diff --git a/data/Balls-Fragile128.png b/data/Balls-Fragile128.png new file mode 100644 index 0000000..13f324f Binary files /dev/null and b/data/Balls-Fragile128.png differ diff --git a/data/Balls-Fragile16.png b/data/Balls-Fragile16.png new file mode 100644 index 0000000..9835980 Binary files /dev/null and b/data/Balls-Fragile16.png differ diff --git a/data/Balls-Fragile32.png b/data/Balls-Fragile32.png new file mode 100644 index 0000000..60f1528 Binary files /dev/null and b/data/Balls-Fragile32.png differ diff --git a/data/Balls-Fragile64.png b/data/Balls-Fragile64.png new file mode 100644 index 0000000..deef115 Binary files /dev/null and b/data/Balls-Fragile64.png differ diff --git a/data/Balls-Fragile96.png b/data/Balls-Fragile96.png new file mode 100644 index 0000000..73c5663 Binary files /dev/null and b/data/Balls-Fragile96.png differ diff --git a/data/Balls-Red128.png b/data/Balls-Red128.png new file mode 100644 index 0000000..d82c8aa Binary files /dev/null and b/data/Balls-Red128.png differ diff --git a/data/Balls-Red16.png b/data/Balls-Red16.png new file mode 100644 index 0000000..feec689 Binary files /dev/null and b/data/Balls-Red16.png differ diff --git a/data/Balls-Red32.png b/data/Balls-Red32.png new file mode 100644 index 0000000..e104121 Binary files /dev/null and b/data/Balls-Red32.png differ diff --git a/data/Balls-Red64.png b/data/Balls-Red64.png new file mode 100644 index 0000000..aaf0dc9 Binary files /dev/null and b/data/Balls-Red64.png differ diff --git a/data/Balls-Red96.png b/data/Balls-Red96.png new file mode 100644 index 0000000..196f48e Binary files /dev/null and b/data/Balls-Red96.png differ diff --git a/data/Balls-Seeker32.png b/data/Balls-Seeker32.png new file mode 100644 index 0000000..747c84e Binary files /dev/null and b/data/Balls-Seeker32.png differ diff --git a/data/Balls-Seeker64.png b/data/Balls-Seeker64.png new file mode 100644 index 0000000..aedbb8f Binary files /dev/null and b/data/Balls-Seeker64.png differ diff --git a/data/Balls-SuperClock64.png b/data/Balls-SuperClock64.png new file mode 100644 index 0000000..3ae1f63 Binary files /dev/null and b/data/Balls-SuperClock64.png differ diff --git a/data/Balls-SuperClock96.png b/data/Balls-SuperClock96.png new file mode 100644 index 0000000..3084211 Binary files /dev/null and b/data/Balls-SuperClock96.png differ diff --git a/data/Balls-SuperStar64.png b/data/Balls-SuperStar64.png new file mode 100644 index 0000000..56b6b6d Binary files /dev/null and b/data/Balls-SuperStar64.png differ diff --git a/data/Balls-SuperStar96.png b/data/Balls-SuperStar96.png new file mode 100644 index 0000000..37123ec Binary files /dev/null and b/data/Balls-SuperStar96.png differ diff --git a/data/Balls-Upside128.png b/data/Balls-Upside128.png new file mode 100644 index 0000000..552a87f Binary files /dev/null and b/data/Balls-Upside128.png differ diff --git a/data/Balls-Upside16.png b/data/Balls-Upside16.png new file mode 100644 index 0000000..8a4698e Binary files /dev/null and b/data/Balls-Upside16.png differ diff --git a/data/Balls-Upside32.png b/data/Balls-Upside32.png new file mode 100644 index 0000000..451d880 Binary files /dev/null and b/data/Balls-Upside32.png differ diff --git a/data/Balls-Upside64.png b/data/Balls-Upside64.png new file mode 100644 index 0000000..09f75d2 Binary files /dev/null and b/data/Balls-Upside64.png differ diff --git a/data/Balls-Upside96.png b/data/Balls-Upside96.png new file mode 100644 index 0000000..a2ebadb Binary files /dev/null and b/data/Balls-Upside96.png differ diff --git a/data/Balls-Water16.png b/data/Balls-Water16.png new file mode 100644 index 0000000..b5ad399 Binary files /dev/null and b/data/Balls-Water16.png differ diff --git a/data/Balls-Water32.png b/data/Balls-Water32.png new file mode 100644 index 0000000..e7e8951 Binary files /dev/null and b/data/Balls-Water32.png differ diff --git a/data/Balls-Water64.png b/data/Balls-Water64.png new file mode 100644 index 0000000..9dacfa5 Binary files /dev/null and b/data/Balls-Water64.png differ diff --git a/data/Balls-Water96.png b/data/Balls-Water96.png new file mode 100644 index 0000000..9bc66dd Binary files /dev/null and b/data/Balls-Water96.png differ diff --git a/data/Balls-XMAS128.png b/data/Balls-XMAS128.png new file mode 100644 index 0000000..abc3a39 Binary files /dev/null and b/data/Balls-XMAS128.png differ diff --git a/data/Hexa-16.png b/data/Hexa-16.png new file mode 100644 index 0000000..e8087e9 Binary files /dev/null and b/data/Hexa-16.png differ diff --git a/data/Hexa-32.png b/data/Hexa-32.png new file mode 100644 index 0000000..e872a22 Binary files /dev/null and b/data/Hexa-32.png differ diff --git a/data/Hexa-64.png b/data/Hexa-64.png new file mode 100644 index 0000000..1f36016 Binary files /dev/null and b/data/Hexa-64.png differ diff --git a/data/Quad.png b/data/Quad.png new file mode 100644 index 0000000..7ac6624 Binary files /dev/null and b/data/Quad.png differ diff --git a/data/UPiPang.mid b/data/UPiPang.mid new file mode 100644 index 0000000..b82cfd3 Binary files /dev/null and b/data/UPiPang.mid differ diff --git a/data/UPiPang.mp3 b/data/UPiPang.mp3 new file mode 100644 index 0000000..1ae73d0 Binary files /dev/null and b/data/UPiPang.mp3 differ diff --git a/data/bonus.png b/data/bonus.png new file mode 100644 index 0000000..f5ebaa8 Binary files /dev/null and b/data/bonus.png differ diff --git a/data/border.png b/data/border.png new file mode 100644 index 0000000..75cbc9f Binary files /dev/null and b/data/border.png differ diff --git a/data/brandybun3.png b/data/brandybun3.png new file mode 100644 index 0000000..142a547 Binary files /dev/null and b/data/brandybun3.png differ diff --git a/data/desert2.png b/data/desert2.png new file mode 100644 index 0000000..bbc2ff7 Binary files /dev/null and b/data/desert2.png differ diff --git a/data/font2.png b/data/font2.png new file mode 100644 index 0000000..d230ad6 Binary files /dev/null and b/data/font2.png differ diff --git a/data/gameover.png b/data/gameover.png new file mode 100644 index 0000000..555cca1 Binary files /dev/null and b/data/gameover.png differ diff --git a/data/glossyfont.png b/data/glossyfont.png new file mode 100644 index 0000000..1f283ca Binary files /dev/null and b/data/glossyfont.png differ diff --git a/data/gun.voc b/data/gun.voc new file mode 100644 index 0000000..060ec8d Binary files /dev/null and b/data/gun.voc differ diff --git a/data/guyChristmas.png b/data/guyChristmas.png new file mode 100644 index 0000000..d9fc4de Binary files /dev/null and b/data/guyChristmas.png differ diff --git a/data/guy_danigm.png b/data/guy_danigm.png new file mode 100644 index 0000000..723a972 Binary files /dev/null and b/data/guy_danigm.png differ diff --git a/data/guy_pix.png b/data/guy_pix.png new file mode 100644 index 0000000..f86949b Binary files /dev/null and b/data/guy_pix.png differ diff --git a/data/guy_pux.png b/data/guy_pux.png new file mode 100644 index 0000000..912f0c4 Binary files /dev/null and b/data/guy_pux.png differ diff --git a/data/guy_r2.png b/data/guy_r2.png new file mode 100644 index 0000000..10c77ee Binary files /dev/null and b/data/guy_r2.png differ diff --git a/data/guy_sonic.png b/data/guy_sonic.png new file mode 100644 index 0000000..50b2dac Binary files /dev/null and b/data/guy_sonic.png differ diff --git a/data/harpoon.png b/data/harpoon.png new file mode 100644 index 0000000..981e380 Binary files /dev/null and b/data/harpoon.png differ diff --git a/data/icon.bmp b/data/icon.bmp new file mode 100644 index 0000000..15b2184 Binary files /dev/null and b/data/icon.bmp differ diff --git a/data/icon.ico b/data/icon.ico new file mode 100644 index 0000000..5350fee Binary files /dev/null and b/data/icon.ico differ diff --git a/data/icon.png b/data/icon.png new file mode 100644 index 0000000..58071e4 Binary files /dev/null and b/data/icon.png differ diff --git a/data/l1.jpg b/data/l1.jpg new file mode 100644 index 0000000..7220654 Binary files /dev/null and b/data/l1.jpg differ diff --git a/data/l2.jpg b/data/l2.jpg new file mode 100644 index 0000000..c05522e Binary files /dev/null and b/data/l2.jpg differ diff --git a/data/l3.jpg b/data/l3.jpg new file mode 100644 index 0000000..a957cc8 Binary files /dev/null and b/data/l3.jpg differ diff --git a/data/l4.jpg b/data/l4.jpg new file mode 100644 index 0000000..a9dce1a Binary files /dev/null and b/data/l4.jpg differ diff --git a/data/l5.jpg b/data/l5.jpg new file mode 100644 index 0000000..c849701 Binary files /dev/null and b/data/l5.jpg differ diff --git a/data/l6.jpg b/data/l6.jpg new file mode 100644 index 0000000..119546f Binary files /dev/null and b/data/l6.jpg differ diff --git a/data/l7.jpg b/data/l7.jpg new file mode 100644 index 0000000..2c27396 Binary files /dev/null and b/data/l7.jpg differ diff --git a/data/l8.jpg b/data/l8.jpg new file mode 100644 index 0000000..bf416b3 Binary files /dev/null and b/data/l8.jpg differ diff --git a/data/l9.jpg b/data/l9.jpg new file mode 100644 index 0000000..497d6cd Binary files /dev/null and b/data/l9.jpg differ diff --git a/data/level.png b/data/level.png new file mode 100644 index 0000000..97098be Binary files /dev/null and b/data/level.png differ diff --git a/data/level.voc b/data/level.voc new file mode 100644 index 0000000..dca3f19 Binary files /dev/null and b/data/level.voc differ diff --git a/data/level_empty.png b/data/level_empty.png new file mode 100644 index 0000000..7079875 Binary files /dev/null and b/data/level_empty.png differ diff --git a/data/magic.voc b/data/magic.voc new file mode 100644 index 0000000..12b7c03 Binary files /dev/null and b/data/magic.voc differ diff --git a/data/meltdown.png b/data/meltdown.png new file mode 100644 index 0000000..cfc90c5 Binary files /dev/null and b/data/meltdown.png differ diff --git a/data/meow.voc b/data/meow.voc new file mode 100644 index 0000000..e28f8d7 Binary files /dev/null and b/data/meow.voc differ diff --git a/data/paused.png b/data/paused.png new file mode 100644 index 0000000..4cd283b Binary files /dev/null and b/data/paused.png differ diff --git a/data/pop.voc b/data/pop.voc new file mode 100644 index 0000000..3bd522c Binary files /dev/null and b/data/pop.voc differ diff --git a/data/pop3.voc b/data/pop3.voc new file mode 100644 index 0000000..f9d6b9f Binary files /dev/null and b/data/pop3.voc differ diff --git a/data/quake.voc b/data/quake.voc new file mode 100644 index 0000000..10865f2 Binary files /dev/null and b/data/quake.voc differ diff --git a/data/shoot.voc b/data/shoot.voc new file mode 100644 index 0000000..571d658 Binary files /dev/null and b/data/shoot.voc differ diff --git a/data/super.voc b/data/super.voc new file mode 100644 index 0000000..12b7c03 Binary files /dev/null and b/data/super.voc differ diff --git a/lib/Games/PangZero/Ball.pm b/lib/Games/PangZero/Ball.pm new file mode 100644 index 0000000..2c9a3ca --- /dev/null +++ b/lib/Games/PangZero/Ball.pm @@ -0,0 +1,265 @@ +########################################################################## +package Games::PangZero::Ball; +########################################################################## + +use Games::PangZero::Globals; + +@ISA = qw(Games::PangZero::GameObject); +$Gravity = 0.05; +$MagicBallRect = SDL::Rect->new(80, 0, 16, 15); + +for (my $i = 0; $i <= $#Games::PangZero::BallDesc; ++$i) { + my $desc = $Games::PangZero::BallDesc[$i]; + $desc->{speedY} = 0 unless $desc->{speedY}; + $desc->{bounceY} = $desc->{speedY} * $desc->{speedY} / $Games::PangZero::Ball::Gravity / 2 unless $desc->{bounceY}; +} + +sub Create { + my ($description, $x, $y, $dir) = @_; + my ($retval); + + my $code = sprintf('$retval = Games::PangZero::%s->new(@_);', $description->{class}); + eval $code; die $@ if $@; + return $retval; +} + +sub Spawn { + my ($description, $x, $dir, $hasBonus) = @_; + my ($retval); + + $x = $Games::PangZero::Game->Rand( $Games::PangZero::ScreenWidth - $description->{width} ) if $x < 0; + $retval = Games::PangZero::Ball::Create( $description, $x, -$description->{height} - $Games::PangZero::ScreenMargin, $dir ); + $retval->GiveMagic() if $retval->{w} > 32; + $retval->GiveBonus() if $hasBonus; + + $retval->{spawning} = 1; + my $surfaceName = 'dark' . $description->{surface}; + $retval->{surface} = $Games::PangZero::BallSurfaces{$surfaceName}; + die "No surface: $surfaceName" unless $retval->{surface}; + return $retval; +} + +sub new { + my ($class, $description, $x, $y, $dir) = @_; + my $self = Games::PangZero::GameObject->new(); + %{$self} = ( %{$self}, + 'x' => $x, + 'y' => $y, + 'w' => $description->{width}, + 'h' => $description->{height}, + 'surface' => $Games::PangZero::BallSurfaces{$description->{surface}}, + 'hexa' => $description->{hexa} ? 1 : 0, + 'desc' => $description, + 'hasmagic' => 0, # true if one of the ball's descendants is magic + 'ismagic' => 0, # true if the ball IS magic + 'spawning' => 0, + ); + $self->{speedX} = $dir > 0 ? 1.3 : -1.3; + $self->SetupCollisions(); + bless $self, $class; +} + +sub NormalAdvance { + my $self = shift; + + $self->{speedY} += $Games::PangZero::Ball::Gravity * $Games::PangZero::GameSpeed unless ($self->{hexa}); + $self->{x} += $self->{speedX} * $Games::PangZero::GameSpeed; + $self->{y} += $self->{speedY} * $Games::PangZero::GameSpeed; + if ($self->{y} > $Games::PangZero::ScreenHeight - $self->{h}) { + $self->{y} = $Games::PangZero::ScreenHeight - $self->{h}; + if ($self->{hexa}) { + $self->{speedY} = -abs($self->{speedY}); + } else { + $self->{speedY} = -$self->{desc}->{speedY}; + } + $self->Bounce; + } + if ($self->{y} < 0) { + $self->{y} = 0; + $self->{speedY} = abs($self->{speedY}); + } + if ($self->{x} < 0) { + $self->{x} = 0; + $self->{speedX} = abs( $self->{speedX} ); + } + if ($self->{x} > $Games::PangZero::ScreenWidth - $self->{w}) { + $self->{x} = $Games::PangZero::ScreenWidth - $self->{w}; + $self->{speedX} = -abs( $self->{speedX} ); + } +} + +sub SpawningAdvance { + my $self = shift; + + $self->{y} += 0.32; + if ($self->{y} >= 0) { + $self->{spawning} = 0; + $self->{surface} = $Games::PangZero::BallSurfaces{$self->{desc}->{surface}}, + } +} + +sub Advance { + my $self = shift; + + unless( $Games::PangZero::GamePause > 0 ) { + if ($self->{spawning}) { + $self->SpawningAdvance(); + } else { + $self->NormalAdvance(); + } + } + + $self->CheckCollisions() unless $Games::PangZero::Game->{nocollision} or $self->{spawning}; +} + +sub Bounce { +} + +sub CheckCollisions { + my $self = shift; + + foreach my $harpoon (values %Games::PangZero::Harpoon::Harpoons) { + if ($self->Collisions($harpoon)) { + $self->Pop($harpoon->{guy}, $harpoon->{popEffect}); + $harpoon->Delete(); + return; + } + } + foreach my $guy (values %Games::PangZero::Guy::Guys) { + if ($Games::PangZero::GamePause <= 0 and $self->Collisions($guy)) { + $guy->Kill(); + } + } +} + +sub Draw { + my ($self) = @_; + + return if $Games::PangZero::GamePause > 0 and $Games::PangZero::GamePause < 100 and (int($Games::PangZero::GamePause / 3) % 4) < 2; + + $self->TransferRect(); + if ($self->{ismagic} and int($Games::PangZero::Game->{anim}/4) % 2) { + SDL::Video::blit_surface($Games::PangZero::BallSurfaces{ball4}, $Games::PangZero::Ball::MagicBallRect, $Games::PangZero::App, $self->{rect} ); + } else { + SDL::Video::blit_surface($self->{surface}, $self->{desc}->{rect}, $Games::PangZero::App, $self->{rect} ); + } +} + +sub Collisions { + my ($self, $other) = @_; + + # Bounding box detection + + return unless $self->SUPER::Collisions($other); + + # Circle vs rectangle collision + + my ($centerX, $centerY, $boxAxisX, $boxAxisY, $boxCenterX, $boxCenterY, $distSquare, $distance); + $boxAxisX = ($other->{collisionw} or $other->{w}) / 2; + $boxAxisY = ($other->{collisionh} or $other->{h}) / 2; + $boxCenterX = $other->{x} + $other->{w} / 2; + $boxCenterY = $other->{y} + $other->{h} / 2; + $centerX = $self->{x} + $self->{w} / 2; + $centerY = $self->{y} + $self->{h} / 2; + + # Translate coordinates to the box center + $centerX -= $boxCenterX; + $centerY -= $boxCenterY; + $centerX = abs($centerX); + $centerY = abs($centerY); + + if ($centerX < $boxAxisX) { + return 1 if $centerY < $boxAxisY + $self->{h} / 2; + return 0; + } + if ($centerY < $boxAxisY) { + return 2 if $centerX < $boxAxisX + $self->{w} / 2; + return 0; + } + $distSquare = ($centerX-$boxAxisX) * ($centerX-$boxAxisX); + $distSquare += ($centerY-$boxAxisY) * ($centerY-$boxAxisY); + return 3 if $distSquare < $self->{h} * $self->{h} / 4; + + return 0; +} + +sub Pop { + my ($self, $guy, $popEffect) = @_; + + Carp::confess "no $popEffect" unless defined $popEffect; + $Games::PangZero::GameEvents{'pop'} = 1; + $Games::PangZero::GameEvents{'magic'} = 1 if ($self->{ismagic}); + $guy->GiveScore($self->{desc}->{score}) if $guy; + $self->Delete(); + + goto skipChildren if ($popEffect eq 'meltdown'); + + if ($self->{desc}->{nextgen}) { + die caller unless $self->{desc}->{nextgen}->{class}; + my @children = $self->SpawnChildren(); + if (scalar @children) { + $self->AdjustChildren(@children); + if ($popEffect eq 'HalfCutter') { + push @Games::PangZero::GameObjects, ($self->{speedX} > 0 ? $children[1] : $children[0]); + } else { + push @Games::PangZero::GameObjects, (@children); + } + } + } + if ($self->{bonus} and $popEffect ne 'superkill') { + push @Games::PangZero::GameObjects, Games::PangZero::BonusDrop->new($self); + } + $Games::PangZero::Game->OnBallPopped(); + + skipChildren: + push @Games::PangZero::GameObjects, Games::PangZero::Pop->new($self->{x}, $self->{y}, $self->{desc}->{popIndex}, $self->{surface}); +} + +sub SpawnChildren { + my $self = shift; + my $nextgen = $self->{desc}->{nextgen}; + die caller unless $nextgen->{class}; + my $x = $self->{x} + $self->{w} / 2; + my $y = $self->{y} + ( $self->{h} - $nextgen->{height} ) / 2; + my $child1 = Create($nextgen, $self->{x}, $y, 0); + my $child2 = Create($nextgen, $self->{x} + $self->{w} - $nextgen->{width}, $y, 1); + + return ($child1, $child2); +} + +sub AdjustChildren { + my ($self, @children) = @_; + my ($nextgen, $speedY, $altitude); + + if ($self->{hasmagic}) { + $children[0]->GiveMagic(); + } + + $nextgen = $self->{desc}->{nextgen}; + $altitude = $Games::PangZero::ScreenHeight - $self->{y} - $self->{h}; + $speedY = 1.8; + unless ($altitude > $nextgen->{bounceY}) { + $speedY = 1.8; + while ($speedY * $speedY / $Games::PangZero::Ball::Gravity / 2 + $altitude < $nextgen->{bounceY}) { + ++$speedY; + } + } + foreach (@children) { + $_->{speedY} = -$speedY; + } +} + +sub GiveMagic { + my $self = shift; + + $self->{hasmagic} = 1; + $self->{ismagic} = 1 unless $self->{desc}->{nextgen}; +} + +sub GiveBonus { + my $self = shift; + + $self->{bonus} = 1; +} + +1; diff --git a/lib/Games/PangZero/BonusDrop.pm b/lib/Games/PangZero/BonusDrop.pm new file mode 100644 index 0000000..34cae4e --- /dev/null +++ b/lib/Games/PangZero/BonusDrop.pm @@ -0,0 +1,100 @@ +package Games::PangZero::BonusDrop; + +@ISA = qw(Games::PangZero::GameObject); +use strict; +use warnings; + +use vars qw(@BonusDesc); + +@BonusDesc = ( +# MachineGun is disabled for now as it is broken (seems like invisible bullets keep flying around) +# { 'weaponClass' => 'MachineGun', 'bonusDelay' => 1500, 'srcRect' => SDL::Rect->new( 0, 64, 32, 32), }, + { 'weaponClass' => 'HalfCutter', 'bonusDelay' => 1000, 'srcRect' => SDL::Rect->new(32, 64, 32, 32), }, + { 'weaponClass' => 'PowerWire', 'bonusDelay' => 3000, 'srcRect' => SDL::Rect->new(32, 96, 32, 32), }, + { 'onCollectedSub' => \&OnCollectedSlowEffect, 'srcRect' => SDL::Rect->new(32, 0, 32, 32), }, +); + + +sub new { + my ($class, $ball) = @_; + my ($self); + + $self = Games::PangZero::GameObject->new(); + + %{$self} = ( %{$self}, + 'x' => $ball->{x} + ($ball->{w} - 32) / 2, + 'y' => $ball->{y} + ($ball->{h} - 32) / 2, + 'w' => 32, + 'h' => 32, + 'speedY' => -3, + 'speedX' => 0, + 'bottomDelay' => 500, + 'desc' => $BonusDesc[int $Games::PangZero::Game->Rand(scalar @BonusDesc)], + ); + bless $self, $class; +} + +sub Advance { + my $self = shift; + + if ($self->{y} >= $Games::PangZero::ScreenHeight - $self->{h}) { + $self->{y} = $Games::PangZero::ScreenHeight - $self->{h}; + if (--$self->{bottomDelay} < 0) { + $self->Delete(); + } + } else { + $self->{speedY} += 0.1; + $self->{y} += $self->{speedY}; + } + + $self->CheckCollisions() if $self->{speedY} >= 0; +} + +sub CheckCollisions { + my $self = shift; + my ($guy, @guysTouched); + + foreach $guy (@Games::PangZero::GameObjects) { + next unless ref($guy) eq 'Games::PangZero::Guy'; + next unless $self->Collisions($guy); + push @guysTouched, ($guy); + } + return unless @guysTouched; + $self->Collected($guysTouched[$Games::PangZero::Game->Rand( scalar @guysTouched )]); +} + +sub SetOnCollectedSub { + my ($self, $onCollectedSub) = @_; + $self->{onCollectedSub} = $onCollectedSub; +} + +sub Collected { + my ($self, $guy) = @_; + + if ($self->{onCollectedSub}) { + $self->{onCollectedSub}->($self, $guy); + } elsif ($self->{desc}->{onCollectedSub}) { + $self->{desc}->{onCollectedSub}->($self, $guy); + } else { + $guy->{weapon} = $self->{desc}->{weaponClass}; + $guy->{bonusDelay} = $self->{desc}->{bonusDelay} * $Games::PangZero::WeaponDuration->{durationmultiplier}; + } + $self->Delete(); +} + +sub Draw { + my $self = shift; + + return if $self->{bottomDelay} < 100 and (($Games::PangZero::Game->{anim} / 4) % 2 < 1); + $self->TransferRect(); + SDL::Video::blit_surface($Games::PangZero::BonusSurface, $self->{desc}->{srcRect}, $Games::PangZero::App, $self->{rect}); +} + +sub OnCollectedSlowEffect { + my ($self, $guy) = @_; + + Games::PangZero::SlowEffect::RemoveSlowEffects(); + push @Games::PangZero::GameObjects, Games::PangZero::SlowEffect->new(); +} + +1; diff --git a/lib/Games/PangZero/ChallengeGame.pm b/lib/Games/PangZero/ChallengeGame.pm new file mode 100644 index 0000000..3d7096b --- /dev/null +++ b/lib/Games/PangZero/ChallengeGame.pm @@ -0,0 +1,95 @@ +########################################################################## +package Games::PangZero::ChallengeGame; +########################################################################## + +@ISA = qw(Games::PangZero::PlayableGameBase); +use strict; +use warnings; + +sub new { + my ($class) = @_; + my $self = Games::PangZero::PlayableGameBase->new(); + %{$self} = (%{$self}, + 'challenge' => undef, + ); + bless $self, $class; +} + +sub SetGameLevel { + my ($self, $level) = @_; + + Games::PangZero::SlowEffect::RemoveSlowEffects(); + $self->SUPER::SetGameLevel($level); + $level = $#Games::PangZero::ChallengeLevels if $level > $#Games::PangZero::ChallengeLevels; + $self->{challenge} = $Games::PangZero::ChallengeLevels[$level]; + die unless $self->{challenge}; + $self->SpawnChallenge(); +} + +sub AdvanceGame { + my ($self) = @_; + + if ($self->{nextlevel}) { + Games::PangZero::Music::PlaySound('level'); + $self->SetGameLevel($self->{level} + 1); + delete $self->{nextlevel}; + } + if ($self->{playerspawned}) { + $self->SpawnChallenge(); + $self->{playerspawned} = 0; + } + $self->SUPER::AdvanceGame(); +} + +sub SpawnChallenge { + my $self = shift; + my ($challenge, @guys, $balldesc, $ball, $hasBonus, %balls, $numBalls, $ballsSpawned, @ballKeys, $x); + + @guys = $self->PopEveryBall(); + foreach (@guys) { + $_->{bonusDelay} = 1; + $_->{invincible} = 1; + } + $Games::PangZero::GamePause = 0; + delete $Games::PangZero::GameEvents{magic}; + $challenge = $self->{challenge}; + die unless $challenge; + + while ($challenge =~ /(\w+)/g) { + $balldesc = $Games::PangZero::BallDesc{$1}; + warn "Unknown ball in challenge: $1" unless $balldesc; + $balls{$1}++; + $numBalls++; + } + $ballsSpawned = 0; + while ($ballsSpawned < $numBalls) { + foreach (keys %balls) { + next unless $balls{$_}; + --$balls{$_}; + $balldesc = $Games::PangZero::BallDesc{$_}; + $x = $Games::PangZero::ScreenWidth * ($ballsSpawned * 2 + 1) / ($numBalls * 2) - $balldesc->{width} / 2; + $x = $Games::PangZero::ScreenWidth - $balldesc->{width} if $x > $Games::PangZero::ScreenWidth - $balldesc->{width}; + $hasBonus = (($balldesc->{width} >= 32) and ($self->Rand(1) < $Games::PangZero::DifficultyLevel->{bonusprobability})); + $ball = &Games::PangZero::Ball::Spawn($balldesc, $x, ($ballsSpawned % 2) ? 0 : 1, $hasBonus); + if ($ball->{w} <= 32) { + $ball->{ismagic} = $ball->{hasmagic} = 0; + } + push @Games::PangZero::GameObjects, ($ball) ; + ++$ballsSpawned; + } + } +} + +sub OnBallPopped { + my $self = shift; + my ($i); + + for ($i = $#Games::PangZero::GameObjects; $i >= 0; --$i) { + if ($Games::PangZero::GameObjects[$i]->isa('Games::PangZero::Ball')) { + return; + } + } + $self->{nextlevel} = 1; +} + +1; diff --git a/lib/Games/PangZero/Config.pm b/lib/Games/PangZero/Config.pm new file mode 100644 index 0000000..eb26d05 --- /dev/null +++ b/lib/Games/PangZero/Config.pm @@ -0,0 +1,146 @@ +########################################################################## +# CONFIG SAVE/LOAD +########################################################################## + +package Games::PangZero::Config; + +use File::ShareDir qw(dist_dir); + +sub IsMicrosoftWindows { + return $^O eq 'MSWin32'; +} + + +sub TestDataDir { + return -f "$Games::PangZero::DataDir/glossyfont.png"; # Should be a file from the latest version. +} + +sub FindDataDir { + return if $Games::PangZero::DataDir and TestDataDir(); + my @guesses = ('.', dist_dir('Games-PangZero')); + foreach my $guess (@guesses) { + $Games::PangZero::DataDir = $guess; + return if TestDataDir(); + $Games::PangZero::DataDir = "$guess/data"; + return if TestDataDir(); + } + die "Couldn't find the data directory. Please set it manually."; +} + +sub GetConfigFilename { + if ( IsMicrosoftWindows() ) { + if ($ENV{USERPROFILE}) { + return "$ENV{USERPROFILE}\\pangzero.cfg"; + } + return "$Games::PangZero::DataDir/pangzero.cfg"; + } + if ($ENV{HOME}) { + return "$ENV{HOME}/.pangzerorc"; + } + if (-w $Games::PangZero::DataDir) { + return "$Games::PangZero::DataDir/pangzero.cfg"; + } + return "/tmp/pangzero.cfg"; +} + +sub GetConfigVars { + my ($i, $j); + my @result = qw( + Games::PangZero::NumGuys + Games::PangZero::DifficultyLevelIndex + Games::PangZero::WeaponDurationIndex + Games::PangZero::Slippery + Games::PangZero::MusicEnabled + Games::PangZero::SoundEnabled + Games::PangZero::FullScreen + Games::PangZero::ShowWebsite + Games::PangZero::DeathBallsEnabled + Games::PangZero::EarthquakeBallsEnabled + Games::PangZero::WaterBallsEnabled + Games::PangZero::SeekerBallsEnabled + ); + for ($i=0; $i < scalar @Games::PangZero::Players; ++$i) { + for ($j=0; $j < 3; ++$j) { + push @result, ("Games::PangZero::Players[$i]->{keys}->[$j]"); + } + push @result, ("Games::PangZero::Players[$i]->{colorindex}"); + push @result, ("Games::PangZero::Players[$i]->{imagefileindex}"); + } + my ($difficulty, $gameMode); + for ($difficulty=0; $difficulty < scalar @Games::PangZero::DifficultyLevels; ++$difficulty) { + foreach $gameMode ('highScoreTablePan', 'highLevelTablePan', 'highScoreTableCha', 'highLevelTableCha') { + next if ($Games::PangZero::DifficultyLevels[$difficulty]->{name} eq 'Miki' and $gameMode eq 'highScoreTableCha'); + for ($i=0; $i < 5; ++$i) { + push @result, "Games::PangZero::DifficultyLevels[$difficulty]->{$gameMode}->[$i]->[0]", # Name of high score + "Games::PangZero::DifficultyLevels[$difficulty]->{$gameMode}->[$i]->[1]", # High score + } + } + } + return @result; +} + +sub SaveConfig { + my ($filename, $varname, $value); + $filename = GetConfigFilename(); + + open CONFIG, "> $filename" or return; + foreach $varname (GetConfigVars()) { + eval("\$value = \$$varname"); die $@ if $@; + print CONFIG "\$$varname = $value\n"; + } + close CONFIG; +} + +sub LoadConfig { + my ($filename, $text, $varname); + + $text = ''; + $filename = GetConfigFilename(); + if (open CONFIG, "$filename") { + read CONFIG, $text, 16384; + close CONFIG; + } + + foreach $varname (GetConfigVars()) { + my $pattern = $varname; + $pattern =~ s/\[/\\[/g; + if ($text =~ /$pattern = (.+?)$/m) { + $val = $1; + if ($varname eq Games::PangZero::ShowWebsite) { + eval( "\$$varname = '$val'" ); + } + elsif($val =~ /^SDLK_\w+$/) { + eval( "\$$varname = SDL::Events::$val()" ); + } + elsif($val =~ /^[\d\.]+$/) { + eval( "\$$varname = $val" ); + } + else { + eval( "\$$varname = '$val'" ); + } + } + } + + SetDifficultyLevel($Games::PangZero::DifficultyLevelIndex); + SetWeaponDuration($Games::PangZero::WeaponDurationIndex); +} + +sub SetDifficultyLevel { + my $difficultyLevelIndex = shift; + if ($difficultyLevelIndex < 0 or $difficultyLevelIndex > $#Games::PangZero::DifficultyLevels) { + $difficultyLevelIndex = $Games::PangZero::DifficultyLevelIndex; + } + $Games::PangZero::DifficultyLevelIndex = $difficultyLevelIndex; + $Games::PangZero::DifficultyLevel = $Games::PangZero::DifficultyLevels[$difficultyLevelIndex]; +} + +sub SetWeaponDuration { + my $weaponDurationIndex = shift; + if ($weaponDurationIndex < 0 or $weaponDurationIndex > $#Games::PangZero::WeaponDurations) { + $weaponDurationIndex = $Games::PangZero::WeaponDurationIndex; + } + $Games::PangZero::WeaponDurationIndex = $weaponDurationIndex; + $Games::PangZero::WeaponDuration = $Games::PangZero::WeaponDurations[$Games::PangZero::WeaponDurationIndex]; +} + +1; diff --git a/lib/Games/PangZero/DeadGuy.pm b/lib/Games/PangZero/DeadGuy.pm new file mode 100644 index 0000000..f534872 --- /dev/null +++ b/lib/Games/PangZero/DeadGuy.pm @@ -0,0 +1,83 @@ +########################################################################## +package Games::PangZero::DeadGuy; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); +use strict; +use warnings; + +sub new { + my ($class, $guy, $dir) = @_; + my ($self, $player); + + $self = Games::PangZero::GameObject->new(); + $player = $guy->{player}; + + %{$self} = ( %{$self}, + 'x' => $guy->{x}, + 'y' => $guy->{y}, + 'w' => 64, + 'h' => 64, + 'speedY' => -7, + 'surface' => $player->{guySurface}, + 'anim' => 0, + 'bounce' => 0, + 'bouncex' => 0, + ); + $self->{'speedX'} = ($Games::PangZero::Game->Rand(2) + 1.5) * (($self->{x} > $Games::PangZero::ScreenWidth / 2) ? 1 : -1); + bless $self, $class; +} + +sub Advance { + my $self = shift; + + $self->{speedY} += 0.1; + $self->{x} += $self->{speedX}; + $self->{y} += $self->{speedY}; + + unless ($self->{bouncex}) { + if ($self->{x} < -16) { + $self->{x} = -16; + $self->{speedX} = abs( $self->{speedX} ); + $self->{speedY} = -3 if $self->{speedY} > -3; + $self->{bouncex} = 1; + } + if ($self->{x} > $Games::PangZero::ScreenWidth - $self->{w} +16) { + $self->{x} = $Games::PangZero::ScreenWidth - $self->{w} + 16; + $self->{speedX} = -abs( $self->{speedX} ); + $self->{speedY} = -3 if $self->{speedY} > -3; + $self->{bouncex} = 1; + } + } + if ($self->{y} > $Games::PangZero::ScreenHeight - 64 and not $self->{bounce}) { + $self->{bounce} = 1; + $self->{speedY} = -3; + } + + if ($self->{y} > $Games::PangZero::PhysicalScreenHeight) { + $self->Delete; + } + $self->{anim} += $self->{speedX} > 0 ? -1 : +1; +} + +sub Draw { + my $self = shift; + my ($srcrect); + + $srcrect = SDL::Rect->new(($self->{speedX} > 0 ? 0 : 64), 128, 64, 64 ); + $self->TransferRect(); + if(SDL::Config->has('SDL_gfx_rotozoom')) { + my $roto = SDL::Surface->new( SDL::Video::SDL_SWSURFACE(), 64, 64, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF); + SDL::Video::blit_surface($self->{surface}, $srcrect, $roto, SDL::Rect->new(0, 0, $roto->w, $roto->h) ); + $roto = SDL::GFX::Rotozoom::surface($roto, $self->{anim} * 5, 1, SDL::GFX::Rotozoom::SMOOTHING_OFF()); + $self->{rect}->x( $self->{rect}->x - ($roto->w - 64) / 2 ); + $self->{rect}->y( $self->{rect}->y - ($roto->h - 64) / 2 ); + SDL::Video::blit_surface($roto, SDL::Rect->new(0, 0, 64, 64), $Games::PangZero::App, $self->{rect} ); + return; + } + else { + SDL::Video::blit_surface($self->{surface}, $srcrect, $Games::PangZero::App, $self->{rect} ); + } +} + +1; diff --git a/lib/Games/PangZero/DeathBall.pm b/lib/Games/PangZero/DeathBall.pm new file mode 100644 index 0000000..082fd88 --- /dev/null +++ b/lib/Games/PangZero/DeathBall.pm @@ -0,0 +1,54 @@ +########################################################################## +package Games::PangZero::DeathBall; +########################################################################## + +@ISA = qw(Games::PangZero::Ball); +use strict; +use warnings; + +sub new { + my $class = shift; + my $self = Games::PangZero::Ball->new(@_); + $self->{expires} = 2000; # 20sec + $self->{speedX} *= 0.9; + bless $self, $class; +} + +sub NormalAdvance { + my $self = shift; + + $self->SUPER::NormalAdvance(); + if (--$self->{expires} < 0) { + $self->{bonus} = 1 if $self->{hasmagic}; + $self->Pop(undef, 'expire'); + } + +} + +sub Pop { + my ($self, $guy, $popEffect) = @_; + + $self->{dontspawn} = 1 if $popEffect eq 'expire' or $popEffect eq 'superkill'; + $self->SUPER::Pop($guy, $popEffect); + if (CountDeathBalls() > 30) { + $Games::PangZero::GameEvents{'meltdown'} = 1; + } +} + +sub SpawnChildren { + my $self = shift; + + return if $self->{dontspawn}; + $self->SUPER::SpawnChildren(@_); +} + +sub CountDeathBalls { + my $count = 0; + + foreach my $ball (@Games::PangZero::GameObjects) { + if (ref($ball) eq 'Games::PangZero::DeathBall') { ++$count; } + } + return $count; +} + +1; diff --git a/lib/Games/PangZero/DemoGame.pm b/lib/Games/PangZero/DemoGame.pm new file mode 100644 index 0000000..34fcfac --- /dev/null +++ b/lib/Games/PangZero/DemoGame.pm @@ -0,0 +1,48 @@ +########################################################################## +package Games::PangZero::DemoGame; +########################################################################## + +@ISA = qw(Games::PangZero::PanicGame); + +sub ResetGame { + my $self = shift; + Games::PangZero::Config::SetDifficultyLevel(1); + Games::PangZero::Config::SetWeaponDuration(0); + $Games::PangZero::Slippery = 0; + $self->SUPER::ResetGame(); + + my $ball = Games::PangZero::Ball::Create($Games::PangZero::BallDesc[4], 400, 0, -10, 0); + $ball->GiveMagic(); + + push @Games::PangZero::GameObjects, ( + Games::PangZero::Ball::Create($Games::PangZero::BallDesc[0], 100, 0, 1), + Games::PangZero::Ball::Create($Games::PangZero::BallDesc{super0}, 300, 0, 0), + Games::PangZero::Ball::Create($Games::PangZero::BallDesc{super1}, 500, 0, 1), + $ball, + ); + $Games::PangZero::GamePause = 0; + $Games::PangZero::GameSpeed = 0.8; + $self->{spawndelay} = $self->{superballdelay} = 1000000; + $self->{ballcounter} = 0; + $self->{balls} = [ qw(b0 h0 w1 quake death seeker) ]; +} + +sub SetGameSpeed { + $Games::PangZero::GameSpeed = 0.8; +} + +sub SpawnBalls { + my $self = shift; + + return if (--$self->{spawndelay} > 0); + my $ballName = $self->{balls}->[$self->{ballcounter}]; + return unless $ballName; + push @Games::PangZero::GameObjects, ( Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc{$ballName}, 100, 1, 0) ); + $self->{spawndelay} = 1000000; + ++$self->{ballcounter}; +} + +sub RespawnPlayers {} +sub OnBallPopped {} + +1; diff --git a/lib/Games/PangZero/DemoPlaybackGame.pm b/lib/Games/PangZero/DemoPlaybackGame.pm new file mode 100644 index 0000000..0172eb5 --- /dev/null +++ b/lib/Games/PangZero/DemoPlaybackGame.pm @@ -0,0 +1,26 @@ +########################################################################## +package Games::PangZero::DemoPlaybackGame; +########################################################################## + +@ISA = qw(Games::PangZero::DemoGame Games::PangZero::PlaybackGame); +use strict; +use warnings; + +sub new { + my $class = shift; + my $self = Games::PangZero::PlaybackGame->new(@_); + bless $self, $class; +} + +sub DrawScoreBoard { + my $self = shift; + my $x = 10; + my $y = $Games::PangZero::ScreenHeight + 2 * $Games::PangZero::ScreenMargin + 5; + if ($self->{anim} < 1) { + SDLx::SFont::print_text( $Games::PangZero::Background, $x, $y, "Press F to fast forward" ); + SDLx::SFont::print_text( $Games::PangZero::App, $x, $y, "Press F to fast forward" ); + } return; + SDL::Video::fill_rect($Games::PangZero::App, SDL::Rect->new(0, $y, $Games::PangZero::PhysicalScreenWidth, $Games::PangZero::PhysicalScreenHeight - $y), SDL::Video::map_RGB($Games::PangZero::App->format(), 0, 0, 0)); + SDLx::SFont::print_text( $Games::PangZero::App, $x, $y, $self->{recordpointer} ); + +} diff --git a/lib/Games/PangZero/DemoRecordGame.pm b/lib/Games/PangZero/DemoRecordGame.pm new file mode 100644 index 0000000..725c2a1 --- /dev/null +++ b/lib/Games/PangZero/DemoRecordGame.pm @@ -0,0 +1,15 @@ +########################################################################## +package Games::PangZero::DemoRecordGame; +########################################################################## + +@ISA = qw(Games::PangZero::DemoGame Games::PangZero::RecordGame); +use strict; +use warnings; + +sub new { + my $class = shift; + my $self = Games::PangZero::RecordGame->new(@_); + bless $self, $class; +} + +1; diff --git a/lib/Games/PangZero/EarthquakeBall.pm b/lib/Games/PangZero/EarthquakeBall.pm new file mode 100644 index 0000000..3949118 --- /dev/null +++ b/lib/Games/PangZero/EarthquakeBall.pm @@ -0,0 +1,32 @@ +########################################################################## +package Games::PangZero::EarthquakeBall; +########################################################################## + +@ISA = qw(Games::PangZero::Ball); +use strict; +use warnings; + +sub new { + my $class = shift; + my $self = Games::PangZero::Ball->new(@_); + bless $self, $class; +} + +sub CountEarthquakeBalls { + my $count = 0; + + foreach my $ball (@Games::PangZero::GameObjects) { + if (ref($ball) eq 'Games::PangZero::EarthquakeBall') { ++$count; } + } + return $count; +} + +sub Bounce { + my $self = shift; + + unless ($Games::PangZero::GameEvents{earthquake} and $Games::PangZero::GameEvents{earthquake} > $self->{desc}->{quake}) { + $Games::PangZero::GameEvents{earthquake} = [$self->{desc}->{quake}, $self->{x}]; + } +} + +1; diff --git a/lib/Games/PangZero/FpsIndicator.pm b/lib/Games/PangZero/FpsIndicator.pm new file mode 100644 index 0000000..5f6ccf6 --- /dev/null +++ b/lib/Games/PangZero/FpsIndicator.pm @@ -0,0 +1,29 @@ +########################################################################## +package Games::PangZero::FpsIndicator; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); + +sub new { + my ($class) = @_; + my $self = Games::PangZero::GameObject->new(); + my $width = Games::PangZero::Graphics::TextWidth("999"); + %{$self} = ( %{$self}, + 'x' => $Games::PangZero::ScreenWidth - $width + $Games::PangZero::ScreenMargin, + 'y' => -$Games::PangZero::ScreenMargin, + 'w' => $width, + 'h' => 32, + ); + + $self->TransferRect(); + bless $self, $class; +} + +sub Draw { + my $self = shift; + + SDLx::SFont::print_text( $Games::PangZero::App, $self->{rect}->x, $self->{rect}->y, Games::PangZero::GameTimer::GetFramesPerSecond() ); + +} + +1; diff --git a/lib/Games/PangZero/FragileBall.pm b/lib/Games/PangZero/FragileBall.pm new file mode 100644 index 0000000..8fbc803 --- /dev/null +++ b/lib/Games/PangZero/FragileBall.pm @@ -0,0 +1,41 @@ +########################################################################## +package Games::PangZero::FragileBall; +########################################################################## + +@ISA = qw( Games::PangZero::Ball ); +use strict; +use warnings; + +sub Bounce { + my $self = shift; + if ($self->{desc}->{nextgen}) { + $self->{bonus} = 0; + $self->Pop(undef, ''); + } + $self->{speedX} = ($self->{speedX} > 0) ? 1.3 : -1.3; +} + +sub SpawnChildren { + my $self = shift; + my (@children, $child, $i); + + my $nextgen = $self->{desc}->{nextgen}; + die caller unless $nextgen->{class}; + my $numchildren = 2; + while ($nextgen->{nextgen}) { + $nextgen = $nextgen->{nextgen}; + $numchildren *= 2; + } + + my $y = $self->{y} + ($self->{h} - $nextgen->{height}) / 2; + for ($i = 0; $i < $numchildren; ++$i) { + $child = Games::PangZero::Ball::Create($nextgen, $self->{x}, $y, 0); + $child->{speedX} = -1.5 + ($i / ($numchildren-1) * 3); + $child->{x} = $self->{x} + ($self->{w} - $child->{w}) * ($i / ($numchildren-1)); + push @children, $child; + } + + return @children; +} + +1; diff --git a/lib/Games/PangZero/GameBase.pm b/lib/Games/PangZero/GameBase.pm new file mode 100644 index 0000000..620eb7d --- /dev/null +++ b/lib/Games/PangZero/GameBase.pm @@ -0,0 +1,110 @@ +########################################################################## +package Games::PangZero::GameBase; +########################################################################## + +use SDL; +use SDL::Video; + +sub new { + my ($class) = @_; + my $self = { + abortgame => 0, + anim => 0, + nocollision => 0, + backgrounds => [ 'desert2.png', ], + }; + $Games::PangZero::GameSpeed = 1.0; + $Games::PangZero::GamePause = 0; + bless $self, $class; +} + +sub Exit { + Games::PangZero::ShowWebPage("http://apocalypse.rulez.org/pangzero/Thanks_For_Playing_Pang_Zero_$Games::PangZero::VERSION" ) if $Games::PangZero::ShowWebsite ne $Games::PangZero::VERSION; + exit; +} + +sub Rand { + shift; + return rand($_[0]); +} + +sub Delay { + my ($self, $ticks) = @_; + + while ($ticks > 0) { + my $advance = $self->CalculateAdvances(); + %Games::PangZero::Events = (); + Games::PangZero::HandleEvents(); + return if $self->{abortgame}; + $ticks -= $advance; + $self->DrawGame(); + } +} + +sub SetGameSpeed { +} + +sub SetBackground { + my ($self, $backgroundIndex) = @_; + + return if $backgroundIndex >= scalar( @{$self->{backgrounds}} ); + Games::PangZero::Graphics::LoadBackground($self->{backgrounds}->[$backgroundIndex]); + SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h), $Games::PangZero::App, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h)); +} + +sub ShowTooltip { +} + +sub ResetGame { + my $self = shift; + @Games::PangZero::GameObjects = (); + %Games::PangZero::Guy::Guys = (); + %Games::PangZero::Harpoon::Harpoons = (); + $Games::PangZero::GamePause = 0; + %Games::PangZero::GameEvents = (); + $self->SetBackground(0); +} + +sub CalculateAdvances { + my $advance = Games::PangZero::GameTimer::GetAdvances(); + while ($advance <= 0) { + SDL::delay(3); # Wait 3ms = 0.3 game ticks + $advance = Games::PangZero::GameTimer::GetAdvances(); + } + if ($advance > 5) { + # print STDERR "advance = $advance!\n"; + $advance = 5; + } + return $advance; +} + +sub AdvanceGameObjects { + my ($self) = @_; + + ++$self->{anim}; + foreach my $gameObject (@Games::PangZero::GameObjects) { + $gameObject->Advance(); + } +} + +sub OnBallPopped { +} + +sub DrawGame { + my ($self) = @_; + + my ($gameObject); + foreach $gameObject (@Games::PangZero::GameObjects) { + $gameObject->Clear(); + } + $self->DrawScoreBoard(); + foreach $gameObject (@Games::PangZero::GameObjects) { + $gameObject->Draw(); + } + SDL::Video::flip($Games::PangZero::App); +} + +sub DrawScoreBoard { +} + +1; diff --git a/lib/Games/PangZero/GameObject.pm b/lib/Games/PangZero/GameObject.pm new file mode 100644 index 0000000..a7b939b --- /dev/null +++ b/lib/Games/PangZero/GameObject.pm @@ -0,0 +1,96 @@ +########################################################################## +package Games::PangZero::GameObject; +########################################################################## + +sub new { + my ($class) = @_; + my $self = { + 'rect' => SDL::Rect->new( 0, 0, 0, 0 ), + 'speedX' => 0, + 'speedY' => 0, + 'x' => 0, + 'y' => 0, + 'w' => 10, + 'h' => 10, + }; + bless $self, $class; +} + +sub Delete { + my $self = shift; + + for (my $i = 0; $i < scalar @Games::PangZero::GameObjects; ++$i) { + if ($Games::PangZero::GameObjects[$i] eq $self) { + splice @Games::PangZero::GameObjects, $i, 1; + last; + } + } + $self->{deleted} = 1; + $self->Clear(); +} + +sub Advance { + my $self = shift; + + $self->{advance}->($self) if $self->{advance}; +} + +sub Clear { + my ($self) = @_; + SDL::Video::blit_surface($Games::PangZero::Background, $self->{rect}, $Games::PangZero::App, $self->{rect}); +} + +sub TransferRect { + my ($self) = @_; + + $self->{rect}->x($self->{x} + $Games::PangZero::ScreenMargin); + $self->{rect}->y($self->{y} + $Games::PangZero::ScreenMargin); + $self->{rect}->w($self->{w}); + $self->{rect}->h($self->{h}); +} + +sub Draw { + my ($self) = @_; + + $self->TransferRect(); + if ($self->{draw}) { + $self->{draw}->($self); + } else { + SDL::Video::fill_rect($Games::PangZero::App, $self->{rect}, SDL::Video::map_RGB($Games::PangZero::App->format(), 0x80, 0, 0)); + } +} + +sub SetupCollisions { + my ($self) = @_; + + $self->{collisionw} = ($self->{collisionw} or $self->{w}); + $self->{collisionh} = ($self->{collisionh} or $self->{h}); + $self->{collisionmarginw1} = ( $self->{w} - $self->{collisionw} ) / 2; + $self->{collisionmarginw2} = $self->{collisionmarginw1} + $self->{collisionw}; + $self->{collisionmarginh1} = ( $self->{h} - $self->{collisionh} ) / 2; + $self->{collisionmarginh2} = $self->{collisionmarginh1} + $self->{collisionh}; + $self->{centerx} = $self->{w} / 2; + $self->{centery} = $self->{y} / 2; +} + +sub Collisions { + my ($self, $other) = @_; + + # Bounding box detection + + unless ($self->{collisionmarginw1} and $other->{collisionmarginw1}) { + return 0 if $self->{x} >= $other->{x} + $other->{w}; + return 0 if $other->{x} >= $self->{x} + $self->{w}; + return 0 if $self->{y} >= $other->{y} + $other->{h}; + return 0 if $other->{y} >= $self->{y} + $self->{h}; + return 1; + } + + return 0 if $self->{x} + $self->{collisionmarginw1} >= $other->{x} + $other->{collisionmarginw2}; + return 0 if $other->{x} + $other->{collisionmarginw1} >= $self->{x} + $self->{collisionmarginw2}; + return 0 if $self->{y} + $self->{collisionmarginh1} >= $other->{y} + $other->{collisionmarginh2}; + return 0 if $other->{y} + $other->{collisionmarginh1} >= $self->{y} + $self->{collisionmarginh2}; + return 1; +} + +1; diff --git a/lib/Games/PangZero/GamePause.pm b/lib/Games/PangZero/GamePause.pm new file mode 100644 index 0000000..a3dde8d --- /dev/null +++ b/lib/Games/PangZero/GamePause.pm @@ -0,0 +1,54 @@ +########################################################################## +package Games::PangZero::GamePause; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); + +sub Show { + foreach my $gameObject (@Games::PangZero::GameObjects) { + return if (ref $gameObject eq 'Games::PangZero::GamePause'); + } + push @Games::PangZero::GameObjects, Games::PangZero::GamePause->new(); +} + +sub new { + my ($class) = @_; + my $self = Games::PangZero::GameObject->new(); + my $width = Games::PangZero::Graphics::TextWidth("Time left: 9.999"); + %{$self} = ( %{$self}, + 'x' => ($Games::PangZero::PhysicalScreenWidth - $width) / 2, + 'y' => 100, + 'w' => $width, + 'h' => 32, + ); + $self->TransferRect(); + bless $self, $class; +} + +sub BringToFront { + my $self = shift; + + @Games::PangZero::GameObjects = grep { $_ ne $self } @Games::PangZero::GameObjects; + push @Games::PangZero::GameObjects, ($self); +} + +sub Advance { + my $self = shift; + + if ($Games::PangZero::GamePause <= 0) { + $self->Delete; + return; + } + unless ($Games::PangZero::GameObjects[$#Games::PangZero::GameObjects] eq $self) { + $self->BringToFront(); + } +} + +sub Draw { + my $self = shift; + + SDLx::SFont::print_text( $Games::PangZero::App, $self->{rect}->x, $self->{rect}->y, "Time left: " . ($Games::PangZero::GamePause / 100) ); + +} + +1; diff --git a/lib/Games/PangZero/GameTimer.pm b/lib/Games/PangZero/GameTimer.pm new file mode 100644 index 0000000..08f117d --- /dev/null +++ b/lib/Games/PangZero/GameTimer.pm @@ -0,0 +1,36 @@ +########################################################################## +package Games::PangZero::GameTimer; +########################################################################## + +use vars qw($FirstTick $LastTick $TotalAdvances $LastFpsTick $LastFps $Fps); + +sub ResetTimer { + $FirstTick = SDL::get_ticks(); + $LastTick = $LastFpsTick = $FirstTick; + $TotalAdvances = 0; + $Fps = $LastFps = 0; +} + +sub GetAdvances { + my ($ticks, $advance); + + $ticks = SDL::get_ticks(); + $advance = int(($ticks - $FirstTick) / 10) - $TotalAdvances; + $TotalAdvances += $advance; + + # Calculate frames per second; + ++$Fps if $advance > 0; + if ($ticks - $LastFpsTick > 1000) { + $LastFps = $Fps; + $LastFpsTick = $ticks; + $Fps = 0; + } + + return $advance; +} + +sub GetFramesPerSecond { + return $LastFps; +} + +1; diff --git a/lib/Games/PangZero/Globals.pm b/lib/Games/PangZero/Globals.pm new file mode 100644 index 0000000..4f39fcd --- /dev/null +++ b/lib/Games/PangZero/Globals.pm @@ -0,0 +1,248 @@ +########################################################################## +# GLOBAL CONFIGURATION +########################################################################## +package Games::PangZero::Globals; + +use Games::PangZero::Config; +use SDL::Rect; + +%Games::PangZero::Sounds = ( + 'pop' => 'pop.voc', + 'shoot' => 'shoot.voc', + 'death' => 'meow.voc', + 'level' => 'level.voc', + 'bonuslife' => 'magic.voc', + 'pause' => 'pop3.voc', + 'quake' => 'quake.voc', +); + +@Games::PangZero::DifficultyLevels = ( + { 'name' => 'Easy', 'spawnmultiplier' => 1.2, 'speed' => 0.8, 'harpoons' => 5, 'superball' => 0.8, 'bonusprobability' => 0.2, }, + { 'name' => 'Normal', 'spawnmultiplier' => 1.0, 'speed' => 1.0, 'harpoons' => 3, 'superball' => 1.0, 'bonusprobability' => 0.1, }, + { 'name' => 'Hard', 'spawnmultiplier' => 0.9, 'speed' => 1.2, 'harpoons' => 2, 'superball' => 1.1, 'bonusprobability' => 0.05, }, + { 'name' => 'Nightmare','spawnmultiplier' => 0.8, 'speed' => 1.4, 'harpoons' => 2, 'superball' => 1.5, 'bonusprobability' => 0.02, }, + { 'name' => 'Miki', 'spawnmultiplier' => 0.4, 'speed' => 1.0, 'harpoons' => 3, 'superball' => 1.0, 'bonusprobability' => 0.1, }, +); +Games::PangZero::Config::SetDifficultyLevel(1); +@Games::PangZero::WeaponDurations = ( + { 'name' => 'Short (Default)', 'durationmultiplier' => 1, }, + { 'name' => 'Medium', 'durationmultiplier' => 3, }, + { 'name' => 'Long', 'durationmultiplier' => 6, }, + { 'name' => 'Very Long', 'durationmultiplier' => 12, }, + { 'name' => 'Forever', 'durationmultiplier' => 10000, }, +); +Games::PangZero::Config::SetWeaponDuration(0); + +$Games::PangZero::NumGuys = 1; +@Games::PangZero::Players = ( + { 'keys' => [SDLK_LEFT, SDLK_RIGHT, SDLK_UP], }, # blue + { 'keys' => [SDLK_a, SDLK_d, SDLK_s], }, # red + { 'keys' => [SDLK_j, SDLK_l, SDLK_k], }, # green + { 'keys' => [SDLK_KP6, SDLK_KP4, SDLK_KP5], }, # pink + { 'keys' => [SDLK_KP6, SDLK_KP4, SDLK_KP5], }, # yellow + { 'keys' => [SDLK_KP6, SDLK_KP4, SDLK_KP5], }, # cyan + { 'keys' => [SDLK_KP6, SDLK_KP4, SDLK_KP5], }, # gray + { 'keys' => [SDLK_KP6, SDLK_KP4, SDLK_KP5], }, # snot + { 'keys' => [SDLK_KP6, SDLK_KP4, SDLK_KP5], }, # purple +); +@Games::PangZero::GuyImageFiles = ( 'guyChristmas.png', 'guy_danigm.png', 'guy_pix.png', 'guy_pux.png', 'guy_r2.png', 'guy_sonic.png' ); +@Games::PangZero::GuyColors = ( [170, 255, 'blue'], [ 0, 255, 'red'], [ 85, 255, 'green'], [212, 255, 'pink'], + [ 42, 255, 'yellow'], [128, 255, 'cyan'], [128, 0, 'gray'], [113, 128, 'snot'], [212, 64, 'purple'] ); +for (my $i=0; $i<=$#Games::PangZero::Players; ++$i) { + $Games::PangZero::Players[$i]->{number} = $i; + $Games::PangZero::Players[$i]->{colorindex} = $i; + $Games::PangZero::Players[$i]->{imagefileindex} = $i % scalar(@Games::PangZero::GuyImageFiles); +} + +my %n0 = ('popIndex' => 0, 'rect' => SDL::Rect->new(0, 0, 128, 106)); +my %n1 = ('popIndex' => 1, 'rect' => SDL::Rect->new(0, 0, 96, 80)); +my %n2 = ('popIndex' => 2, 'rect' => SDL::Rect->new(0, 0, 64, 53)); +my %n3 = ('popIndex' => 3, 'rect' => SDL::Rect->new(0, 0, 32, 28)); +my %n4 = ('popIndex' => 4, 'rect' => SDL::Rect->new(0, 0, 16, 15)); + +@Games::PangZero::BallDesc = ( +# Normal balls (n0 .. n4) + { 'name' => 'n0', 'class' => 'Ball', 'score' => 2000, 'spawndelay' => 1, 'speedY' => 6.5, %n0, 'surface' => 'ball0', 'nextgen' => 'n1', }, + { 'name' => 'n1', 'class' => 'Ball', 'score' => 1000, 'spawndelay' => 0.5, 'speedY' => 5.7, %n1, 'surface' => 'ball1', 'nextgen' => 'n2', }, + { 'name' => 'n2', 'class' => 'Ball', 'score' => 800, 'spawndelay' => 0.25, 'speedY' => 5, %n2, 'surface' => 'ball2', 'nextgen' => 'n3', }, + { 'name' => 'n3', 'class' => 'Ball', 'score' => 600, 'spawndelay' => 0.12, 'speedY' => 4, %n3, 'surface' => 'ball3', 'nextgen' => 'n4', }, + { 'name' => 'n4', 'class' => 'Ball', 'score' => 500, 'spawndelay' => 0.05, 'speedY' => 3, %n4, 'surface' => 'ball4', }, +# "Bouncy" balls (b0..b2) + { 'name' => 'b0', 'class' => 'Ball', 'score' => 1500, 'spawndelay' => 0.5, 'speedY' => 5.7, %n2, 'surface' => 'bouncy2', 'nextgen' => 'b1', }, + { 'name' => 'b1', 'class' => 'Ball', 'score' => 750, 'spawndelay' => 0.2, 'speedY' => 5, %n3, 'surface' => 'bouncy3', 'nextgen' => 'b2', }, + { 'name' => 'b2', 'class' => 'Ball', 'score' => 500, 'spawndelay' => 0.1, 'speedY' => 4.2, %n4, 'surface' => 'bouncy4' }, +# Hexas (h0..h2) + { 'name' => 'h0', 'class' => 'Hexa', 'score' => 1500, 'spawndelay' => 0.5, 'popIndex' => 5, 'hexa' => 1, + 'surface' => 'hexa0', 'rect' => SDL::Rect->new(0, 0, 64, 52), 'nextgen' => 'h1', }, + { 'name' => 'h1', 'class' => 'Hexa', 'score' => 1000, 'spawndelay' => 0.2, 'popIndex' => 6, 'hexa' => 1, + 'surface' => 'hexa1', 'rect' => SDL::Rect->new(0, 0, 32, 28), 'nextgen' => 'h2', }, + { 'name' => 'h2', 'class' => 'Hexa', 'score' => 500, 'spawndelay' => 0.1, 'popIndex' => 7, 'hexa' => 1, + 'surface' => 'hexa2', 'rect' => SDL::Rect->new(0, 0, 16, 14), + 'magicrect' => SDL::Rect->new(48, 0, 16, 14), }, +# Water ball + { 'name' => 'w1', 'class' => 'WaterBall', 'score' => 1500, 'spawndelay' => 0.4, 'speedY' => 5.7, %n1, 'surface' => 'blue1', 'nextgen' => 'w2', }, + { 'name' => 'w2', 'class' => 'WaterBall', 'score' => 1000, 'spawndelay' => 0.2, 'speedY' => 5, %n2, 'surface' => 'blue2', 'nextgen' => 'w3', }, + { 'name' => 'w3', 'class' => 'WaterBall', 'score' => 800, 'spawndelay' => 0.1, 'speedY' => 4, %n3, 'surface' => 'blue3', 'nextgen' => 'w4', }, + { 'name' => 'w4', 'class' => 'WaterBall', 'score' => 600, 'spawndelay' => 0.05, 'speedY' => 3, %n4, 'surface' => 'blue4', }, +# Fragile + { 'name' => 'f0', 'class' => 'FragileBall', 'score' => 1500, 'spawndelay' => 0.8, 'speedY' => 6.5, %n0, 'surface' => 'frag0', 'nextgen' => 'f1', }, + { 'name' => 'f1', 'class' => 'FragileBall', 'score' => 1500, 'spawndelay' => 0.4, 'speedY' => 5.7, %n1, 'surface' => 'frag1', 'nextgen' => 'f2', }, + { 'name' => 'f2', 'class' => 'FragileBall', 'score' => 1000, 'spawndelay' => 0.2, 'speedY' => 5, %n2, 'surface' => 'frag2', 'nextgen' => 'f3', }, + { 'name' => 'f3', 'class' => 'FragileBall', 'score' => 800, 'spawndelay' => 0.1, 'speedY' => 4, %n3, 'surface' => 'frag3', 'nextgen' => 'f4', }, + { 'name' => 'f4', 'class' => 'FragileBall', 'score' => 600, 'spawndelay' => 0.05, 'speedY' => 3, %n4, 'surface' => 'frag4', }, +# Superball + { 'name' => 'super0', 'class' => 'SuperBall', 'score' => 1000, 'spawndelay' => 0.5, 'speedY' => 5.7, %n1, 'surface' => 'green1', }, + { 'name' => 'super1', 'class' => 'SuperBall', 'score' => 800, 'spawndelay' => 0.25, 'speedY' => 5, %n2, 'surface' => 'green2', }, + { 'name' => 'xmas', 'class' => 'XmasBall', 'score' => 1000, 'spawndelay' => 0.5, 'speedY' => 6.5, %n0, 'surface' => 'xmas', }, +# Death + { 'name' => 'death', 'class' => 'DeathBall', 'score' => 0, 'spawndelay' => 0.5, 'speedY' => 5, %n2, 'surface' => 'death2', 'nextgen' => 'death', }, +# Seeker + { 'name' => 'seeker', 'class' => 'SeekerBall', 'score' => 1200, 'spawndelay' => 0.2, 'speedY' => 5.7, %n2, 'surface' => 'white2', 'nextgen' => 'seeker1', }, + { 'name' => 'seeker1', 'class' => 'SeekerBall', 'score' => 1200, 'spawndelay' => 0.1, 'speedY' => 5, %n3, 'surface' => 'white3', }, +# Quake + { 'name' => 'quake', 'class' => 'EarthquakeBall', 'score' => 1600, 'spawndelay' => 0.7, 'speedY' => 5.7, %n2, 'surface' => 'quake2', + 'quake' => 5, 'nextgen' => 'quake1', }, + { 'name' => 'quake1', 'class' => 'EarthquakeBall', 'score' => 1200, 'spawndelay' => 0.2, 'speedY' => 5, %n3, 'surface' => 'quake3', + 'quake' => 3, 'nextgen' => 'quake2', }, + { 'name' => 'quake2', 'class' => 'EarthquakeBall', 'score' => 1000, 'spawndelay' => 0.1, 'speedY' => 4.2, %n4, 'surface' => 'quake4', + 'quake' => 2, }, +# Upside down ball + { 'name' => 'u0', 'class' => 'UpsideDownBall', 'score' => 2000, 'spawndelay' => 1, 'speedY' => 5.8, %n0, 'surface' => 'upside0', 'nextgen' => 'u1', }, + { 'name' => 'u1', 'class' => 'UpsideDownBall', 'score' => 1000, 'spawndelay' => 0.5, 'speedY' => 5.8, %n1, 'surface' => 'upside1', 'nextgen' => 'u2', }, + { 'name' => 'u2', 'class' => 'UpsideDownBall', 'score' => 800, 'spawndelay' => 0.25, 'speedY' =>5.8, %n2, 'surface' => 'upside2', 'nextgen' => 'u3', }, + { 'name' => 'u3', 'class' => 'UpsideDownBall', 'score' => 600, 'spawndelay' => 0.12, 'speedY' =>5.9, %n3, 'surface' => 'upside3', 'nextgen' => 'u4', }, + { 'name' => 'u4', 'class' => 'UpsideDownBall', 'score' => 500, 'spawndelay' => 0.05, 'speedY' =>5.9, %n4, 'surface' => 'upside4', }, + + { 'name' => 'credits1', 'class' => 'Ball', 'speedY' => 6.1, 'nextgen' => 'credits1', 'surface' => 'blue3', %n3 }, + { 'name' => 'credits2', 'class' => 'Ball', 'speedY' => 6.1, 'nextgen' => 'credits2', 'surface' => 'ball3', %n3 }, +); +{ + foreach my $ballDesc (@Games::PangZero::BallDesc) { + $ballDesc->{width} = $ballDesc->{rect}->w(); + $ballDesc->{height} = $ballDesc->{rect}->h(); + $Games::PangZero::BallDesc{$ballDesc->{name}} = $ballDesc; + } + foreach my $ballDesc (@Games::PangZero::BallDesc) { + my $nextgen = $ballDesc->{nextgen}; + $ballDesc->{nextgen} = $Games::PangZero::BallDesc{$nextgen} if $nextgen; + } +} + +@Games::PangZero::ChallengeLevels = ( + 'n4 n4 n4 n4 xmas', + 'n3 n3 n3', + 'n2 n2', + 'b0 b0', + 'h2 h2 h2 h2 h2 h2', + 'h0 h0', + 'n1 f2', + 'w1 n2', + 'n0 b0 w1 h0', +# 10 + 'n1 quake', + 'n1 b0 quake', + 'w1 seeker u2', + 'n0 seeker seeker', + 'w1 w1', + 'f1 quake h0', + 'w1 seeker h0 h0', + 'n0 w1 w1 b0 h0', + 'u0 u0 quake', + 'quake quake w1 b0 h0', +# 20 + 'death n1 b0', + 'n4 ' x 24, + 'w1 w1 w1 f0', + 'death w1 h0', + 'n0 n0 u0 seeker h2 h2 b0', + 'n4 b2 h2 u4 ' x 6, + 'quake quake quake b0', + 'h0 h0 h0 h0 h0 h0 h0 h0', + 'quake seeker f3 n1 b0 b0', + 'death death w1 f0 n0 u2 h0', +# 30 + 'n0 n0 u0 u0', + 'death quake n1', + 'b0 h0 n2 ' x 3, + 'w1 w1 w1 w1 f1 f1', + 'n3 n3 n3 u3 ' x 4, + 'quake quake seeker seeker n0 f0', + 'seeker ' x 8, + 'n0 n1 n2 n3 n4 b0 f2 h0 h1 h2 w1 seeker', + 'quake quake quake h0 h0 h0 u2', + 'death quake seeker w1 n0 b0 h0', +# 40 + 'n0 n1 n2 ' x 3, + 'death quake seeker u2 ' x 3, + 'f0 f0', + 'death quake f0 n1 ' x 2, + 'h0 ' x 8 . ' f0 f1 ', + 'death ' x 10, + 'quake b0 ' x 5, + 'w1 w1 f0 f1 death', + 'seeker ' x 13, + 'n0 u0 w1 f0 quake death ' x 2, +); + +for ( my $i = 0; $i < 10; ++$i) { + $Games::PangZero::ChallengeLevels[$i + 49] = $Games::PangZero::ChallengeLevels[$i + 9] . ' ' . $Games::PangZero::ChallengeLevels[$i + 29]; + $Games::PangZero::ChallengeLevels[$i + 59] = $Games::PangZero::ChallengeLevels[$i + 19] . ' ' . $Games::PangZero::ChallengeLevels[$i + 39]; +} +foreach (@Games::PangZero::ChallengeLevels) { + while (/(\w+)/g) { + die "Unknown ball '$1' in challenge '$_'" unless defined $Games::PangZero::BallDesc{$1}; + } +} + +my %BallMixes = ( + 'easy' => [ qw(n0 2 n1 20 n2 10 n3 3 n4 2 f0 3 f1 5 f2 5 b0 5 b1 2 b2 1 w1 10 h0 5 h1 3 h2 1 quake 1 seeker 2 u1 1 u2 2 u3 4 u4 1) ], + 'medium' => [ qw(n0 10 n1 20 n2 10 n3 3 n4 2 f0 3 f1 3 b0 10 b1 2 b2 1 w1 15 h0 15 h1 5 h2 1 death 2 quake 5 seeker 10 u0 2 u1 5 u2 5 u3 5) ], + 'bouncy' => [ qw(n0 20 n1 10 n2 5 n3 1 n4 1 f0 3 f1 3 b0 30 b1 9 b2 1 w1 10 h0 15 h1 5 death 5 quake 10 seeker 15 u0 5 u1 5 u2 1 u3 1) ], + 'hard' => [ qw(n0 20 n1 10 n2 5 n3 1 f0 5 f1 1 b0 20 b1 2 w1 20 h0 20 h1 5 death 10 quake 15 seeker 20 u0 5 u1 5 u2 1 u3 1) ], + 'watery' => [ qw(n0 20 n1 10 n2 5 n3 1 n4 1 f0 3 f1 1 b0 10 b1 5 w1 50 h0 15 h1 5 death 5 quake 10 seeker 15 u0 1 u1 5 u2 5 u3 1) ], + 'hexas' => [ qw(n0 20 n1 10 n2 5 n3 1 f0 3 f1 1 b0 15 b1 2 w1 20 h0 40 h1 15 death 5 quake 10 seeker 15 u0 1 u1 8 u2 2 u3 1) ], + 'quakes' => [ qw(n0 15 n1 10 n2 5 n3 1 f0 3 f1 1 b0 15 w1 15 h0 20 h1 5 death 5 quake 40 seeker 15 u0 8 u1 1 u2 2 u3 1) ], +); + +sub AddLevels { + my ($num, $balls, $gamespeedStart, $gamespeedEnd, $spawndelayStart, $spawndelayEnd) = @_; + my ($i, $level); + + for ($i = 0; $i < $num; ++$i) { + $level = { + 'balls' => $balls, + 'gamespeed' => $gamespeedStart + ($gamespeedEnd - $gamespeedStart) * ($i) / ($num), + 'spawndelay' => $spawndelayStart + ($spawndelayEnd - $spawndelayStart) * ($i) / ($num), + }; + push @Games::PangZero::PanicLevels, ( $level ); + } +} + +AddLevels( 9, $BallMixes{easy}, 0.75, 1.25, 20, 20 ); # 0-9 +AddLevels( 10, $BallMixes{medium}, 0.7 , 1.3 , 20, 15 ); # 1x +AddLevels( 10, $BallMixes{hard}, 0.7 , 1.5 , 15, 15 ); # 2x +AddLevels( 10, $BallMixes{hexas}, 1.0 , 1.5 , 15, 12 ); # 3x +AddLevels( 10, $BallMixes{watery}, 0.7 , 1.7 , 15, 17 ); # 4x +AddLevels( 10, $BallMixes{bouncy}, 1.0 , 2.0 , 12, 12 ); # 5x +AddLevels( 10, $BallMixes{quakes}, 1.5 , 2.2 , 13, 8 ); # 6x +AddLevels( 10, $BallMixes{hard}, 1.0 , 2.2 , 13, 10 ); # 7x +AddLevels( 10, $BallMixes{hexas}, 1.3 , 2.4 , 12, 9 ); # 8x +AddLevels( 10, $BallMixes{hard}, 2.0 , 3.0 , 13, 10 ); # 9x + +# Set defaults + +$Games::PangZero::ScreenMargin = 16; +$Games::PangZero::ScreenWidth = 800 - $Games::PangZero::ScreenMargin * 2; +$Games::PangZero::ScreenHeight = 416; +$Games::PangZero::SoundEnabled = 1; +$Games::PangZero::MusicEnabled = 1; +$Games::PangZero::DeathBallsEnabled = 1; +$Games::PangZero::EarthquakeBallsEnabled = 1; +$Games::PangZero::WaterBallsEnabled = 1; +$Games::PangZero::SeekerBallsEnabled = 1; +$Games::PangZero::FullScreen = 1; +$Games::PangZero::UnicodeMode = 0; +$Games::PangZero::Slippery = 0; +$Games::PangZero::ShowWebsite = 0; + +1; diff --git a/lib/Games/PangZero/Graphics.pm b/lib/Games/PangZero/Graphics.pm new file mode 100644 index 0000000..262605d --- /dev/null +++ b/lib/Games/PangZero/Graphics.pm @@ -0,0 +1,276 @@ +package Games::PangZero::Graphics; + +use strict; +use warnings; + +use SDL; +use SDL::Surface; +use SDL::Palette; +use SDL::PixelFormat; +use SDL::Video; +use SDL::Event; +use SDL::Events; +use SDL::Color; +use SDL::Config; +use SDL::Cursor; +use SDL::GFX::Rotozoom; +use SDL::Mixer; +use SDL::Mixer::Samples; +use SDL::Mixer::Channels; +use SDL::Mixer::Music; +use SDL::Mixer::MixChunk; +use SDL::Mixer::MixMusic; +use SDL::Joystick; +use SDL::Mouse; +use SDL::Image; +use SDLx::SFont; + +sub LoadSurfaces { + my ($i, $transparentColor); + + my %balls = qw ( + ball0 Balls-Red128.png ball1 Balls-Red96.png ball2 Balls-Red64.png ball3 Balls-Red32.png ball4 Balls-Red16.png + xmas Balls-XMAS128.png + ball4 Balls-Red16.png ball3 Balls-Red32.png + bouncy2 Balls-Bouncy64.png bouncy3 Balls-Bouncy32.png bouncy4 Balls-Bouncy16.png + hexa0 Hexa-64.png hexa1 Hexa-32.png hexa2 Hexa-16.png + blue1 Balls-Water96.png blue2 Balls-Water64.png blue3 Balls-Water32.png blue4 Balls-Water16.png + frag0 Balls-Fragile128.png frag1 Balls-Fragile96.png frag2 Balls-Fragile64.png frag3 Balls-Fragile32.png frag4 Balls-Fragile16.png + green1 Balls-SuperClock96.png green2 Balls-SuperClock64.png gold1 Balls-SuperStar96.png gold2 Balls-SuperStar64.png + death2 Balls-Death64.png + white2 Balls-Seeker64.png white3 Balls-Seeker32.png + quake2 Balls-EarthQ64.png quake3 Balls-EarthQ32.png quake4 Balls-EarthQ16.png + upside0 Balls-Upside128.png upside1 Balls-Upside96.png upside2 Balls-Upside64.png upside3 Balls-Upside32.png upside4 Balls-Upside16.png + ); + + foreach (sort keys %balls) { + $Games::PangZero::BallSurfaces{$_} = SDL::Image::load("$Games::PangZero::DataDir/$balls{$_}"); + $Games::PangZero::BallSurfaces{$_} = SDL::Video::display_format($Games::PangZero::BallSurfaces{$_}); + $transparentColor = $Games::PangZero::BallSurfaces{$_}->get_pixel(0); + SDL::Video::set_color_key($Games::PangZero::BallSurfaces{$_}, SDL_SRCCOLORKEY, $transparentColor ); + $Games::PangZero::BallSurfaces{"dark$_"} = SDL::Image::load( "$Games::PangZero::DataDir/$balls{$_}"); + $Games::PangZero::BallSurfaces{"dark$_"} = SDL::Video::display_format($Games::PangZero::BallSurfaces{"dark$_"}); + SDL::Video::set_color_key($Games::PangZero::BallSurfaces{"dark$_"}, SDL_SRCCOLORKEY, $Games::PangZero::BallSurfaces{"dark$_"}->get_pixel(0) ); + SDL::Video::set_alpha($Games::PangZero::BallSurfaces{"dark$_"}, SDL_SRCALPHA, 128); + } + + $Games::PangZero::BorderSurface = SDL::Image::load("$Games::PangZero::DataDir/border.png"); + $Games::PangZero::RedBorderSurface = SDL::Image::load("$Games::PangZero::DataDir/border.png"); + $Games::PangZero::WhiteBorderSurface = SDL::Image::load("$Games::PangZero::DataDir/border.png"); + $Games::PangZero::BonusSurface = SDL::Image::load("$Games::PangZero::DataDir/bonus.png"); + $Games::PangZero::LevelIndicatorSurface = SDL::Image::load("$Games::PangZero::DataDir/level.png"); + $Games::PangZero::LevelIndicatorSurface2 = SDL::Image::load("$Games::PangZero::DataDir/level_empty.png"); + + AlterPalette( $Games::PangZero::RedBorderSurface, sub { 1; }, + sub { shift @_; my ($h, $s, $i) = Games::PangZero::Palette::RgbToHsi(@_); + return Games::PangZero::Palette::HsiToRgb( $h - 30, $s, $i * 0.75 + 63); } ); + AlterPalette( $Games::PangZero::WhiteBorderSurface, sub { 1; }, + sub { shift @_; my ($h, $s, $i) = Games::PangZero::Palette::RgbToHsi(@_); + return Games::PangZero::Palette::HsiToRgb( 0, 0, $i*0.25 + 191 ); } ); + + MakeGuySurfaces(); +} + +sub MakeGuySurface { + my ($player) = @_; + my ($guySurfaceFile, $guySurface, $whiteGuySurface, $harpoonSurface); + + $guySurfaceFile = $Games::PangZero::DataDir . '/' . $Games::PangZero::GuyImageFiles[ $player->{imagefileindex} % scalar(@Games::PangZero::GuyImageFiles) ]; + $guySurface = SDL::Image::load($guySurfaceFile); + $whiteGuySurface = SDL::Image::load($guySurfaceFile); + $harpoonSurface = SDL::Image::load("$Games::PangZero::DataDir/harpoon.png"); + $player->{hue} = $Games::PangZero::GuyColors[$player->{colorindex}]->[0]; + $player->{saturation} = $Games::PangZero::GuyColors[$player->{colorindex}]->[1]; + + AlterPalette($whiteGuySurface, sub {1;}, sub { return (255, 255, 255); } ); + AlterPalette( $guySurface, sub { $_[3] > $_[2] and $_[3] > $_[1]; }, + sub { + shift @_; + my ($h, $s, $i) = Games::PangZero::Palette::RgbToHsi(@_); + return Games::PangZero::Palette::HsiToRgb($player->{hue}, $player->{saturation}, $i); } + ); + AlterPalette( $harpoonSurface, sub { 1; }, + sub { + shift @_; + my ($h, $s, $i) = Games::PangZero::Palette::RgbToHsi(@_); + return Games::PangZero::Palette::HsiToRgb($player->{hue}, $player->{saturation} * $s / 256, $i); } + ); + $player->{guySurface} = $guySurface; + $player->{whiteGuySurface} = $whiteGuySurface; + $player->{harpoonSurface} = $harpoonSurface; +} + +sub MakeGuySurfaces { + foreach my $player (@Games::PangZero::Players) { + MakeGuySurface($player); + } + + $Games::PangZero::WhiteHarpoonSurface = SDL::Image::load("$Games::PangZero::DataDir/harpoon.png"); + AlterPalette($Games::PangZero::WhiteHarpoonSurface, sub {1;}, sub { return (255, 255, 255); } ); +} + +sub AlterPalette { + my ($surface, $filterSub, $alterSub) = @_; + my ($r, $g, $b); + my ($palette, $numColors, $n, $color); + + $palette = $surface->format->palette(); + $numColors = ($surface->format->BytesPerPixel == 1) ? $palette->ncolors() : -1; + for ($n = 0; $n < $numColors; $n++) { + $color = $palette->color_index($n); + ($r, $g, $b) = ( $color->r, $color->g, $color->b ); + + next unless $filterSub->($n, $r, $g, $b); + ($r, $g, $b) = $alterSub->($n, $r, $g, $b); + $r = $g = $b = 4 if ($r == 0 and $g == 0 and $b == 0); + + $color->r($r); + $color->g($g); + $color->b($b); + SDL::Video::set_colors($surface, $n, $color); + } + $surface = SDL::Video::display_format($surface); +} + +sub RenderBorder { + my ($borderSurface, $targetSurface) = @_; + my ($dstrect, $srcrect1, $srcrect2, $xpos, $ypos, $width, $height); + + $width = $Games::PangZero::ScreenWidth + 2 * $Games::PangZero::ScreenMargin; + $height = $Games::PangZero::ScreenHeight + 2 * $Games::PangZero::ScreenMargin; + + # Draw the corners + $dstrect = SDL::Rect->new(0, 0, 16, 16); + $srcrect1 = SDL::Rect->new(0, 0, 16, 16); + SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect); + $dstrect->x($width - 16); $srcrect1->x(144); + SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect); + $dstrect->y($height - 16); $srcrect1->y(144); + SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect); + $dstrect->x(0); $srcrect1->x(0); + SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect); + + if(SDL::Config->has('SDL_gfx_rotozoom')) { + # Top border + my $zoom = SDL::Surface->new(SDL_SWSURFACE(), 128, 16, 32); + $srcrect1->x(16); $srcrect1->y(0); $srcrect1->w(128); $srcrect1->h(16); + SDL::Video::blit_surface($borderSurface, $srcrect1, $zoom, SDL::Rect->new(0, 0, $srcrect1->w, $srcrect1->h) ); + $zoom = SDL::GFX::Rotozoom::zoom_surface($zoom, $Games::PangZero::ScreenWidth / 128, 1, SDL::GFX::Rotozoom::SMOOTHING_OFF()); + $dstrect->x(16); $dstrect->y(0); + SDL::Video::blit_surface($zoom, SDL::Rect->new(0, 0, $zoom->w, $zoom->h), $targetSurface, $dstrect ); + + # Left border + $zoom = SDL::Surface->new(SDL_SWSURFACE(), 16, 128, 32); + $srcrect1->x(0); $srcrect1->y(16); $srcrect1->h(128); $srcrect1->w(16); + SDL::Video::blit_surface($borderSurface, $srcrect1, $zoom, SDL::Rect->new(0, 0, $srcrect1->w, $srcrect1->h) ); + $zoom = SDL::GFX::Rotozoom::zoom_surface($zoom, 1, $Games::PangZero::ScreenHeight / 128, SDL::GFX::Rotozoom::SMOOTHING_OFF()); + $dstrect->x(0); $dstrect->y(16); + SDL::Video::blit_surface($zoom, SDL::Rect->new(0, 0, $zoom->w, $zoom->h), $targetSurface, $dstrect ); + } + + # Draw top and bottom border + + $srcrect1->w(128); $srcrect1->x(16); $srcrect1->y(0); + $srcrect2 = SDL::Rect->new( 16, 144, 128, 16 ); + for ($xpos = 16; $xpos < $width-16; ) { + $dstrect->x($xpos); + $dstrect->y(0); + SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect); + $dstrect->y($height - 16); + SDL::Video::blit_surface($borderSurface, $srcrect2, $targetSurface, $dstrect); + $xpos += $srcrect1->w(); + $srcrect1->w(16); $srcrect1->x(128); + $srcrect2->w(16); $srcrect2->x(128); + } + + # Draw left and right border + + $srcrect1->h(128); $srcrect1->y(16); $srcrect1->x(0); + $srcrect2->h(128); $srcrect2->y(16); $srcrect2->x(144); + for ($ypos = 16; $ypos < $height-16; ) { + $dstrect->x(0); + $dstrect->y($ypos); + SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect); + $dstrect->x($width - 16); + SDL::Video::blit_surface($borderSurface, $srcrect2, $targetSurface, $dstrect); + $ypos += $srcrect1->h(); + $srcrect1->h(16); $srcrect1->y(128); + $srcrect2->h(16); $srcrect2->y(128); + } + + if(SDL::Config->has('SDL_gfx_rotozoom')) { + # Top border + my $zoom = SDL::Surface->new(SDL::Video::SDL_SWSURFACE(), 128, 16, 32); + $srcrect1->x(16); $srcrect1->y(0); $srcrect1->w(128); $srcrect1->h(16); + SDL::Video::blit_surface($borderSurface, $srcrect1, $zoom, SDL::Rect->new(0, 0, $srcrect1->w, $srcrect1->h) ); + $zoom = SDL::GFX::Rotozoom::zoom_surface($zoom, $Games::PangZero::ScreenWidth / 128, 1, SDL::GFX::Rotozoom::SMOOTHING_OFF()); + $dstrect->x(16); $dstrect->y(0); + SDL::Video::blit_surface($zoom, SDL::Rect->new(0, 0, $zoom->w, $zoom->h), $targetSurface, $dstrect ); + + # Left border + $zoom = SDL::Surface->new( SDL_SWSURFACE(), 16, 128, 32); + $srcrect1->x(0); $srcrect1->y(16); $srcrect1->h(128); $srcrect1->w(16); + SDL::Video::blit_surface($borderSurface, $srcrect1, $zoom, SDL::Rect->new(0, 0, $srcrect1->w, $srcrect1->h) ); + $zoom = SDL::GFX::Rotozoom::zoom_surface($zoom, 1, $Games::PangZero::ScreenHeight / 128, SDL::GFX::Rotozoom::SMOOTHING_OFF()); + $dstrect->x(0); $dstrect->y(16); + SDL::Video::blit_surface($zoom, SDL::Rect->new(0, 0, $zoom->w, $zoom->h), $targetSurface, $dstrect ); + } +} + +sub LoadBackground { + my $filename = shift; + + SDL::Video::fill_rect($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::PhysicalScreenWidth, $Games::PangZero::PhysicalScreenHeight), SDL::Video::map_RGB($Games::PangZero::Background->format(), 0, 0, 0)); + my $backgroundImage = SDL::Image::load("$Games::PangZero::DataDir/$filename"); + my $dstrect = SDL::Rect->new($Games::PangZero::ScreenMargin, $Games::PangZero::ScreenMargin, 0, 0); + my $srcrect = SDL::Rect->new(0, 0, $Games::PangZero::ScreenWidth, $Games::PangZero::ScreenHeight); + if ($Games::PangZero::ScreenWidth != $backgroundImage->w() or $Games::PangZero::ScreenHeight != $backgroundImage->h()) { + if (SDL::Config->has('SDL_gfx_rotozoom')) { + my $zoomX = $Games::PangZero::ScreenWidth / $backgroundImage->w(); # $zoomX = 1.0 if $zoomX < 1.0; + my $zoomY = $Games::PangZero::ScreenHeight / $backgroundImage->h(); # $zoomY = 1.0 if $zoomY < 1.0; + $backgroundImage = SDL::GFX::Rotozoom::zoom_surface($backgroundImage, $zoomX, $zoomY, SDL::GFX::Rotozoom::SMOOTHING_OFF()); + } + } + SDL::Video::blit_surface($backgroundImage, $srcrect, $Games::PangZero::Background, $dstrect); + + RenderBorder($Games::PangZero::BorderSurface, $Games::PangZero::Background); +} + +sub TextWidth { + SDLx::SFont::SDL_TEXTWIDTH(@_); # perl-sdl-2.x +} + +sub FindVideoMode { + if ($Games::PangZero::FullScreen < 2) { + return (800, 600); + } + + # Find a suitable widescreen mode + # One native resolution: 1680 x 1050 => 1.6 : 1 + # Which could translate to: 840 x 525 => 1.6 : 1 + # Some adapters have: 848 x 480 => 1.76 : 1 + # 720 x 480 => 1.5 : 1 + # 800 x 512 => 1.56 : 1 + # Conclusion: Any resolution where w in [800,900], h > 480 and r in [1.5, 1.8] is good + + my ($modes, $mode, @goodModes, $w, $h, $ratio); + $modes = SDL::Video::list_modes( 0, SDL_HWSURFACE ); #add back fullscreen + foreach $mode (@{$modes}) { + $w = $mode->w; + $h = $mode->h; + $ratio = $w / $h; + warn sprintf( "%4d x %4d => %0.3f\n", $w, $h, $ratio ); + next if $w < 800 or $w > 900; + next if $h < 480; + next if $ratio < 1.5 or $ratio > 1.8; + push @goodModes, ( { -w => $w, -h => $h, -score => abs($ratio - 1.6) * 1000 + abs($w - 800) } ); + } + @goodModes = sort { $a->{-score} <=> $b->{-score} } @goodModes; + return (800, 600) unless @goodModes; + foreach $mode (@goodModes) { + print sprintf( '%d x %d => %0.3f (score %d)', $mode->{-w}, $mode->{-h}, $mode->{-w} / $mode->{-h}, $mode->{-score} ), "\n"; + } + return ($goodModes[0]->{-w}, $goodModes[0]->{-h}); +} + +1; diff --git a/lib/Games/PangZero/Guy.pm b/lib/Games/PangZero/Guy.pm new file mode 100644 index 0000000..a747947 --- /dev/null +++ b/lib/Games/PangZero/Guy.pm @@ -0,0 +1,233 @@ +########################################################################## +package Games::PangZero::Guy; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); +use vars qw(%Guys $GuyId); + +sub new { + my ($class, $player) = @_; + my $self = Games::PangZero::GameObject->new(); + my $number = $player->{number}; + %{$self} = ( %{$self}, + 'player' => $player, + 'number' => $number, + 'x' => $player->{startX}, + 'y' => $Games::PangZero::ScreenHeight - 64, + 'w' => 64, + 'h' => 64, + 'collisionw' => '28', + 'collisionh' => '48', + 'delay' => 0, + 'speedY' => 0, + 'speedX' => 0, + 'dir' => $number % 2, + 'state' => 'idle', + 'killed' => 0, + 'harpoons' => 0, + 'invincible' => 0, + 'surface' => $player->{guySurface}, + 'whiteSurface' => $player->{whiteGuySurface}, + 'weapon' => 'Harpoon', + 'bonusDelay' => 0, + 'id' => ++$GuyId, + ); + bless $self, $class; + $self->SetupCollisions(); + $self->CalculateAnimPhases(); + $Guys{$self->{id}} = $self; + return $self; +} + +sub Delete { + my $self = shift; + + $self->SUPER::Delete; + delete $Guys{$self->{id}}; +} + +sub CalculateAnimPhases { + my $self = shift; + + $self->{animPhases} = $self->{player}->{guySurface}->w / 128, +} + +sub DemoMode { + my ($self) = shift; + $self->{state} = 'demo'; + $self->{dir} = 1; +} + +sub Fire { + my ($self) = @_; + + if ($self->{harpoons} < $Games::PangZero::DifficultyLevel->{harpoons}) { + ++$self->{harpoons}; + eval("unshift \@Games::PangZero::GameObjects, (Games::PangZero::$self->{weapon}::Create(\$self));"); + $self->{state} = 'shoot'; + $self->{delay} = 7; + Games::PangZero::Music::PlaySound('shoot'); + return 1; + } + return 0; +} + +sub AdvanceWhileFlying { + my $self = shift; + + $self->{speedY} += $Games::PangZero::Ball::Gravity * 2; + $self->{y} += $self->{speedY}; + $self->{x} += $self->{dir} > 0 ? 1 : -1; + if ($self->{x} < -16) { + $self->{x} = 0; + $self->{dir} = 1; + } + if ($self->{x} > $Games::PangZero::ScreenWidth - $self->{w} + 16) { + $self->{x} = $Games::PangZero::ScreenWidth - $self->{w}; $self->{dir} = 0; + } + if ($self->{y} >= $Games::PangZero::ScreenHeight - $self->{h}) { + $self->{state} = 'idle'; + $self->{y} = $Games::PangZero::ScreenHeight - $self->{h}; + $self->{speedX} = $self->{dir} ? 1 : -1; + } +} + +sub Advance { + my ($self) = @_; + my ($slippery, $keys); + + $slippery = $Games::PangZero::Slippery ? 0.0625 : 0; + + return if $self->{killed}; + return if $self->{state} eq 'demo'; + --$self->{invincible}; + + if ($self->{bonusDelay} > 0) { + --$self->{bonusDelay}; + $self->{weapon} = 'Harpoon' if $self->{bonusDelay} <= 0; + } + + if ($self->{state} eq 'fly') { + $self->AdvanceWhileFlying(); + return; + } + + if ($self->{delay} > 0) { + --$self->{delay}; + $keys = [ 0, 0, 0 ]; + } else { + $keys = $self->{player}->{keys}; + } + + $self->{speedX} = 0 unless $slippery; + $self->{state} = 'idle'; + + if ( $Games::PangZero::Events{$keys->[2]} ) { + return if $self->Fire(); + } + if ( $Games::PangZero::Keys{$keys->[0]} ) { + if ($slippery) { + $self->{speedX} -= $slippery * 2 if $self->{speedX} > -3; + } else { + $self->{speedX} = -3; + } + $self->{dir} = 0; + $self->{state} = 'walk'; + } elsif ( $Games::PangZero::Keys{$keys->[1]} ) { + if ($slippery) { + $self->{speedX} += $slippery * 2 if $self->{speedX} < 3; + } else { + $self->{speedX} = 3; + } + $self->{dir} = 1; + $self->{state} = 'walk'; + } else { + if ($slippery) { + $self->{speedX} += $slippery if $self->{speedX} < 0; + $self->{speedX} -= $slippery if $self->{speedX} > 0; + } + } + $self->{x} += $self->{speedX}; + + if ($self->{x} < -16) { + $self->{x} = -16; $self->{speedX} = 0; + } + if ($self->{x} > $Games::PangZero::ScreenWidth - $self->{w} + 16) { + $self->{x} = $Games::PangZero::ScreenWidth - $self->{w} + 16; $self->{speedX} = 0; + } +} + +sub Draw { + my ($self) = @_; + my ($surface, $srcrect, $srcx, $srcy, $srcw, $srch); + + return if ($self->{killed}); + $surface = $self->{surface}; + $surface = $self->{whiteSurface} if $self->{invincible} > 0 and (int($self->{invincible} / 2) % 3 == 0); + + $srcw = $srch = 64; + if ($self->{state} eq 'idle') { + $srcx = $self->{dir} * 128; + $srcy = 64; + } elsif ($self->{state} eq 'walk') { + $srcx = $self->{dir} * $self->{animPhases} * 64 + (int($self->{x} / 50) % $self->{animPhases}) * 64; + $srcy = 0; + } elsif ($self->{state} eq 'demo') { + $srcx = $self->{dir} * $self->{animPhases} * 64 + (int($Games::PangZero::Game->{anim} / 16) % $self->{animPhases}) * 64; + $srcy = 0; + } elsif ($self->{state} eq 'shoot') { + $srcx = $self->{dir} * 128 + 64; + $srcx -= 64 if ($self->{delay} <= 1); + $srcy = 64; + } elsif ($self->{state} eq 'fly') { + $srcx = ($self->{dir} > 0 ? 0 : 64); + $srcy = 128; + } + $srcrect = SDL::Rect->new($srcx, $srcy, $srcw, $srch ); + $self->TransferRect(); + SDL::Video::blit_surface($surface, $srcrect, $Games::PangZero::App, $self->{rect}); +} + +sub Kill { + my ($self) = @_; + + return if $Games::PangZero::Cheat; + return if $self->{invincible} > 0; + $self->{justkilled} = 1; + $Games::PangZero::GameEvents{'kill'} = 1; + print "player killed\n" if $ENV{PANGZERO_TEST}; +} + +sub Earthquake { + my ($self, $amplitude) = @_; + + return if $self->{state} eq 'fly'; + $self->{speedY} = -($amplitude->[0]); + $self->{dir} = $amplitude->[1] > $self->{x} ? 0 : 1; + $self->{state} = 'fly'; + $self->{y} -= 3; +} + +sub DeleteHarpoons { + my ($self) = @_; + my (@gameObjects, $harpoon); + + @gameObjects = @Games::PangZero::GameObjects; + foreach $harpoon (@gameObjects) { + $harpoon->Delete if ($harpoon->{guy} and $harpoon->{guy} eq $self); + } +} + +sub GiveScore { + my ($self, $score) = @_; + + my $player = $self->{player}; + $player->{score} += $score; + if ($player->{score} >= $player->{scoreforbonuslife}) { + ++$player->{lives}; + $player->{scoreforbonuslife} += 200000; + Games::PangZero::Music::PlaySound('bonuslife'); + } +} + +1; diff --git a/lib/Games/PangZero/HalfCutter.pm b/lib/Games/PangZero/HalfCutter.pm new file mode 100644 index 0000000..0828627 --- /dev/null +++ b/lib/Games/PangZero/HalfCutter.pm @@ -0,0 +1,28 @@ +########################################################################## +package Games::PangZero::HalfCutter; +########################################################################## + +@ISA = qw(Games::PangZero::Harpoon); +use strict; +use warnings; + +sub Create { + return Games::PangZero::HalfCutter->new(@_); +} + +sub new { + my $class = shift; + my $self = Games::PangZero::Harpoon->new(@_); + $self->{popEffect} = 'HalfCutter'; + $self->{originalSurface} = $self->{surface}; + bless $self, $class; +} + +sub Advance { + my $self = shift; + + $self->{surface} = (($Games::PangZero::Game->{anim} % 15) < 3) ? $Games::PangZero::WhiteHarpoonSurface : $self->{originalSurface}; + $self->SUPER::Advance(); +} + +1; diff --git a/lib/Games/PangZero/Harpoon.pm b/lib/Games/PangZero/Harpoon.pm new file mode 100644 index 0000000..fd388c9 --- /dev/null +++ b/lib/Games/PangZero/Harpoon.pm @@ -0,0 +1,87 @@ +########################################################################## +package Games::PangZero::Harpoon; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); +use vars qw(%Harpoons $HarpoonId); + +sub Create { + return Games::PangZero::Harpoon->new(@_); +} + +sub new { + my ($class, $guy) = @_; + my ($self); + + $self = Games::PangZero::GameObject->new(); + %{$self} = ( %{$self}, + 'x' => $guy->{x} + 22, + 'y' => $Games::PangZero::ScreenHeight - 32, + 'w' => 18, + 'h' => 32, + 'speedY' => -3, + 'speedX' => 0, + 'guy' => $guy, + 'surface' => $guy->{player}->{harpoonSurface}, + 'popEffect' => '', + 'id' => ++$HarpoonId, + ); + $Harpoons{$self->{id}} = $self; + bless $self, $class; +} + +sub Delete { + my $self = shift; + + delete $Harpoons{$self->{id}}; + --$self->{guy}->{harpoons}; + $self->SUPER::Delete(); +} + +sub Advance { + my $self = shift; + + if ($self->{y} < 0) { + $self->Delete(); + return; + } + $self->{y} += $self->{speedY}; + $self->{h} = $Games::PangZero::ScreenHeight - $self->{y}; +} + +sub GetAnimPhase { + my $self = shift; + + return (int($Games::PangZero::Game->{anim} / 4) % 3) + 1; +} + +sub Draw { + my $self = shift; + my ($x, $y, $h, $maxh, $dstrect, $srcrect); + + $self->TransferRect(); + $y = $self->{y}; + $dstrect = SDL::Rect->new( $self->{x} + $Games::PangZero::ScreenMargin, 0, $self->{w}, 0 ); + $srcrect = SDL::Rect->new( (0, 64, 32, 96)[ $self->GetAnimPhase() ], 0, $self->{w}, 0 ); + $maxh = 160; + + # The harpoon needs to be drawn from tile pieces. + # $y iterates from $self->{y} to $Games::PangZero::ScreenHeight + # We draw at most $maxh height tiles at a time. + + while ($y < $Games::PangZero::ScreenHeight) { + $h = $Games::PangZero::ScreenHeight - $y; + $h = $maxh if $h > $maxh; + $dstrect->y( $y + $Games::PangZero::ScreenMargin ); + $dstrect->h( $h ); + $srcrect->h( $h ); + SDL::Video::blit_surface($self->{surface}, $srcrect, $Games::PangZero::App, $dstrect ); + + # Prepare for next piece + $y += $h; + $srcrect->y( 32 ); # First piece starts at 0, rest start at 32 + $maxh = 128; + } +} + +1; diff --git a/lib/Games/PangZero/Hexa.pm b/lib/Games/PangZero/Hexa.pm new file mode 100644 index 0000000..3b84ae5 --- /dev/null +++ b/lib/Games/PangZero/Hexa.pm @@ -0,0 +1,43 @@ +########################################################################## +package Games::PangZero::Hexa; +########################################################################## + +@ISA = qw(Games::PangZero::Ball); + +sub new { + my $class = shift; + my $self = Games::PangZero::Ball->new(@_); + $self->{speedX} = ($Games::PangZero::Game->Rand(1.25) + 1.25) * ($self->{speedX} > 0 ? 1 : -1); + $self->{speedY} = -4 + abs($self->{speedX}); + + bless $self, $class; +} + +sub Draw { + my $self = shift; + my ($rect, $srcx, $phase); + + return if $Games::PangZero::GamePause > 0 and $Games::PangZero::GamePause < 100 and (int($Games::PangZero::GamePause / 3) % 4) < 2; + + $self->TransferRect(); + if ($self->{ismagic} and int($Games::PangZero::Game->{anim} / 3) % 3 == 0) { + SDL::Video::blit_surface($self->{surface}, $self->{desc}->{magicrect}, $Games::PangZero::App, $self->{rect}); + } else { + $rect = $self->{desc}->{rect}; + $phase = int($Games::PangZero::Game->{anim} / 5) % 3; + $phase = 2 - $phase if $self->{speedX} < 0; + $srcx = $phase * $self->{w}; + $rect->x( $rect->x + $srcx ); + SDL::Video::blit_surface($self->{surface}, $rect, $Games::PangZero::App, $self->{rect} ); + $rect->x( $rect->x - $srcx ); + } +} + +sub AdjustChildren { + my ($self, $child1, $child2) = @_; + if ($self->{hasmagic}) { + $child2->GiveMagic(); + } +} + +1; diff --git a/lib/Games/PangZero/Highscore.pm b/lib/Games/PangZero/Highscore.pm new file mode 100644 index 0000000..d911391 --- /dev/null +++ b/lib/Games/PangZero/Highscore.pm @@ -0,0 +1,125 @@ +########################################################################## +# HIGH SCORE TABLE +########################################################################## +package Games::PangZero::Highscore; + +use vars qw( @Games::PangZero::UnsavedHighScores ); + +foreach (@Games::PangZero::DifficultyLevels) { + $_->{highScoreTablePan} = [ ['UPI', 250000], ['UPI', 200000], ['UPI', 150000], ['UPI', 100000], ['UPI', 50000] ]; + $_->{highScoreTablePan} = [ ['UPI', 2500], ['UPI', 2000], ['UPI', 1500], ['UPI', 1000], ['UPI', 500] ] if $_->{name} eq 'Miki'; + $_->{highLevelTablePan} = [ ['UPI', 50], ['UPI', 40], ['UPI', 30], ['UPI', 20], ['UPI', 10] ]; + $_->{highLevelTablePan} = [ ['UPI', 20], ['UPI', 16], ['UPI', 12], ['UPI', 8], ['UPI', 4] ] if $_->{name} eq 'Miki'; + $_->{highScoreTableCha} = [ ['UPI', 250000], ['UPI', 200000], ['UPI', 150000], ['UPI', 100000], ['UPI', 50000] ]; + $_->{highLevelTableCha} = [ ['UPI', 30], ['UPI', 25], ['UPI', 20], ['UPI', 15], ['UPI', 10] ]; +} + +sub AddHighScore { + my ($player, $score, $level) = @_; + + unshift @Games::PangZero::UnsavedHighScores, [$player, $score, $level]; +} + +sub MergeUnsavedHighScores { + my ($table) = @_; + my ($unsavedHighScore, $player, $score, $level); + + die unless ($table =~ /^(Cha|Pan)$/); + foreach $unsavedHighScore (@Games::PangZero::UnsavedHighScores) { + ($player, $score, $level) = @{$unsavedHighScore}; + &MergeUnsavedHighScore( $Games::PangZero::DifficultyLevel->{"highScoreTable$table"}, $player, $score ); + &MergeUnsavedHighScore( $Games::PangZero::DifficultyLevel->{"highLevelTable$table"}, $player, $level ); + } + + splice @{$Games::PangZero::DifficultyLevel->{"highScoreTable$table"}}, 5; + splice @{$Games::PangZero::DifficultyLevel->{"highLevelTable$table"}}, 5; + @Games::PangZero::UnsavedHighScores = (); + my $newHighScore = &InputPlayerNames($table); + if ($newHighScore) { + $Games::PangZero::Game->RunHighScore( $Games::PangZero::DifficultyLevelIndex, $table, 0 ); + } +} + +sub MergeUnsavedHighScore { + my ($highScoreList, $player, $score) = @_; + my ($i); + + for ($i = 0; $i < scalar @{$highScoreList}; ++$i) { + if ($highScoreList->[$i]->[1] < $score) { + splice @{$highScoreList}, $i, 0, [$player, $score]; + return; + } + } +} + +sub InputPlayerNames { + my ($table) = @_; + my ($highScoreEntry, $player, $score, $message, $retval); + + die unless ($table =~ /^(Cha|Pan)$/); + $retval = 0; + foreach $highScoreEntry (@{$Games::PangZero::DifficultyLevel->{"highScoreTable$table"}}, @{$Games::PangZero::DifficultyLevel->{"highLevelTable$table"}}) { + $player = $highScoreEntry->[0]; + next unless ref $player; + unless ($player->{highScoreName}) { + $score = $highScoreEntry->[1]; + $message = $score < 1000 ? "Level $score" : "Score $score"; + $player->{highScoreName} = &InputPlayerName($player, $message); + } + $highScoreEntry->[0] = $player->{highScoreName}; + $retval = 1; + } + foreach $player (@Games::PangZero::Players) { + delete $player->{highScoreName}; + } + return $retval; +} + +sub InputPlayerName { + my ($player, $message) = @_; + my ($nameMenuItem, @menuItems, $x, $y, $yInc); + + SDL::Events::enable_unicode(1); + $Games::PangZero::UnicodeMode = 1; + my $name = ($player->{name} or '') . '|'; + my $guy = Games::PangZero::Guy->new($player); + ($guy->{x}, $guy->{y}) = (150, 150); + $guy->DemoMode(); + + ($x, $y, $yInc) = (230, 80, 45); + push @menuItems, ( + Games::PangZero::MenuItem->new( $x, $y += $yInc, "HIGH SCORE!!!"), + Games::PangZero::MenuItem->new( $x, $y += $yInc, $message), + Games::PangZero::MenuItem->new( $x, $y += $yInc, "Please enter your name:"), + $nameMenuItem = Games::PangZero::MenuItem->new( $x, $y += $yInc, $name ), + ); + push @Games::PangZero::GameObjects, ($guy, @menuItems); + + while (1) { + $Games::PangZero::LastUnicodeKey = 0; + $Games::PangZero::Game->MenuAdvance(); + last if $Games::PangZero::Game->{abortgame}; + if (%Games::PangZero::Events) { + if ($Games::PangZero::MenuEvents{BACKSP}) { + substr($name, -2, 1, ''); # Remove next to last char + $nameMenuItem->SetText($name); + } elsif ($Games::PangZero::MenuEvents{BUTTON}) { + last; + } elsif ($Games::PangZero::LastUnicodeKey < 127 and $Games::PangZero::LastUnicodeKey >= 32 and length($name) < 9) { + substr($name, -1, 0, chr($Games::PangZero::LastUnicodeKey)); # Insert before last char + $nameMenuItem->SetText($name); + } + } + } + $name =~ s/\|$//; + $player->{name} = $name; + $name = "Anonymous" if $name =~ /^\s*$/; + $guy->Delete(); + foreach (@menuItems) { + $_->Delete(); + } + SDL::Events::enable_unicode(0); $Games::PangZero::UnicodeMode = 0; + return $name; +} + +1; diff --git a/lib/Games/PangZero/Joystick.pm b/lib/Games/PangZero/Joystick.pm new file mode 100644 index 0000000..5d50e7e --- /dev/null +++ b/lib/Games/PangZero/Joystick.pm @@ -0,0 +1,74 @@ +########################################################################## +package Games::PangZero::Joystick; +########################################################################## + +use vars qw(@Games::PangZero::Joysticks @Games::PangZero::JoystickButtons); + +sub InitJoystick { + my ($numJoysticks, $joystick, $numButtons, $i); + + $numJoysticks = SDL::Joystick::num_joysticks(); + for ($i = 0; $i < $numJoysticks; $i++) { + print STDERR "Found joystick " , $i+1 , ": " , SDL::Joystick::name($i), "\n"; + $joystick = SDL::Joystick->new($i); + next unless $joystick; + $numButtons = SDL::Joystick::num_buttons($joystick); + next unless $numButtons; + push @Games::PangZero::Joysticks, $joystick; + push @Games::PangZero::JoystickButtons, $numButtons; + print STDERR "Joystick opened, $numButtons buttons.\n"; + } +} + +sub ReadJoystick { + my ($readBothAxes) = @_; + my ($i, $button, $buttonPressed); + + $i = 0; + foreach my $joystick (@Games::PangZero::Joysticks) { + my $axis = SDL::Joystick::get_axis($joystick, 0); + if ($axis <= -10000) { + $Games::PangZero::Events{"L$i"} = $Games::PangZero::MenuEvents{LEFT} = 1 unless $Games::PangZero::Keys{"L$i"}; + $Games::PangZero::Keys{"L$i"} = 1; + $Games::PangZero::Keys{"R$i"} = 0; + } elsif ($axis >= 10000) { + $Games::PangZero::Events{"R$i"} = $Games::PangZero::MenuEvents{RIGHT} = 1 unless $Games::PangZero::Keys{"R$i"}; + $Games::PangZero::Keys{"R$i"} = 1; + $Games::PangZero::Keys{"L$i"} = 0; + } else { + $Games::PangZero::Keys{"L$i"} = 0; + $Games::PangZero::Keys{"R$i"} = 0; + } + + if ($readBothAxes) { + $axis = SDL::Joystick::get_axis($joystick, 1); + if ($axis <= -10000) { + $Games::PangZero::Events{"U$i"} = $Games::PangZero::MenuEvents{UP} = 1 unless $Games::PangZero::Keys{"U$i"}; + $Games::PangZero::Keys{"U$i"} = 1; + $Games::PangZero::Keys{"D$i"} = 0; + } elsif ($axis >= 10000) { + $Games::PangZero::Events{"D$i"} = $Games::PangZero::MenuEvents{DOWN} = 1 unless $Games::PangZero::Keys{"D$i"}; + $Games::PangZero::Keys{"D$i"} = 1; + $Games::PangZero::Keys{"U$i"} = 0; + } else { + $Games::PangZero::Keys{"D$i"} = 0; + $Games::PangZero::Keys{"U$i"} = 0; + } + } + + $buttonPressed = 0; + for ($button = 0; $button < $Games::PangZero::JoystickButtons[$i]; $button++) { + if (SDL::Joystick::get_button($joystick, $button)) { + $buttonPressed = 1; + last; + } + } + if ($buttonPressed and not $Games::PangZero::Keys{"B$i"}) { + $Games::PangZero::Events{"B$i"} = $Games::PangZero::MenuEvents{BUTTON} = 1; + } + $Games::PangZero::Keys{"B$i"} = $buttonPressed; + $i++; + } +} + +1; diff --git a/lib/Games/PangZero/MachineGun.pm b/lib/Games/PangZero/MachineGun.pm new file mode 100644 index 0000000..a6c8e2e --- /dev/null +++ b/lib/Games/PangZero/MachineGun.pm @@ -0,0 +1,65 @@ +########################################################################## +package Games::PangZero::MachineGun; +########################################################################## + +@ISA = qw(Games::PangZero::Harpoon); +use strict; +use warnings; +use vars qw(@SrcRects); + +@SrcRects = ( + SDL::Rect->new( 0, 160, 32, 32 ), + SDL::Rect->new( 32, 160, 32, 32 ), + SDL::Rect->new( 64, 160, 32, 32 ), +); + +sub Create { + return ( Games::PangZero::MachineGun->new(@_, 0), Games::PangZero::MachineGun->new(@_, 1), Games::PangZero::MachineGun->new(@_, 2) ); +} + +sub new { + my ($class, $guy, $index) = @_; + my ($self); + + $self = Games::PangZero::Harpoon->new($guy); + %{$self} = ( %{$self}, + 'x' => $guy->{x} + 16, + 'y' => $guy->{y} - 16, + 'w' => 32, + 'h' => 32, + 'index' => $index, + 'speedY' => -9, + 'speedX' => (-2, 0, 2)[$index], + ); + bless $self, $class; +} + +sub Delete { + my $self = shift; + + --$self->{guy}->{harpoons} if $self->{index} == 1; + delete $Harpoon::Harpoons{$self->{id}}; + $self->Games::PangZero::GameObject::Delete(); +} + +sub Advance { + my $self = shift; + + if ($self->{y} < 0 + or $self->{x} < 0 + or $self->{x} > $Games::PangZero::ScreenWidth - $self->{w}) { + $self->Delete(); + return; + } + $self->{y} += $self->{speedY}; + $self->{x} += $self->{speedX}; +} + +sub Draw { + my $self = shift; + + $self->TransferRect(); + SDL::Video::blit_surface($self->{surface}, $SrcRects[$self->{index}], $Games::PangZero::App, $self->{rect}); +} + +1; diff --git a/lib/Games/PangZero/Meltdown.pm b/lib/Games/PangZero/Meltdown.pm new file mode 100644 index 0000000..45d7ff3 --- /dev/null +++ b/lib/Games/PangZero/Meltdown.pm @@ -0,0 +1,50 @@ +########################################################################## +package Games::PangZero::Meltdown; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); +use strict; +use warnings; + +sub new { + my ($class) = @_; + my ($self, $surface); + + $self = Games::PangZero::GameObject->new(); + $surface = SDL::Image::load( "$Games::PangZero::DataDir/meltdown.png" ); + %{$self} = ( %{$self}, + 'x' => ($Games::PangZero::ScreenWidth - $surface->w) / 2, + 'y' => -$surface->h, + 'w' => $surface->w, + 'h' => $surface->h, + 'speedY' => 0, + 'surface' => $surface, + 'bounce' => 0, + ); + bless $self, $class; +} + +sub Advance { + my $self = shift; + $self->{speedY} += 0.1; + $self->{y} += $self->{speedY}; + + if ($self->{bounce} == 0 and $self->{y} > $Games::PangZero::ScreenHeight - $self->{h}) { + $self->{bounce} = 1; + $self->{speedY} = -5; + $self->{y} = $Games::PangZero::ScreenHeight - $self->{h}; + } + + if ($self->{bounce} and $self->{y} > $Games::PangZero::PhysicalScreenHeight) { + $self->Delete; + } +} + +sub Draw { + my $self = shift; + + $self->TransferRect(); + SDL::Video::blit_surface($self->{surface}, SDL::Rect->new(0, 0, $self->{surface}->w, $self->{surface}->h), $Games::PangZero::App, $self->{rect} ); +} + +1; diff --git a/lib/Games/PangZero/Menu.pm b/lib/Games/PangZero/Menu.pm new file mode 100644 index 0000000..16c1a62 --- /dev/null +++ b/lib/Games/PangZero/Menu.pm @@ -0,0 +1,753 @@ +########################################################################## +package Games::PangZero::Menu; +########################################################################## + +use SDL::Events; +use Games::PangZero::FpsIndicator; +use Games::PangZero::MenuItem; + +@ISA = qw(Games::PangZero::GameBase); +use vars qw(@syms); +@syms = qw(UNKNOWN FIRST BACKSPACE TAB CLEAR RETURN PAUSE ESCAPE SPACE EXCLAIM QUOTEDBL HASH DOLLAR AMPERSAND QUOTE LEFTPAREN RIGHTPAREN ASTERISK PLUS COMMA MINUS PERIOD SLASH 0 1 2 3 4 5 6 7 8 9 COLON SEMICOLON LESS EQUALS GREATER QUESTION AT LEFTBRACKET BACKSLASH RIGHTBRACKET CARET UNDERSCORE BACKQUOTE a b c d e f g h i j k l m n o p q r s t u v w x y z DELETE WORLD_0 WORLD_1 WORLD_2 WORLD_3 WORLD_4 WORLD_5 WORLD_6 WORLD_7 WORLD_8 WORLD_9 WORLD_10 WORLD_11 WORLD_12 WORLD_13 WORLD_14 WORLD_15 WORLD_16 WORLD_17 WORLD_18 WORLD_19 WORLD_20 WORLD_21 WORLD_22 WORLD_23 WORLD_24 WORLD_25 WORLD_26 WORLD_27 WORLD_28 WORLD_29 WORLD_30 WORLD_31 WORLD_32 WORLD_33 WORLD_34 WORLD_35 WORLD_36 WORLD_37 WORLD_38 WORLD_39 WORLD_40 WORLD_41 WORLD_42 WORLD_43 WORLD_44 WORLD_45 WORLD_46 WORLD_47 WORLD_48 WORLD_49 WORLD_50 WORLD_51 WORLD_52 WORLD_53 WORLD_54 WORLD_55 WORLD_56 WORLD_57 WORLD_58 WORLD_59 WORLD_60 WORLD_61 WORLD_62 WORLD_63 WORLD_64 WORLD_65 WORLD_66 WORLD_67 WORLD_68 WORLD_69 WORLD_70 WORLD_71 WORLD_72 WORLD_73 WORLD_74 WORLD_75 WORLD_76 WORLD_77 WORLD_78 WORLD_79 WORLD_80 WORLD_81 WORLD_82 WORLD_83 WORLD_84 WORLD_85 WORLD_86 WORLD_87 WORLD_88 WORLD_89 WORLD_90 WORLD_91 WORLD_92 WORLD_93 WORLD_94 WORLD_95 KP0 KP1 KP2 KP3 KP4 KP5 KP6 KP7 KP8 KP9 KP_PERIOD KP_DIVIDE KP_MULTIPLY KP_MINUS KP_PLUS KP_ENTER KP_EQUALS UP DOWN RIGHT LEFT INSERT HOME END PAGEUP PAGEDOWN F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 NUMLOCK CAPSLOCK SCROLLOCK RSHIFT LSHIFT RCTRL LCTRL RALT LALT RMETA LMETA LSUPER RSUPER MODE COMPOSE HELP PRINT SYSREQ BREAK MENU POWER EURO UNDO LAST ); + +sub Exit { + my $self = shift; + + Games::PangZero::Config::SaveConfig(); + $self->SUPER::Exit(); +} + +sub SetGameSpeed { + $Games::PangZero::GameSpeed = 1.0; +} + +sub ShowTooltip { + my $self = shift; + my (@lines, $y, $yinc, $rect); + + @lines = @_; + @lines = ("Pang Zero $Games::PangZero::VERSION (C) 2006 by UPi (upi\@sourceforge.net)", + "Use cursor keys to navigate menu, Enter to select", + "P pauses the game, Esc quits") unless scalar @lines; + + $Games::PangZero::ScoreFont->use(); + ($y, $yinc) = ($Games::PangZero::ScreenHeight + 35, 20); + $rect = SDL::Rect->new(0, $y, $Games::PangZero::PhysicalScreenWidth, $Games::PangZero::PhysicalScreenHeight - $y ); + SDL::Video::fill_rect($Games::PangZero::Background, $rect, SDL::Video::map_RGB($Games::PangZero::Background->format(), 0, 0, 0)); + foreach (@lines) { + SDLx::SFont::print_text( $Games::PangZero::Background, 10, $y, $_ ) if $y + $yinc < $Games::PangZero::PhysicalScreenHeight; + + $y += $yinc; + } + $rect = SDL::Rect->new( 0, $Games::PangZero::ScreenHeight + 35, $Games::PangZero::PhysicalScreenWidth, $Games::PangZero::PhysicalScreenWidth - $y ); + SDL::Video::blit_surface($Games::PangZero::Background, $rect, $Games::PangZero::App, $rect); + $Games::PangZero::MenuFont->use(); +} + +sub MenuAdvance { + my $self = shift; + + my $advance = $self->CalculateAdvances(); + %Games::PangZero::Events = %Games::PangZero::MenuEvents = (); + %Games::PangZero::GameEvents = (); + Games::PangZero::HandleEvents('readbothaxes'); + while ($advance--) { + $self->AdvanceGameObjects(); + } + while (ref($Games::PangZero::GameObjects[$#Games::PangZero::GameObjects]) ne 'Games::PangZero::MenuItem') { + unshift @Games::PangZero::GameObjects, (pop @Games::PangZero::GameObjects); + } + $self->DrawGame(); +} + +sub SetCurrentItemIndex { + my ($self, $index) = @_; + + return if ($index < 0 or $index >= scalar @{$self->{menuItems}} or not $self->{menuItems}->[$index]->CanSelect()); + $self->{currentItemIndex} = $index; + $self->{currentItem} = $self->{menuItems}->[$index]; + $self->{currentItem}->Select(); +} + +sub EnterSubMenu { + my $self = shift; + my ($recall, $menuItem); + + $recall->{oldItems} = $self->{menuItems}; + $recall->{oldCurrentItemIndex} = $self->{currentItemIndex}; + foreach $menuItem (@{$self->{menuItems}}) { $menuItem->Hide(); } + $self->{menuItems} = []; + + return $recall; +} + +sub LeaveSubMenu { + my ($self, $recall) = @_; + my ($menuItem); + + foreach $menuItem (@{$self->{menuItems}}) { $menuItem->HideAndDelete(); } + $self->{menuItems} = $recall->{oldItems}; + foreach $menuItem (@{$self->{menuItems}}) { $menuItem->Show(); } + $self->SetCurrentItemIndex($recall->{oldCurrentItemIndex}); + $self->{abortgame} = 0; +} + +sub HandleUpDownKeys { + my $self = shift; + + if ($Games::PangZero::MenuEvents{DOWN}) { + $self->SetCurrentItemIndex( $self->{currentItemIndex} + 1 ); + } + if ($Games::PangZero::MenuEvents{UP}) { + $self->SetCurrentItemIndex( $self->{currentItemIndex} - 1 ); + } +} + +sub KeyToText { + my ($key) = @_; + eval("SDLK_$_ eq $key") and return ucfirst(lc($_)) foreach @syms; + print "No match for $key\n"; + return "???"; +} + +sub KeysToText { + my $keys = shift; + my ($retval); + if ( $keys->[0] =~ /^[LRB](\d)+$/ ) { + return "Joystick $1"; + } + return join(' / ', KeyToText($keys->[0]), KeyToText($keys->[1]), KeyToText($keys->[2]) ); +} + +sub RunTutorial { + my ($self, $ball) = @_; + my $recall = $self->EnterSubMenu(); + my @oldGameObjects = @Games::PangZero::GameObjects; + my %oldGuys = %Guy::Guys; + my %oldHarpoons = %Harpoon::Harpoons; + my $oldGame = $Games::PangZero::Game; + + $Games::PangZero::ScoreFont->use(); + $Games::PangZero::Game = Games::PangZero::TutorialGame->new; + $Games::PangZero::Game->SetChallenge($ball); + $Games::PangZero::Game->Run(); + $Games::PangZero::MenuFont->use(); + $self->SetGameSpeed(); + + @Games::PangZero::GameObjects = @oldGameObjects; + %Guy::Guys = %oldGuys; + %Harpoon::Harpoons = %oldHarpoons; + $Games::PangZero::Game = $oldGame; + $self->LeaveSubMenu($recall); +} + +sub RunTutorialMenu { + my $self = shift; + my ($baseX, $menuItem); + + my $recall = $self->EnterSubMenu(); + $self->{title}->Hide(); + my $baseY = 50; + + my @tutorials = ( + ['n2', 'Normal Ball', 'There is nothing special about this ball. Just keep shooting it.'], + ['b0', 'Bouncy Ball', 'This ball bounces higher than the normal ball.', 'Otherwise it behaves the same.'], + ['h0', 'Hexa', 'The Hexa is weightless and travels in a straight line.', 'With practice you can shoot it just as easily as the normal ball.'], + ['w1', 'Water Ball', 'The water ball pops each time it bounces.', 'This can create a tide of small balls fast.', 'Mop it up quickly.'], + ['f1', 'Fragile Ball', 'The fragile ball shatters into little bits the moment it is hit.', 'Prepare for a shower of small balls.'], + ['death', 'Death Ball', 'This ball cannot be killed with your harpoon.', 'Shooting will make it multiply. Too many death balls cause meltdown.', 'Evade it for 20 seconds to get rid of it.'], + ['seeker', 'Seeker Ball', 'The seeker ball will chase you forever.', 'You have to keep moving and shooting to evade it.'], + ['quake', 'Earthquake Ball', 'This ball is super heavy.', 'In fact the earth will quake each time it bounces.', 'Shoot it quickly, or it will send you flying.'], + ['u0', 'Upside Down Ball', 'This crazy ball bounces on the top of the screen.', 'Maybe it came from an alternate universe,', 'where gravity is negative?'], + ['super0, n1', 'Super Ball', 'The Super Ball is your friend. It will still kill you on touch.', 'The green super ball will pause the game for 8 seconds.', 'The gold super ball will kill every ball.'], + ); + + push @{$self->{menuItems}}, + Games::PangZero::MenuItem->new( 50, $baseY, "Back to main menu"); +# Games::PangZero::MenuItem->new( 50, $baseY += 40, "Run Demo" ); + + $baseY = 110; + $baseX = 50; + foreach (@tutorials) { + my @tutItem = @{$_}; + my $challenge = shift @tutItem; + my $menuItem = Games::PangZero::MenuItem->new( $baseX, $baseY += 40, @tutItem ); + $menuItem->{challenge} = $challenge; + push @{$self->{menuItems}}, $menuItem; + if ($baseY + 140 >= $Games::PangZero::ScreenHeight) { + $baseY = 110; + $baseX = 450; + } + } + push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); + $self->SetCurrentItemIndex(1); + + while (1) { + $self->MenuAdvance(); + last if $self->{abortgame}; + $self->HandleUpDownKeys(); + + if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} >= 6 and $self->{currentItemIndex} <= 10) { + $self->SetCurrentItemIndex($self->{currentItemIndex} - 5); + } + if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} >= 1 and $self->{currentItemIndex} <= 5) { + $self->SetCurrentItemIndex($self->{currentItemIndex} + 5); + } + if ($Games::PangZero::MenuEvents{BUTTON}) { + if (0 == $self->{currentItemIndex}) { + last; +# } elsif (1 == $self->{currentItemIndex}) { +# $self->{result} = 'demo'; +# last; + } else { + $self->RunTutorial($self->{currentItem}->{challenge}); + } + } + } + + $self->LeaveSubMenu($recall); + $self->{title}->Show(); +} + +sub RunCredits { + my ($self, $demo) = @_; + my ($i, $ball, @balls); + + my $time = $self->{anim}; + my $recall = $self->EnterSubMenu(); + my @oldGameObjects = @Games::PangZero::GameObjects; + foreach my $gameObject (@Games::PangZero::GameObjects) { + $gameObject->Clear(); + } + @Games::PangZero::GameObjects = ($self->{title}); + push @Games::PangZero::GameObjects, Games::PangZero::FpsIndicator->new(); + my ($y, $yinc) = (110, 36); + push @{$self->{menuItems}}, ( + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Written by: UPi "), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Music by: SAdam" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Graphics by: UPi, DaniGM, EBlanca" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc * 1.5, "TESTERS" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Ulmar, Surba, Miki, Aisha, Descant" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc * 1.5, "http://apocalypse.rulez.org/pangzero" ), + ); + foreach $i (@{$self->{menuItems}}) { $i->Center(); } + + for ($i = 0; $i < 20; ++$i) { + $ball = Games::PangZero::Ball::Spawn( $Games::PangZero::BallDesc{'credits1'}, 100, 1, 0 ); + $ball->{y} = $i * -5; + push @balls, ($ball); + $ball = Games::PangZero::Ball::Spawn( $Games::PangZero::BallDesc{'credits2'}, $Games::PangZero::ScreenWidth - 132, -1, 0 ); + $ball->{y} = $i * -5; + push @balls, ($ball); + } + push @Games::PangZero::GameObjects, @balls; + push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); + + while (1) { + $self->MenuAdvance(); + last if $self->{abortgame}; + if ($demo) { + last if %Games::PangZero::Events; + last if $self->{anim} - $time > 20 * 100; # 30s + } + } + + @Games::PangZero::GameObjects = @oldGameObjects; + foreach (@balls) { $_->Delete(); } + $self->LeaveSubMenu($recall); +} + +sub RunHighScore { + my ($self, $difficultyLevel, $table, $auto) = @_; + my ($time, $recall, $y, $yinc, $retval); + + die unless $table =~ /^(Cha|Pan)$/; + $time = 0; + $recall = $self->EnterSubMenu(); + ($y, $yinc) = (110, 40); + $difficultyLevel = $Games::PangZero::DifficultyLevels[$difficultyLevel]; + push @{$self->{menuItems}}, ( + Games::PangZero::MenuItem->new( 320, 50, ($table eq 'Cha' ? 'Challenge Game - ' : 'Panic Game - ') . $difficultyLevel->{name} ), #. " difficulty" ), + Games::PangZero::MenuItem->new( 50, $y, "Highest Score" ), + Games::PangZero::MenuItem->new( 480, $y, "Highest Level" ), + ); + $self->{menuItems}->[0]->Center(); + $y += $yinc; + foreach (@{$difficultyLevel->{"highScoreTable$table"}}) { + push @{$self->{menuItems}}, ( Games::PangZero::MenuItem->new( 10, $y += $yinc, $_->[0] ) ); + push @{$self->{menuItems}}, ( Games::PangZero::MenuItem->new( 250, $y, $_->[1] ) ); + } + $y = 110 + $yinc; + foreach (@{$difficultyLevel->{"highLevelTable$table"}}) { + push @{$self->{menuItems}}, ( Games::PangZero::MenuItem->new( 460, $y += $yinc, $_->[0] ) ); + push @{$self->{menuItems}}, ( Games::PangZero::MenuItem->new( 700, $y, $_->[1] ) ); + } + push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); + + while (not $retval) { + $self->MenuAdvance(); + if ($self->{abortgame}) { + $retval = 'abortgame'; last; + } + if ($auto) { + $retval = 'next' if ++$time > 100 * 6; + $retval = 'abortgame' if %Games::PangZero::Events; + } else { + if ($Games::PangZero::MenuEvents{LEFT} or $Games::PangZero::MenuEvents{UP}) { + $retval = 'prev'; last; + } elsif ($Games::PangZero::MenuEvents{RIGHT} or $Games::PangZero::MenuEvents{DOWN}) { + $retval = 'next'; last; + } elsif ($Games::PangZero::MenuEvents{BUTTON}) { + $retval = 'abortgame'; + } + } + } + $self->LeaveSubMenu($recall); + return $retval; +} + +sub RunHighScores { + my ($self, $auto) = @_; + my ($recall, $retval, $i, $table, @tables); + + if ($auto) { + $self->ShowTooltip(); + } else { + $self->ShowTooltip("Use arrow keys to navigate, Esc to go back"); + } + $recall = $self->EnterSubMenu(); + $self->{title}->Hide(); + $table = 0; + @tables = ( [0, 'Pan'], [0, 'Cha'], [1, 'Pan'], [1, 'Cha'], [2, 'Pan'], [2, 'Cha'], [3, 'Pan'], [3, 'Cha'], [4, 'Pan'] ); + + while (1) { + $retval = $self->RunHighScore( @{$tables[$table]}, $auto ); + if ($retval eq 'next') { + ++$table; + $table = 0 if $table == scalar @tables; + last if $table == 0 and $auto; + } elsif ($retval eq 'prev') { + --$table; + $table = $#tables if $table < 0; + } else { + last; + } + } + + $self->ShowTooltip(); + $self->{title}->Show(); + $self->LeaveSubMenu($recall); +} + +sub UpdateBallMixerMenu { + my $self = shift; + + $self->{menuItems}->[1]->SetParameter( $Games::PangZero::DeathBallsEnabled ? 'on' : 'off' ); + $self->{menuItems}->[2]->SetParameter( $Games::PangZero::EarthquakeBallsEnabled ? 'on' : 'off' ); + $self->{menuItems}->[3]->SetParameter( $Games::PangZero::WaterBallsEnabled ? 'on' : 'off' ); + $self->{menuItems}->[4]->SetParameter( $Games::PangZero::SeekerBallsEnabled ? 'on' : 'off' ); +} + +sub RunBallMixerMenu { + my $self = shift; + my ($recall); + + $recall = $self->EnterSubMenu(); + my ($y, $yinc) = (110, 40); + push @{$self->{menuItems}}, ( + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Back to options menu"), + Games::PangZero::MenuItem->new( 100, $y += $yinc + 20, "Death Balls: ", "Death balls multiply every time you shoot them.", "You can get rid of them by NOT shooting them for 20 seconds." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Earthquake Balls: ", "Earthquake balls shake the ground when they bounce.", "This sends you flying. Very dangerous." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Water Balls: ", "Water balls quickly dissolve, creating a flood of small balls." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Seeker Balls: ", "This ball picks a target, and chases him." ), + ); + $self->UpdateBallMixerMenu(); + push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); + $self->SetCurrentItemIndex(0); + + while (1) { + $self->MenuAdvance(); + last if $self->{abortgame}; + $self->HandleUpDownKeys(); + + if ($Games::PangZero::MenuEvents{BUTTON}) { + last if $self->{currentItemIndex} == 0; # Back to main + if ($self->{currentItemIndex} == 1) { + $Games::PangZero::DeathBallsEnabled = 1 - $Games::PangZero::DeathBallsEnabled; $self->UpdateBallMixerMenu(); + } elsif ($self->{currentItemIndex} == 2) { + $Games::PangZero::EarthquakeBallsEnabled = 1 - $Games::PangZero::EarthquakeBallsEnabled; $self->UpdateBallMixerMenu(); + } elsif ($self->{currentItemIndex} == 3) { + $Games::PangZero::WaterBallsEnabled = 1 - $Games::PangZero::WaterBallsEnabled; $self->UpdateBallMixerMenu(); + } elsif ($self->{currentItemIndex} == 4) { + $Games::PangZero::SeekerBallsEnabled = 1 - $Games::PangZero::SeekerBallsEnabled; $self->UpdateBallMixerMenu(); + } + } + } + + $self->LeaveSubMenu($recall); +} + +sub UpdateOptionsMenu { + my $self = shift; + + $self->{menuItems}->[1]->SetParameter( $Games::PangZero::Slippery ? 'on' : 'off' ); + $self->{menuItems}->[3]->SetParameter( $Games::PangZero::SoundEnabled ? 'on' : 'off'); + $self->{menuItems}->[4]->SetParameter( $Games::PangZero::MusicEnabled ? 'on' : 'off'); + $self->{menuItems}->[5]->SetText('< ' . ('Windowed', 'Fullscreen', 'Widescreen')[$Games::PangZero::FullScreen] + . ($self->{restart} ? ' (requires restart)' : '') . ' >'); + $self->{menuItems}->[6]->SetParameter( $Games::PangZero::ShowWebsite eq $Games::PangZero::VERSION ? 'no' : 'yes' ); +} + +sub RunOptionsMenu { + my $self = shift; + my $recall = $self->EnterSubMenu(); + my ($y, $yinc) = (80, 38); + push @{$self->{menuItems}}, ( + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Back to main menu"), + Games::PangZero::MenuItem->new( 100, $y += $yinc + 20, "Slippery floor: ", "Turning this on creates and icy floor that you slide on", "This makes the game a lot harder!" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Ball Mixer...", "Turn the special balls on and off.", "This can make the game easier." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Sound: ", "Press Enter to turn sound effects on/off." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Music: ", "Press Enter to turn the background music on/off." ), + Games::PangZero::MenuItem->new( 68, $y += $yinc, "Fullscreen", "Press Left/Right to set the screen mode.", "If you have a wide screen (e.g. 16:9), use the Widescreen option.", "This doesn't take effect until you quit and restart the game." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Show website at exit: ", "Should Pang Zero take you to our web site at exit?", "True enlightenment awaits you online!" ), + ); + $self->UpdateOptionsMenu(); + push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); + $self->SetCurrentItemIndex(0); + + while (1) { + $self->MenuAdvance(); + last if $self->{abortgame}; + $self->HandleUpDownKeys(); + + if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} == 5) { + if ($Games::PangZero::FullScreen > 0) { --$Games::PangZero::FullScreen; $self->{restart} = 1; } + $self->UpdateOptionsMenu(); + } + if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} == 5) { + if ($Games::PangZero::FullScreen < 2) { ++$Games::PangZero::FullScreen; $self->{restart} = 1; } + $self->UpdateOptionsMenu(); + } + if ($Games::PangZero::MenuEvents{BUTTON}) { + last if $self->{currentItemIndex} == 0; # Back to main + if ($self->{currentItemIndex} == 2) { + $self->RunBallMixerMenu(); + } elsif ($self->{currentItemIndex} == 1) { + $Games::PangZero::Slippery = $Games::PangZero::Slippery ? 0 : 1; $self->UpdateOptionsMenu(); + } elsif ($self->{currentItemIndex} == 3) { + $Games::PangZero::SoundEnabled = 1 - $Games::PangZero::SoundEnabled; $self->UpdateOptionsMenu(); + } elsif ($self->{currentItemIndex} == 4) { + Games::PangZero::Music::SetMusicEnabled(1 - $Games::PangZero::MusicEnabled); $self->UpdateOptionsMenu(); + } elsif ($self->{currentItemIndex} == 6) { + $Games::PangZero::ShowWebsite = $Games::PangZero::ShowWebsite eq $Games::PangZero::VERSION ? 0 : $Games::PangZero::VERSION; $self->UpdateOptionsMenu(); + } + } + } + + $self->LeaveSubMenu($recall); +} + +sub UpdateControlsMenu { + my $self = shift; + + $self->{menuItems}->[1]->SetText("< Number of Players: $Games::PangZero::NumGuys >"); + for (my $i = 1 ; $i <= 6; ++$i) { + if ($i > $Games::PangZero::NumGuys) { + $self->{menuItems}->[$i+1]->Hide(); + $self->{keysAsText}->[$i-1]->Hide(); + } else { + $self->{menuItems}->[$i+1]->Show(); + $self->{keysAsText}->[$i-1]->Show(); + } + } +} + +sub RunControlsMenu { + my $self = shift; + my ($menuItem, @keysAsText, @yPositions); + + my $recall = $self->EnterSubMenu(); + $self->{title}->Hide(); + my $baseY = 50; + + push @{$self->{menuItems}}, + Games::PangZero::MenuItem->new( 50, $baseY, "Back to main menu"), + Games::PangZero::MenuItem->new( 18, $baseY += 40, "<>", "Use left and right key to set the number of players here.", "The more the merrier!", "Don't forget to set their keys below." ); + for ( my $i = 1; $i <= 6; ++$i ) { + $yPositions[$i] = $baseY + 20 + $i * 40; + push @{$self->{menuItems}}, (Games::PangZero::MenuItem->new( 50, $yPositions[$i], "Player $i")); + push @keysAsText, (Games::PangZero::MenuItem->new( 220, $yPositions[$i], KeysToText($Games::PangZero::Players[$i-1]->{keys})) ); + } + push @Games::PangZero::GameObjects, (@keysAsText, @{$self->{menuItems}}); + $self->{keysAsText} = \@keysAsText; + $self->UpdateControlsMenu(); + $self->SetCurrentItemIndex(1); + + while (1) { + $self->MenuAdvance(); + last if $self->{abortgame}; + $self->HandleUpDownKeys(); + if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} == 1) { + --$Games::PangZero::NumGuys if $Games::PangZero::NumGuys > 1; + $self->UpdateControlsMenu(); + } + if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} == 1) { + ++$Games::PangZero::NumGuys if $Games::PangZero::NumGuys < 6; + $self->UpdateControlsMenu(); + } + if ($Games::PangZero::MenuEvents{BUTTON}) { + last if $self->{currentItemIndex} == 0; # Back to main + next if $self->{currentItemIndex} == 1; + my $player = $Games::PangZero::Players[$self->{currentItemIndex} - 2]; + my $key = 0; + my $keysAsText = $keysAsText[$self->{currentItemIndex} - 2]; + $self->{currentItem}->Hide(); + $keysAsText->Hide(); + my @prompts = ("Press 'LEFT' key or joystick button", "Press 'RIGHT' key", "Press 'FIRE' key"); + my $keyMenuItem = Games::PangZero::MenuItem->new( 100, $yPositions[$self->{currentItemIndex} - 1], $prompts[0] ); + push @Games::PangZero::GameObjects, ($keyMenuItem); + $keyMenuItem->Select; + while (1) { + $self->MenuAdvance(); + if ($self->{abortgame}) { + $self->{abortgame} = 0; + goto endOfKeyEntry; + } + if (%Games::PangZero::Events) { + my ($event) = %Games::PangZero::Events; + if ($event =~ /^B(\d+)$/) { + $player->{keys} = ["L$1", "R$1", "B$1"]; + last; + } + $player->{keys}->[$key] = $event; + ++$key; + last if $key >= 3; + $keyMenuItem->SetText($prompts[$key]); + } + } + + $keyMenuItem->SetText('Select character'); + my $guy = Games::PangZero::Guy->new($player); + $guy->{x} = $keyMenuItem->{targetX} + $keyMenuItem->{w} + 10; + $guy->{y} = $keyMenuItem->{targetY} - 10; + $guy->DemoMode(); + splice @Games::PangZero::GameObjects, -2, 0, $guy; + while (1) { + $self->MenuAdvance(); + if ($self->{abortgame}) { + $self->{abortgame} = 0; + goto endOfKeyEntry; + } + if ($Games::PangZero::Events{$player->{keys}->[0]}) { + --$player->{imagefileindex}; + $player->{imagefileindex} = $#Games::PangZero::GuyImageFiles if $player->{imagefileindex} < 0; + Games::PangZero::Graphics::MakeGuySurface($player); + $guy->{surface} = $player->{guySurface}; + $guy->CalculateAnimPhases(); + } elsif ($Games::PangZero::Events{$player->{keys}->[1]}) { + ++$player->{imagefileindex}; + $player->{imagefileindex} = 0 if $player->{imagefileindex} > $#Games::PangZero::GuyImageFiles; + Games::PangZero::Graphics::MakeGuySurface($player); + $guy->{surface} = $player->{guySurface}; + $guy->CalculateAnimPhases(); + } elsif ($Games::PangZero::Events{$player->{keys}->[2]}) { + last; + } + } + + $keyMenuItem->SetText('Select color'); + while (1) { + $self->MenuAdvance(); + if ($self->{abortgame}) { + $self->{abortgame} = 0; + goto endOfKeyEntry; + } + if ($Games::PangZero::Events{$player->{keys}->[0]}) { + --$player->{colorindex}; + $player->{colorindex} = $#Games::PangZero::GuyColors if $player->{colorindex} < 0; + Games::PangZero::Graphics::MakeGuySurface($player); + $guy->{surface} = $player->{guySurface}; + } elsif ($Games::PangZero::Events{$player->{keys}->[1]}) { + ++$player->{colorindex}; + $player->{colorindex} = 0 if $player->{colorindex} > $#Games::PangZero::GuyColors; + Games::PangZero::Graphics::MakeGuySurface($player); + $guy->{surface} = $player->{guySurface}; + } elsif ($Games::PangZero::Events{$player->{keys}->[2]}) { + last; + } + } + + endOfKeyEntry: + $guy->Delete() if $guy; + $self->{currentItem}->Show(); + $self->{currentItem}->Select; + $keysAsText->SetText(KeysToText($player->{keys})); + $keysAsText->Show; + $keyMenuItem->HideAndDelete; + } + } + + foreach my $menuItem (@keysAsText) { $menuItem->HideAndDelete(); } + $self->LeaveSubMenu($recall); + $self->{title}->Show(); + delete $self->{keysAsText}; +} + +sub UpdateGameMenu { + my $self = shift; + + $self->{menuItems}->[3]->SetText("< Difficulty: $Games::PangZero::DifficultyLevel->{name} >"); + $self->{menuItems}->[4]->SetText("< Weapon Duration: $Games::PangZero::WeaponDuration->{name} >"); +} + +sub RunGameMenu { + my $self = shift; + my $recall = $self->EnterSubMenu(); + my ($y, $yinc) = (110, 40); + push @{$self->{menuItems}}, ( + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Back to main menu", "Press Enter to return to the main menu"), + Games::PangZero::MenuItem->new( 100, $y += $yinc + 20, "Start Panic Game", "In Panic Mode, the balls continuously fall from the sky.", "Can you keep up the pace?", "This game is for advanced players." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Start Challenge Game", "More and more difficult levels challenge your skill.", "This game is best for beginners." ), + Games::PangZero::MenuItem->new( 68, $y += $yinc, "<>", "Press the Left and Right keys to set the game difficulty.", "The game speed and number of harpoons depend on this setting.", "The `Miki' level is for Deathball Specialists (Panic mode only)." ), + Games::PangZero::MenuItem->new( 68, $y += $yinc, "<>", "Press the Left and Right keys to set the bonus weapon duration.", "This will determine how long you can use bonus weapons." ), + ); + $self->UpdateGameMenu(); + push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); + $self->SetCurrentItemIndex($Games::PangZero::LastGameMenuResult ? $Games::PangZero::LastGameMenuResult : 1); + + while (1) { + $self->MenuAdvance(); + last if $self->{abortgame}; + $self->HandleUpDownKeys(); + + if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} == 3) { + Games::PangZero::Config::SetDifficultyLevel($Games::PangZero::DifficultyLevelIndex - 1); + $self->UpdateGameMenu(); + } + if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} == 3) { + Games::PangZero::Config::SetDifficultyLevel($Games::PangZero::DifficultyLevelIndex + 1); + $self->UpdateGameMenu(); + } + if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} == 4) { + Games::PangZero::Config::SetWeaponDuration($Games::PangZero::WeaponDurationIndex - 1); + $self->UpdateGameMenu(); + } + if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} == 4) { + Games::PangZero::Config::SetWeaponDuration($Games::PangZero::WeaponDurationIndex + 1); + $self->UpdateGameMenu(); + } + if ($Games::PangZero::MenuEvents{BUTTON}) { + last if $self->{currentItemIndex} == 0; # Back to main + if ($self->{currentItemIndex} == 1) { + $self->{result} = 'panic'; + } elsif ($self->{currentItemIndex} == 2) { + if ($Games::PangZero::DifficultyLevel->{name} ne 'Miki') { + $self->{result} = 'challenge'; + } else { + $self->ShowTooltip("Miki difficulty level is for panic mode only."); + } + } + } + last if $self->{result}; + } + + $Games::PangZero::LastGameMenuResult = $self->{currentItemIndex}; + $self->LeaveSubMenu($recall); +} + +sub OnMenuIdle { + my $self = shift; + + ++$self->{idle}; + if ($self->{idle} == 1) { $self->RunHighScores('auto'); } + elsif ($self->{idle} == 2) { $self->RunCredits('demo'); } + elsif ($self->{idle} == 3) { $self->{idle} = 0; return 'demo'; } + return ''; +} + +sub Run { + my $self = shift; + my ($y, $yinc, $idle); + + $self->ResetGame(); + $Games::PangZero::ScoreFont->use(); + ($y, $yinc) = ($Games::PangZero::ScreenHeight + 15, 20); + SDLx::SFont::print_text( $Games::PangZero::Background, 10, $y += $yinc, "Pang Zero $Games::PangZero::VERSION (C) 2006 by UPi (upi\@sourceforge.net)" ) if $y + $yinc * 2 < $Games::PangZero::PhysicalScreenHeight; + + SDLx::SFont::print_text( $Games::PangZero::Background, 10, $y += $yinc, "Use cursor keys to navigate menu, Enter to select" ) if $y + $yinc * 2 < $Games::PangZero::PhysicalScreenHeight; + + SDLx::SFont::print_text( $Games::PangZero::Background, 10, $y += $yinc, "P pauses the game, Esc quits" ) if $y + $yinc * 2 < $Games::PangZero::PhysicalScreenHeight; + + SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h), $Games::PangZero::App, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h)); + + $Games::PangZero::MenuFont->use(); + push @Games::PangZero::GameObjects, (Games::PangZero::FpsIndicator->new()); + $self->SetGameSpeed(); + $Games::PangZero::GamePause = 0; + + ($y, $yinc) = (90, 40); + + $self->{menuItems} = [ + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Start Game" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Options", "Various game settings" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Setup players", "Set the number of players, setup keys and joysticks" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Help", "How to play the game, demo of special balls" ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Credits", "You might be wondering: Who has created Pang Zero?", "Wonder no more." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "High Scores", "Hall of Fame." ), + Games::PangZero::MenuItem->new( 100, $y += $yinc, "Exit Game", "Press Enter to exit the game" ), + ]; + + $self->{title} = Games::PangZero::MenuItem->new( 300, 60, "PANG ZERO" ); + $self->{title}->{filled} = 1; + $self->{title}->{fillcolor} = SDL::Video::map_RGB($Games::PangZero::Background->format(), 0, 128, 255); + $self->{title}->Center(); + + push @Games::PangZero::GameObjects, ( + Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc[8], -1, 1), + Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc[0], -1, 0), + Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc{super0}, -1, 1), + Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc[2], -1, 0), + Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc[5], -1, 1), + $self->{title}, + @{$self->{menuItems}}, + ); + + $self->SetCurrentItemIndex( 0 ); + Games::PangZero::GameTimer::ResetTimer(); + + while (1) { + $self->MenuAdvance(); + $self->Exit() if $self->{abortgame}; + $self->HandleUpDownKeys(); + last if $self->{result}; + if ($Games::PangZero::MenuEvents{BUTTON}) { + if ($self->{currentItemIndex} == 0) { + $self->RunGameMenu(); + } elsif ($self->{currentItemIndex} == 1) { + $self->RunOptionsMenu(); + } elsif ($self->{currentItemIndex} == 2) { + $self->RunControlsMenu(); + } elsif ($self->{currentItemIndex} == 3) { + $self->RunTutorialMenu; + } elsif ($self->{currentItemIndex} == 4) { + $self->RunCredits(); + } elsif ($self->{currentItemIndex} == 5) { + $self->RunHighScores(); + } + $self->Exit() if $self->{currentItemIndex} == 6; + } + if (%Games::PangZero::Events) { + $idle = 0; + } else { + if (++$idle > 1000) { + $self->{result} = $self->OnMenuIdle(); + $idle = 0; + } + } + } + + $Games::PangZero::ScoreFont->use(); + return $self->{result}; +} + +1; diff --git a/lib/Games/PangZero/MenuItem.pm b/lib/Games/PangZero/MenuItem.pm new file mode 100644 index 0000000..7879d21 --- /dev/null +++ b/lib/Games/PangZero/MenuItem.pm @@ -0,0 +1,150 @@ +########################################################################## +package Games::PangZero::MenuItem; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); +use strict; +use warnings; +use vars qw($Gravity); +$Gravity = 0.2; + +sub new { + my ($class, $x, $y, $text) = @_; + my $self = Games::PangZero::GameObject->new(); + %{$self} = ( %{$self}, + 'targetX' => $x, + 'targetY' => $y, + 'h' => 42, + 'selected' => 0, + 'filled' => 0, + 'fillcolor' => SDL::Video::map_RGB($Games::PangZero::Background->format(), 0, 0, 128), + 'parameter' => 0, + 'tooltip' => [ @_[4 .. $#_] ], + ); + bless $self, $class; + $self->SetText($text); + $self->SetInitialSpeed(); + return $self; +} + +sub Center { + my $self = shift; + $self->{targetX} = ( $Games::PangZero::ScreenWidth - $self->{w} ) / 2; +} + +sub Show { + my $self = shift; + return if $self->CanSelect(); + $self->SetInitialSpeed(); +} + +sub Hide { + my $self = shift; + $self->SUPER::Clear(); + $self->{state} = 'leaving'; + $self->{speedX} = rand(10) - 5; +} + +sub HideAndDelete { + my $self = shift; + $self->Hide(); + $self->{deleteAfterHiding} = 1; +} + +sub Delete { + my $self = shift; + $self->{selected} = $self->{filled} = 0; + $self->SUPER::Delete(); +} + +sub ApproachingSpeed { + my ($position, $speed, $target) = @_; + + if ($position + $speed * abs($speed / $Gravity) / 2 > $target) { + return $speed - $Gravity; + } else { + return $speed + $Gravity; + } +} + +sub Advance { + my $self = shift; + + if ('entering' eq $self->{state}) { + $self->{x} += $self->{speedX}; + $self->{y} += $self->{speedY}; + $self->{speedX} = ApproachingSpeed($self->{x}, $self->{speedX}, $self->{targetX}); + $self->{speedY} = ApproachingSpeed($self->{y}, $self->{speedY}, $self->{targetY}); + if ( abs($self->{x} - $self->{targetX}) + abs($self->{y} - $self->{targetY}) < 2 ) { + $self->{x} = $self->{targetX}; + $self->{y} = $self->{targetY}; + $self->{state} = 'shown'; + } + } elsif ('leaving' eq $self->{state}) { + $self->{x} += $self->{speedX}; + $self->{y} += $self->{speedY}; + $self->{speedY} += $Gravity; + if ($self->{y} > $Games::PangZero::PhysicalScreenWidth) { + $self->{state} = 'hidden'; + $self->Delete() if $self->{deleteAfterHiding} + } + } +} + +sub Draw { + my $self = shift; + + return if $self->{state} eq 'hidden'; + $self->TransferRect(); + if ($self->{selected} or $self->{filled}) { + SDL::Video::fill_rect($Games::PangZero::App, $self->{rect}, $self->{fillcolor}); + } + SDLx::SFont::print_text( $Games::PangZero::App,$self->{x} + 5 +$Games::PangZero::ScreenMargin, $self->{y} + $Games::PangZero::ScreenMargin, $self->{text}); +} + +sub SetInitialSpeed { + my $self = shift; + $self->{x} = $self->{targetX} + rand(500) - 250; + $self->{y} = $Games::PangZero::PhysicalScreenHeight; + $self->{speedY} = -sqrt( 2 * $Gravity * ($self->{y} - $self->{targetY}) ); + $self->{speedX} = 0; + $self->{state} = 'entering'; +} + +sub InternalSetText { + my ($self, $text) = @_; + $self->SUPER::Clear(); + $self->{text} = $text; + $self->{w} = Games::PangZero::Graphics::TextWidth($text) + 10; +} + +sub SetText { + my ($self, $text) = @_; + $self->{parameter} = ''; + $self->{basetext} = $text; + $self->InternalSetText($text); +} + +sub SetParameter { + my ($self, $parameter) = @_; + $self->{parameter} = $parameter; + $self->InternalSetText($self->{basetext} . ' ' . $parameter); +} + +sub Select { + my ($self) = @_; + + foreach my $item (@Games::PangZero::GameObjects) { + $item->{selected} = 0 if ref $item eq 'Games::PangZero::MenuItem'; + } + $self->{selected} = 1; + $Games::PangZero::Game->ShowTooltip( @{$self->{tooltip}} ); +} + +sub CanSelect { + my ($self) = @_; + + return $self->{state} =~ /(?:entering|shown)/; +} + +1; diff --git a/lib/Games/PangZero/Music.pm b/lib/Games/PangZero/Music.pm new file mode 100644 index 0000000..e9623af --- /dev/null +++ b/lib/Games/PangZero/Music.pm @@ -0,0 +1,60 @@ +package Games::PangZero::Music; + +use SDL::Mixer ':init'; +use SDL::Mixer::Samples; +use SDL::Mixer::Channels; +use SDL::Mixer::Music; +use SDL::Mixer::MixChunk; +use SDL::Mixer::MixMusic; + +sub LoadMusic { + my ($filename) = @_; + + return undef unless -f $filename; + return SDL::Mixer::Music::load_MUS($filename); +} + +sub LoadSounds { + my $init_flags = SDL::Mixer::init( MIX_INIT_MP3 | MIX_INIT_OGG); + + $Mixer = SDL::Mixer::open_audio( 22050, AUDIO_S16, 2, 1024 ) + 1; + unless($Mixer) { + warn SDL::get_error(); + return 0; + } + + my ($soundName, $fileName); + while (($soundName, $fileName) = each %Games::PangZero::Sounds) { + $Sounds{$soundName} = SDL::Mixer::Samples::load_WAV("$Games::PangZero::DataDir/$fileName"); + } + + if (-f "$Games::PangZero::DataDir/UPiPang.mp3" && ($init_flags & MIX_INIT_MP3)) { + $Games::PangZero::music = LoadMusic("$Games::PangZero::DataDir/UPiPang.mp3"); + } elsif (-f "$Games::PangZero::DataDir/UPiPang.ogg" && ($init_flags & MIX_INIT_OGG)) { + $Games::PangZero::music = LoadMusic("$Games::PangZero::DataDir/UPiPang.ogg"); + } else { + $Games::PangZero::music = LoadMusic("$Games::PangZero::DataDir/UPiPang.mid"); + } + SetMusicEnabled($Games::PangZero::MusicEnabled); +} + +sub PlaySound { + return unless $Games::PangZero::SoundEnabled; + my $sound = shift; + $Mixer and $Sounds{$sound} and SDL::Mixer::Channels::play_channel( -1, $Sounds{$sound}, 0 ); +} + +sub SetMusicEnabled { + return $Games::PangZero::MusicEnabled = 0 unless $Games::PangZero::music; + my $musicEnabled = shift; + + $Games::PangZero::MusicEnabled = $musicEnabled ? 1 : 0; + if ( (not $musicEnabled) and SDL::Mixer::Music::playing_music() ) { + SDL::Mixer::Music::halt_music(); + } + if ($musicEnabled and not SDL::Mixer::Music::playing_music()) { + SDL::Mixer::Music::play_music($Games::PangZero::music, -1); + } +} + +1; diff --git a/lib/Games/PangZero/Palette.pm b/lib/Games/PangZero/Palette.pm new file mode 100644 index 0000000..17299c1 --- /dev/null +++ b/lib/Games/PangZero/Palette.pm @@ -0,0 +1,85 @@ +########################################################################## +# PALETTE MANIPULATION +########################################################################## + +package Games::PangZero::Palette; + +sub RgbToHsi { + my ($r, $g, $b) = @_; + my ($min, $max, $delta, $h, $s, $i); + + if ($r > $g) { + $max = $r > $b ? $r : $b; + $min = $g < $b ? $g : $b; + } else { + $max = $g > $b ? $g : $b; + $min = $r < $b ? $r : $b; + } + $i = ($min + $max) / 2; + if ($min == $max) { + return (0, 0, $i); + } + + $delta = ($max - $min); + if ($i < 128) { + $s = 255 * $delta / ($min + $max); + } else { + $s = 255 * $delta / (511 - $min - $max); + } + + if ($r == $max) { + $h = ($g - $b) / $delta; + } elsif ($g == $max) { + $h = 2 + ($b - $r) / $delta; + } else { + $h = 4 + ($r - $g) / $delta; + } + $h = $h * 42.5; + $h += 255 if $h < 0; + $h -= 255 if $h > 255; + + return ($h, $s, $i); +} + +sub HsiToRgb { + my ($h, $s, $i) = @_; + my ($m1, $m2); + + if ($s < 1) { + $i = int($i + 0.5); + return ($i, $i, $i); + } + + if ($i < 128) { + $m2 = ($i * (255 + $s)) / 65025.0; + } else { + $m2 = ($i + $s - ($i * $s) / 255.0) / 255.0; + } + $m1 = ($i / 127.5) - $m2; + + return ( + &GetHsiValue( $m1, $m2, $h + 85), + &GetHsiValue( $m1, $m2, $h), + &GetHsiValue( $m1, $m2, $h - 85) + ); +} + +sub GetHsiValue { + my ($n1, $n2, $hue) = @_; + my ($value); + + $hue -= 255 if ($hue > 255); + $hue += 255 if ($hue < 0); + if ($hue < 42.5) { + $value = $n1 + ($n2 - $n1) * ($hue / 42.5); + } elsif ($hue < 127.5) { + $value = $n2; + } elsif ($hue < 170) { + $value = $n1 + ($n2 - $n1) * ((170 - $hue) / 42.5); + } else { + $value = $n1; + } + return int($value * 255 + 0.5); +} + +1; diff --git a/lib/Games/PangZero/PanicGame.pm b/lib/Games/PangZero/PanicGame.pm new file mode 100644 index 0000000..b808541 --- /dev/null +++ b/lib/Games/PangZero/PanicGame.pm @@ -0,0 +1,139 @@ +########################################################################## +package Games::PangZero::PanicGame; +########################################################################## + +@ISA = qw(Games::PangZero::PlayableGameBase); + +sub new { + my ($class) = @_; + my $self = Games::PangZero::PlayableGameBase->new(); + %{$self} = (%{$self}, + 'spawndelay' => 0, + 'superballdelay' => 0, + 'leveladvance' => 0, + 'panicleveldesc' => undef, + ); + bless $self, $class; +} + +sub ResetGame { + my $self = shift; + $self->SUPER::ResetGame(); + $self->{spawndelay} = 0; + $self->{superballdelay} = 2500 + $self->Rand(2500); # 25sec - 50sec + $self->{superballdelay} *= $Games::PangZero::DifficultyLevel->{superball}; +} + +sub SetGameSpeed { + my ($self) = @_; + + $Games::PangZero::GameSpeed = $self->{leveldesc}->{gamespeed} * 0.8 * $Games::PangZero::DifficultyLevel->{speed}; +} + +sub SetGameLevel { + my ($self, $level) = @_; + my ($levelIndex); + + $levelIndex = ($level > $#Games::PangZero::PanicLevels) ? $#Games::PangZero::PanicLevels : $level; + $self->{leveldesc} = $Games::PangZero::PanicLevels[$levelIndex]; + die unless $self->{leveldesc}; + $self->{leveladvance} = 0; + $self->SUPER::SetGameLevel($level); +} + +sub AdvanceGame { + my ($self) = @_; + + $self->SpawnBalls() if $Games::PangZero::GamePause <= 0; + $self->SUPER::AdvanceGame(); +} + +sub SpawnBalls { + my $self = shift; + my ($randmax, $rnd, $ballName, $balldesc, $deathBallCount, $earthquakeBallCount, $hasBonus); + + --$self->{superballdelay}; + if ($self->{superballdelay} <= 0) { + push @Games::PangZero::GameObjects, ( + Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc{sprintf('super%d', $self->Rand(2))}, -1, $self->Rand(40) < 20 ? 0 : 1) ); + $self->{superballdelay} = (2500 + $self->Rand(2000)) * $Games::PangZero::DifficultyLevel->{superball}; # 25sec - 45sec + } + + --$self->{spawndelay}; + return if $self->{spawndelay} > 0; + $deathBallCount = $earthquakeBallCount = -1; + $randmax = 10000; + while ($self->{spawndelay} <= 0) { + if ($Games::PangZero::DifficultyLevel->{name} eq 'Miki') { + $balldesc = $Games::PangZero::BallDesc{'death'}; + last; + } + $rnd = int($self->Rand($randmax)); + $randmax = 0; + + # We try to find the balldesc that falls at $rnd + my $ballRoulette = $self->{leveldesc}->{balls}; + for (my $i = 0; $i < scalar @{$ballRoulette}; $i+=2) { + my $rouletteWeight = $ballRoulette->[$i+1]; + $randmax += $rouletteWeight; + $rnd -= $rouletteWeight; + if ($rnd < 0) { + $ballName = $ballRoulette->[$i]; + last; + } + } + next unless ($ballName); # $rnd too large.. We'll have a better $randmax this time! + + ($balldesc) = $Games::PangZero::BallDesc{$ballName}; + if ($balldesc->{class} eq 'DeathBall') { + next unless $Games::PangZero::DeathBallsEnabled; + $deathBallCount = Games::PangZero::DeathBall::CountDeathBalls() if $deathBallCount < 0; # Lazy counting + next if $deathBallCount >= 2; + } + if ($balldesc->{class} eq 'EarthquakeBall') { + next unless $Games::PangZero::EarthquakeBallsEnabled; + $earthquakeBallCount = Games::PangZero::EarthquakeBall::CountEarthquakeBalls if $earthquakeBallCount < 0; + next if $earthquakeBallCount >= 1; + } + if ($balldesc->{class} eq 'WaterBall') { + next unless $Games::PangZero::WaterBallsEnabled; + } + if ($balldesc->{class} eq 'SeekerBall') { + next unless $Games::PangZero::SeekerBallsEnabled; + } + last if $balldesc; + } + + $hasBonus = 1 if ($balldesc->{width} >= 32) and ($self->Rand(1) < $Games::PangZero::DifficultyLevel->{bonusprobability}); + + push @Games::PangZero::GameObjects, ( Games::PangZero::Ball::Spawn($balldesc, -1, $self->Rand(40) < 20 ? 0 : 1, $hasBonus) ); + $self->{spawndelay} = $self->{leveldesc}->{spawndelay} * $balldesc->{spawndelay} * 50; + $self->{spawndelay} /= ($Games::PangZero::NumGuys + 1) / 2; + $self->{spawndelay} *= $Games::PangZero::DifficultyLevel->{spawnmultiplier}; +} + +sub OnBallPopped { + my $self = shift; + + ++$self->{leveladvance}; + if ($self->{leveladvance} >= 18) { + Games::PangZero::Music::PlaySound('level'); + $self->SetGameLevel($self->{level}+1); + } +} + +sub DrawLevelIndicator { + my ($self, $x, $y) = @_; + + $self->{levelIndicatorRect} = SDL::Rect->new($x, $y, 140, $self->{scoreBoardHeight}) unless $self->{levelIndicatorRect}; + SDL::Video::fill_rect($Games::PangZero::App, $self->{levelIndicatorRect}, SDL::Video::map_RGB($Games::PangZero::App->format(), 0, 0, 0)); + SDL::Video::blit_surface($Games::PangZero::LevelIndicatorSurface2, SDL::Rect->new($x, $y, $Games::PangZero::LevelIndicatorSurface2->w, $Games::PangZero::LevelIndicatorSurface2->h), + $Games::PangZero::App, SDL::Rect->new($x, $y, 0, 0)); + SDL::Video::blit_surface($Games::PangZero::LevelIndicatorSurface, SDL::Rect->new(0, 0, 130 * $self->{leveladvance} / 17, 30), $Games::PangZero::App, SDL::Rect->new($x, $y, 0, 0)); + SDLx::SFont::print_text( $Games::PangZero::App, $x + 25, $y + 3, 'Level ' . ($self->{level}+1) ); + + SDLx::SFont::print_text( $Games::PangZero::App, $x, $y + 40, sprintf('spd: %d/%d', $Games::PangZero::GameSpeed * 100, $self->{leveldesc}->{spawndelay}) ) if $self->{scoreBoardHeight} >= 64; + +} + +1; diff --git a/lib/Games/PangZero/PlayableGameBase.pm b/lib/Games/PangZero/PlayableGameBase.pm new file mode 100644 index 0000000..14d4838 --- /dev/null +++ b/lib/Games/PangZero/PlayableGameBase.pm @@ -0,0 +1,414 @@ +########################################################################## +package Games::PangZero::PlayableGameBase; +########################################################################## + +@ISA = qw( Games::PangZero::GameBase ); + +use strict; +use warnings; +use SDL::Video; + +sub new { + my ($class) = @_; + my $self = Games::PangZero::GameBase->new(); + %{$self} = (%{$self}, + 'playersalive' => 0, + 'level' => 0, + 'backgrounds' => [ qw( desert2.png l1.jpg l2.jpg l3.jpg l4.jpg l5.jpg l6.jpg l7.jpg l8.jpg l9.jpg )], + ); + bless $self, $class; +} + +sub ResetGame { + my $self = shift; + $self->SUPER::ResetGame(); + $self->{playersalive} = 0; + $Games::PangZero::GamePause = 0; + + foreach my $player (@Games::PangZero::Players) { + last if $player->{number} >= $Games::PangZero::NumGuys; + $self->SpawnPlayer($player); + } + $self->SetGameLevel(0); + $self->LayoutScoreBoard(); + push @Games::PangZero::GameObjects, (Games::PangZero::FpsIndicator->new()); +} + +sub SetGameSpeed { + my $self = shift; + + $Games::PangZero::GameSpeed = 0.8 * $Games::PangZero::DifficultyLevel->{speed}; +} + +sub SetGameLevel { + my ($self, $level) = @_; + + $self->{level} = $level; + if (($level % 10) == 9) { + $self->SetBackground( int($level / 10) + 1 ); + } + $self->SetGameSpeed(); +} + +sub SpawnPlayer { + my ($self, $player) = @_; + $player->{score} = 0; + $player->{scoreforbonuslife} = 200000; + $player->{lives} = 2; + $player->{startX} = ($Games::PangZero::ScreenWidth - $Games::PangZero::NumGuys * 60) / 2 + 60 * ($player->{number}+0.5) - 32; + $player->{respawn} = -1; + my $guy = Games::PangZero::Guy->new($player); + push @Games::PangZero::GameObjects, ($guy); + ++$self->{playersalive}; + return $guy; +} + +sub AdvanceGameObjects { + my ($self) = @_; + + $self->SUPER::AdvanceGameObjects(); + $self->RespawnPlayers(); + --$Games::PangZero::GamePause if $Games::PangZero::GamePause > 0; +} + +sub RespawnPlayers { + my $self = shift; + + foreach my $player (@Games::PangZero::Players) { + last if $player->{number} >= $Games::PangZero::NumGuys; + if ($player->{respawn} > 0) { + --$player->{respawn}; + $player->{score} = int($player->{respawn} / 100) if $self->{playersalive}; + if ($player->{respawn} <= 0) { + my $guy = $self->SpawnPlayer($player); + $guy->{invincible} = 500; + } + } + } +} + +sub PlayerNextLife { + my ($self, $guy) = @_; + + $guy->DeleteHarpoons; + if ($guy->{player}->{lives}--) { + $guy->{x} = $guy->{player}->{startX}; + $guy->{y} = $Games::PangZero::ScreenHeight - $guy->{h}; + $guy->{state} = 'idle'; + $guy->{speedY} = $guy->{speedX} = 0; + $guy->{invincible} = 500; # 0.5s + $guy->{killed} = 0; + $guy->{justkilled} = 0; + $self->{playerspawned} = 1; + } else { + # One player less + Games::PangZero::Highscore::AddHighScore($guy->{player}, $guy->{player}->{score}, $self->{level} + 1); + $guy->Delete(); + --$self->{playersalive}; + $guy->{player}->{respawn} = 6000; # 60s + } +} + +sub PlayerDeathSequence { + my $self = shift; + my (@killedGuys, @deadGuys, $guy, $i); + + $self->DrawGame(); + Games::PangZero::Music::PlaySound('death'); + Games::PangZero::Graphics::RenderBorder($Games::PangZero::WhiteBorderSurface, $Games::PangZero::App); + SDL::Video::flip($Games::PangZero::App); + $self->Delay(10); + Games::PangZero::Graphics::RenderBorder($Games::PangZero::RedBorderSurface, $Games::PangZero::App); + Games::PangZero::Graphics::RenderBorder($Games::PangZero::RedBorderSurface, $Games::PangZero::Background); + SDL::Video::flip($Games::PangZero::App); + $self->Delay(90); + + @killedGuys = grep { $_->{justkilled}; } @Games::PangZero::GameObjects; + foreach $guy (@killedGuys) { + $guy->Clear(); + $guy->{killed} = 1; + push @deadGuys, (Games::PangZero::DeadGuy->new($guy)); + } + push @Games::PangZero::GameObjects, (@deadGuys); + + for ($i = 0; $i < 300; ++$i) { + Games::PangZero::HandleEvents(); + return if $self->{abortgame}; + my $advance = $self->CalculateAdvances(); + while ($advance--) { + foreach my $gameObject (@deadGuys) { + $gameObject->Advance(); + } + } + $self->DrawGame(); + last if $deadGuys[0]->{deleted}; + } + + foreach $guy (@killedGuys) { + $self->PlayerNextLife($guy); + } + + Games::PangZero::Graphics::RenderBorder($Games::PangZero::BorderSurface, $Games::PangZero::App); + Games::PangZero::Graphics::RenderBorder($Games::PangZero::BorderSurface, $Games::PangZero::Background); +} + +sub SuperKill { + my ($self, $guy) = @_; + my @gameObjects = @Games::PangZero::GameObjects; + my $sound = 0; + foreach my $ball (@gameObjects) { + next unless $ball->isa("Games::PangZero::Ball"); + $ball->Pop($guy, 'superkill'); + $sound = 1; + } + Games::PangZero::Music::PlaySound('pop') if $sound; +} + +sub PopEveryBall { + my $self = shift; + my @guys = (); + my @gameObjects = @Games::PangZero::GameObjects; + foreach (@gameObjects) { + if ($_->isa('Games::PangZero::Ball')) { + $_->Pop(undef, 'meltdown'); + } elsif ('Games::PangZero::Guy' eq ref $_) { + push @guys, $_; + } + } + return @guys; +} + +sub DeathballMeltdown { + my ($self) = @_; + my ($i, $allKilled, @guys, @killedGuys, @deadGuys); + $self->{nocollision} = 1; + my $meltdown = Games::PangZero::Meltdown->new(); + push @Games::PangZero::GameObjects, $meltdown; + + for ($i = 0; $i < 300; ++$i) { + %Games::PangZero::Events = (); + Games::PangZero::HandleEvents(); + return if $self->{abortgame}; + my $advance = $self->CalculateAdvances(); + while ($advance--) { +# TODO REINSTATE THIS IN 1.1!!! $self->PreAdvanceAction(); # Hook for something special + $self->SUPER::AdvanceGameObjects(); + $Games::PangZero::GamePause = 0; + if ($meltdown->{bounce} and not $allKilled) { + $allKilled = 1; + @guys = $self->PopEveryBall(); + foreach (@guys) { + $_->{killed} = 1; + push @deadGuys, Games::PangZero::DeadGuy->new($_); + push @killedGuys, $_; + } + push @Games::PangZero::GameObjects, (@deadGuys); + } + } + $self->DrawGame(); + } + + foreach (@killedGuys) { + $self->PlayerNextLife($_); + } + + $self->{nocollision} = 0; +} + + +########################################################################## +# GAME DRAWING +########################################################################## + +sub DrawScoreBoard { + my ($self) = @_; + + $self->DrawLevelIndicator( 10, $self->{scoreBoardTop} ); + for (my $i = 0; $i < $Games::PangZero::NumGuys; ++$i) { + $self->DrawScore( $Games::PangZero::Players[$i], $Games::PangZero::Players[$i]->{scoreX}, $Games::PangZero::Players[$i]->{scoreY} ); + } +} + +sub LayoutScoreBoard { + my ($self) = @_; + my $scoreBoardTop = $Games::PangZero::ScreenHeight + $Games::PangZero::ScreenMargin * 2 + 5; + my $scoreBoardHeight = $Games::PangZero::PhysicalScreenHeight - $scoreBoardTop; + my $rowHeight = 64; + my $leftMargin = 150; + my $rows = $Games::PangZero::NumGuys > 4 ? 2 : 1; + $rows = 1 if ($scoreBoardTop + $rows * $rowHeight > $Games::PangZero::PhysicalScreenHeight); + + if ($scoreBoardTop + $rows * $rowHeight > $Games::PangZero::PhysicalScreenHeight) { + $rowHeight = 32; + $scoreBoardTop = $Games::PangZero::PhysicalScreenHeight - 32; + } + + my $guysPerRow = int ($Games::PangZero::NumGuys / $rows + 0.5); + my $widthPerGuy = ($Games::PangZero::PhysicalScreenWidth - $leftMargin) / $guysPerRow; + + for (my $i = 0; $i < $Games::PangZero::NumGuys; ++$i) { + $Games::PangZero::Players[$i]->{scoreX} = $leftMargin + ($i % $guysPerRow) * $widthPerGuy; + $Games::PangZero::Players[$i]->{scoreY} = $scoreBoardTop + int ($i / $guysPerRow) * $rowHeight; + $Games::PangZero::Players[$i]->{scoreRect} = + SDL::Rect->new($Games::PangZero::Players[$i]->{scoreX}, $Games::PangZero::Players[$i]->{scoreY}, 130, $rowHeight); + } + + $self->{scoreBoardTop} = $scoreBoardTop; + $self->{scoreBoardHeight} = $scoreBoardHeight; + $self->{rowHeight} = $rowHeight; + +} + +sub DrawLevelIndicator { + my ($self, $x, $y) = @_; + $self->{levelIndicatorRect} = SDL::Rect->new($x, $y, 100, 32) unless $self->{levelIndicatorRect}; + SDL::Video::fill_rect($Games::PangZero::App, $self->{levelIndicatorRect}, SDL::Video::map_RGB($Games::PangZero::App->format(), 0, 0, 0)); + SDLx::SFont::print_text( $Games::PangZero::App, $x, $y + 3, 'Level ' . ($self->{level}+1) ); + +} + +sub PrintNumber { + my ($self, $player, $x, $y, $number) = @_; + my $numberText = sprintf("%d", $number); + my $srcrect = SDL::Rect->new(0, 160, 16, 16); + my $dstrect = SDL::Rect->new($x, $y, 16, 16); + + for (my $i = 0; $i < length($numberText); ++$i) { + $srcrect->x(320 + (ord(substr($numberText, $i)) - ord('0')) * 16); + $dstrect->x($x + $i * 16); + SDL::Video::blit_surface($player->{guySurface}, $srcrect, $Games::PangZero::App, $dstrect ); + } +} + +sub DrawScore { + my ($self, $player, $x, $y, $livesY) = @_; + + SDL::Video::fill_rect($Games::PangZero::App, $player->{scoreRect}, SDL::Video::map_RGB($Games::PangZero::App->format(), 0, 0, 0)); + $self->PrintNumber( $player, $x, $y, $player->{score}); + + $livesY = $self->{rowHeight} > 32 ? $y + 24 : $y + 16; + my $dstrect = SDL::Rect->new($x, $livesY, 32, 32); + my $srcrect = ($self->{rowHeight} <= 32) + ? SDL::Rect->new(320, 176, 16, 16) + : SDL::Rect->new(320, 128, 32, 32); + + if ($player->{lives} > 3) { + SDL::Video::blit_surface($player->{guySurface}, $srcrect, $Games::PangZero::App, $dstrect ); + $self->PrintNumber( $player, $x + $srcrect->w() + 8, $livesY + ($srcrect->h() - 16 ) / 2, $player->{lives} ); + } else { + foreach my $i ( 0 .. $player->{lives}-1 ) { + $dstrect->x( $x + $i * ($srcrect->w() + 4) ); + SDL::Video::blit_surface($player->{guySurface}, $srcrect, $Games::PangZero::App, $dstrect ); + } + } +} + +sub PreAdvanceAction {} + +sub AdvanceGame { + my $self = shift; + %Games::PangZero::GameEvents = (); + $self->PreAdvanceAction(); # Hook for something special + + if ($self->{superKillCount} > 0) { + if (--$self->{superKillDelay} <= 0) { + --$self->{superKillCount}; + $self->{superKillDelay} = 50; + $self->SuperKill($self->{superKillGuy}); + } + $Games::PangZero::GamePause = 0; + } + + $self->AdvanceGameObjects(); + if ($Games::PangZero::GameEvents{earthquake}) { + Games::PangZero::Music::PlaySound('quake'); + foreach my $guy (@Games::PangZero::GameObjects) { + $guy->Earthquake($Games::PangZero::GameEvents{earthquake}) if ref $guy eq 'Games::PangZero::Guy'; + } + } + + if ($Games::PangZero::GameEvents{'pop'}) { + Games::PangZero::Music::PlaySound('pop'); + } + + if ($Games::PangZero::GameEvents{meltdown} and $Games::PangZero::DifficultyLevel->{name} ne 'Miki') { + $self->DeathballMeltdown(); + } elsif ($Games::PangZero::GameEvents{kill} ) { + $self->PlayerDeathSequence(); + return if $self->{playersalive} <= 0; + $Games::PangZero::GamePause = 200 if $Games::PangZero::GamePause < 200; + Games::PangZero::GamePause::Show(); + } elsif ($Games::PangZero::GameEvents{magic}) { + if ($Games::PangZero::GamePause < 200) { + $Games::PangZero::GamePause = 200; + Games::PangZero::Music::PlaySound('pause'); + Games::PangZero::GamePause::Show(); + } + } elsif ($Games::PangZero::GameEvents{superpause}) { + if ($Games::PangZero::GamePause < 800) { + $Games::PangZero::GamePause = 800; + Games::PangZero::Music::PlaySound('pause'); + Games::PangZero::GamePause::Show(); + } + } elsif ($Games::PangZero::GameEvents{superkill}) { + $self->{superKillCount} = 5; + $self->{superKillDelay} = 0; + $self->{superKillGuy} = $Games::PangZero::GameEvents{superkillguy}; + $self->{spawndelay} = 250; + $self->{superballdelay} += 1000; # 10 second penalty + my @gameObjects = @Games::PangZero::GameObjects; + foreach my $spawningBall (@gameObjects) { + $spawningBall->Delete if $spawningBall->{spawning}; + } + } +} + +sub Run { + my ($self) = shift; + + $self->ResetGame(); + Games::PangZero::GameTimer::ResetTimer(); + + $self->{superKillCount} = 0; + $self->{superKillDelay} = 0; + $self->{superKillGuy} = undef; + + while (! $self->{abortgame}) { + + # Calculate advance (how many game updates to perform) + my $advance = $self->CalculateAdvances(); + + # Advance the game + + %Games::PangZero::Events = (); + Games::PangZero::HandleEvents(); + while ($advance-- && ! $self->{abortgame}) { + $self->AdvanceGame(); + } + + if ($self->{playersalive} <= 0) { + my $gameoverSurface = SDL::Image::load("$Games::PangZero::DataDir/gameover.png"); + my @gameObjects = @Games::PangZero::GameObjects; + foreach (@gameObjects) { $_->Delete() if ('Games::PangZero::DeadGuy' eq ref $_); } + $self->DrawGame(); + SDL::Video::blit_surface($gameoverSurface, SDL::Rect->new(0, 0, $gameoverSurface->w, $gameoverSurface->h), + $Games::PangZero::App, SDL::Rect->new( + ($Games::PangZero::PhysicalScreenWidth - $gameoverSurface->w) / 2, $Games::PangZero::PhysicalScreenHeight / 2 - 100, + $gameoverSurface->w, $gameoverSurface->h)); + SDL::Video::flip($Games::PangZero::App); + SDL::delay(1000); + for (my $i=0; $i < 20; ++$i) { + SDL::delay(100); + %Games::PangZero::Events = (); + Games::PangZero::HandleEvents(); + last if $self->{abortgame}; + last if %Games::PangZero::Events; + } + last; + } + $self->DrawGame(); + } + $self->SUPER::ResetGame(); +} + +1; diff --git a/lib/Games/PangZero/PlaybackGame.pm b/lib/Games/PangZero/PlaybackGame.pm new file mode 100644 index 0000000..e956af0 --- /dev/null +++ b/lib/Games/PangZero/PlaybackGame.pm @@ -0,0 +1,108 @@ +########################################################################## +package Games::PangZero::PlaybackGame; +########################################################################## + +@ISA = qw(Games::PangZero::PanicGame); +use strict; +use warnings; +use SDL::Video; + +sub new { + my ($class, $numGuys, $difficultyLevel, $record, $rand, $messages) = @_; + my $self = Games::PangZero::PanicGame->new(); + %{$self} = (%{$self}, + 'record' => $record, + 'rand' => $rand, + 'messages' => $messages, + ); + bless $self, $class; + $self->InitPlayback($numGuys); + Games::PangZero::Config::SetDifficultyLevel($difficultyLevel); + return $self; +} + +sub InitPlayback { + my ($self, $numGuys) = @_; + $self->{recordpointer} = 0; + $self->{randpointer} = 0; + $self->{oldnumguys} = $Games::PangZero::NumGuys; + $self->{olddifficultylevel} = $Games::PangZero::DifficultyLevelIndex; + $Games::PangZero::NumGuys = $numGuys; + + for (my $i=0; $i < $numGuys; ++$i) { + $Games::PangZero::Players[$i]->{oldkeys} = $Games::PangZero::Players[$i]->{keys}; + $Games::PangZero::Players[$i]->{keys} = [ "DLEFT$i", "DRIGHT$i", "DFIRE$i" ]; + } +} + +sub RestoreGameSettings { + my $self = shift; + + for (my $i=0; $i < $Games::PangZero::NumGuys; ++$i) { + $Games::PangZero::Players[$i]->{keys} = $Games::PangZero::Players[$i]->{oldkeys}; + delete $Games::PangZero::Players[$i]->{oldkeys}; + } + $Games::PangZero::NumGuys = $self->{oldnumguys}; + Games::PangZero::Config::SetDifficultyLevel($self->{olddifficultylevel}); +} + +sub CalculateAdvances { + my $self = shift; + + return length($self->{record}) if $self->{skip}; + return $self->SUPER::CalculateAdvances() * ($Games::PangZero::Keys{::SDLK_f()} ? 15 : 1); +} + +sub Rand { + my $self = shift; + + my $result = $self->{rand}->[$self->{randpointer}]; + ++$self->{randpointer}; + return $result; +} + +sub PreAdvanceAction { + my $self = shift; + my ($record, $keys); + + for (my $i=0; $i < $Games::PangZero::NumGuys; ++$i) { + + $record = substr($self->{record}, $self->{recordpointer}++, 1); + $keys = $Games::PangZero::Players[$i]->{keys}; + $Games::PangZero::Keys{$keys->[0]} = $record & 1; + $Games::PangZero::Keys{$keys->[1]} = $record & 2; + $Games::PangZero::Events{$keys->[2]} = $record & 4; + $Games::PangZero::GameEvents{superkill} = 1 if $Games::PangZero::NumGuys == 1 and $record & 8; + } + + $self->{abortgame} = 1 if $self->{recordpointer} >= length $self->{record}; + + if ($self->{messages}) { + my $message = $self->{messages}->{$self->{recordpointer}}; + $self->DisplayMessage($message) if $message; + } +} + +sub DisplayMessage { + my ($self, $message) = @_; + my ($len, $adv) = (0, 0); + my $x = ( $Games::PangZero::PhysicalScreenWidth - &Games::PangZero::Graphics::TextWidth($message) ) / 2; + my $y = $Games::PangZero::PhysicalScreenHeight / 2; + $self->DrawGame(); + + while (1) { + Games::PangZero::HandleEvents(); + return if $self->{abortgame}; + my $advance = $self->CalculateAdvances(); + $adv += $advance; + $len = int($adv / 5); + + SDLx::SFont::print_text( $Games::PangZero::App,$x, $y, substr($message, 0, $len) ); + + SDL::Video::flip($Games::PangZero::App); + last if $len > length($message) + 15; + } + SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, $y, $Games::PangZero::PhysicalScreenWidth, $y, 40), $Games::PangZero::App, SDL::Rect->new(0, $y, $Games::PangZero::App->w, $Games::PangZero::App->h)); +} + +1; diff --git a/lib/Games/PangZero/Pop.pm b/lib/Games/PangZero/Pop.pm new file mode 100644 index 0000000..ed118fe --- /dev/null +++ b/lib/Games/PangZero/Pop.pm @@ -0,0 +1,56 @@ +########################################################################## +package Games::PangZero::Pop; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); + +@Description = ( + { 'xoffset' => 0, 'yoffset' => 0, 'srcx' => 128, 'srcy' => 0, 'sizex' => 128, 'sizey' => 106, }, + { 'xoffset' => 0, 'yoffset' => 0, 'srcx' => 96, 'srcy' => 0, 'sizex' => 96, 'sizey' => 80, }, + { 'xoffset' => 0, 'yoffset' => 0, 'srcx' => 64, 'srcy' => 0, 'sizex' => 64, 'sizey' => 53, }, + { 'xoffset' => 0, 'yoffset' => 0, 'srcx' => 32, 'srcy' => 0, 'sizex' => 32, 'sizey' => 28, }, + { 'xoffset' => 0, 'yoffset' => 0, 'srcx' => 16, 'srcy' => 0, 'sizex' => 16, 'sizey' => 15, }, + + { 'xoffset' => 0, 'yoffset' => 0, 'srcx' => 192, 'srcy' => 0, 'sizex' => 64, 'sizey' => 52, }, + { 'xoffset' => 0, 'yoffset' => 0, 'srcx' => 96, 'srcy' => 0, 'sizex' => 32, 'sizey' => 28, }, + { 'xoffset' => 0, 'yoffset' => 0, 'srcx' => 48, 'srcy' => 0, 'sizex' => 16, 'sizey' => 14, }, +); + +sub new { + my ($class, $x, $y, $index, $surface) = @_; + my $desc = $Games::PangZero::Pop::Description[$index], + my $self = Games::PangZero::GameObject->new(); + %{$self} = ( %{$self}, + 'x' => $x + $desc->{xoffset}, + 'y' => $y + $desc->{yoffset}, + 'w' => $desc->{sizex}, + 'h' => $desc->{sizey}, + 'desc' => $desc, + 'anim' => 0, + 'surface' => $surface, + ); + bless $self, $class; +} + +sub Advance { + my $self = shift; + + if (++$self->{anim} >= 20) { + $self->Delete(); + } +} + +sub Draw { + my $self = shift; + $self->TransferRect(); + my $phase = int($self->{anim} / 5); + $phase = 3 if $phase > 3; + my $srcrect = SDL::Rect->new( + $self->{desc}->{srcx} + $phase * $self->{w}, + $self->{desc}->{srcy}, + $self->{w}, + $self->{h} ); + SDL::Video::blit_surface($self->{surface}, $srcrect, $Games::PangZero::App, $self->{rect} ); +} + +1; diff --git a/lib/Games/PangZero/PowerWire.pm b/lib/Games/PangZero/PowerWire.pm new file mode 100644 index 0000000..4aebf1e --- /dev/null +++ b/lib/Games/PangZero/PowerWire.pm @@ -0,0 +1,44 @@ +########################################################################## +package Games::PangZero::PowerWire; +########################################################################## + +@ISA = qw(Games::PangZero::Harpoon); +use strict; +use warnings; + +sub Create { + return Games::PangZero::PowerWire->new(@_); +} + +sub new { + my $class = shift; + my $self = Games::PangZero::Harpoon->new(@_); + %{$self} = ( %{$self}, + 'topdelay' => 200, + ); + bless $self, $class; +} + +sub Advance { + my $self = shift; + + if ($self->{y} > 0) { + return $self->SUPER::Advance(); + } + $self->{y} = 0; + --$self->{topdelay}; + if ($self->{topdelay} <= 0) { + $self->Delete(); + } +} + +sub GetAnimPhase { + my $self = shift; + + if ($self->{y} <= 0) { + return 0; + } + return $self->SUPER::GetAnimPhase(); +} + +1; diff --git a/lib/Games/PangZero/RecordGame.pm b/lib/Games/PangZero/RecordGame.pm new file mode 100644 index 0000000..8249daf --- /dev/null +++ b/lib/Games/PangZero/RecordGame.pm @@ -0,0 +1,65 @@ +########################################################################## +package Games::PangZero::RecordGame; +########################################################################## + +@ISA = qw(Games::PangZero::PanicGame); +use strict; +use warnings; +use SDL; + +sub Rand { + my $self = shift; + my $result = int(rand($_[0]) * 100) / 100; + push @{$self->{rand}}, ($result); + return $result; +} + +sub Rewind { + my $self = shift; + my ($recordEnd, $playback); + + $recordEnd = length($self->{record}) - $Games::PangZero::NumGuys * 1000; + return if $recordEnd <= 0; + $self->{record} = substr($self->{record}, 0, $recordEnd); + $Games::PangZero::Game = $playback + = DemoPlaybackGame->new($Games::PangZero::NumGuys, $Games::PangZero::DifficultyLevel, $self->{record}, $self->{rand}, {}); + $playback->{skip} = 1; + SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h), $Games::PangZero::App, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h)); + $playback->Run(); + + $playback->RestoreGameSettings(); + %{$self} = %{$playback}; + $Games::PangZero::Game = $self; + $self->{abortgame} = 0; + print "Splicing {rand}: original length is ", scalar(@{$self->{rand}}), "; playback randpointer is $playback->{randpointer}.\n"; + splice @{$self->{rand}}, $playback->{randpointer}; + SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h), $Games::PangZero::App, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h)); + $self->DrawGame(); + %Games::PangZero::Events = %Games::PangZero::Keys = (); + + while( not %Games::PangZero::Events ) { + Games::PangZero::HandleEvents(); + SDL::delay(100); + } + GameTimer::ResetTimer(); +} + +sub PreAdvanceAction { + my $self = shift; + $self->Rewind() if $Games::PangZero::Events{::SDLK_F3()}; + + for (my $i = 0; $i < $Games::PangZero::NumGuys; ++$i) { + my $keys = $Games::PangZero::Players[$i]->{keys}; + my $record = 0; + $record += 1 if $Games::PangZero::Keys{$keys->[0]}; + $record += 2 if $Games::PangZero::Keys{$keys->[1]}; + $record += 4 if $Games::PangZero::Events{$keys->[2]}; + if ($Games::PangZero::Events{SDLK_F2()} and $Games::PangZero::NumGuys == 1) { + $record += 8; + $Games::PangZero::GameEvents{superkill} = 1; + } + $self->{record} .= $record; + } +} + +1; diff --git a/lib/Games/PangZero/SeekerBall.pm b/lib/Games/PangZero/SeekerBall.pm new file mode 100644 index 0000000..3013c51 --- /dev/null +++ b/lib/Games/PangZero/SeekerBall.pm @@ -0,0 +1,63 @@ +########################################################################## +package Games::PangZero::SeekerBall; +########################################################################## + +@ISA = qw( Games::PangZero::Ball ); +use strict; +use warnings; + +sub new { + my $class = shift; + my $self = Games::PangZero::Ball->new(@_); + my @guys = grep {ref $_ eq 'Games::PangZero::Guy'} @Games::PangZero::GameObjects; + $self->{target} = $guys[$Games::PangZero::Game->Rand(scalar @guys)]; + $self->{deltaX} = (-$self->{w} + $self->{target}->{w}) / 2; + die unless $self->{target}; + + bless $self, $class; +} + +sub NormalAdvance { + my $self = shift; + + my $multiplier = ($self->{y} > $Games::PangZero::ScreenHeight - 120) ? 0 : 25; + unless( $Games::PangZero::GamePause > 0 ) { + if ($self->{x} + $self->{speedX} * $multiplier > $self->{target}->{x} + $self->{deltaX}) { + $self->{speedX} -= 0.08; + } else { + $self->{speedX} += 0.08; + } + } + $self->SUPER::NormalAdvance(); +} + +sub AdjustChildren { + my ($self, $child1, $child2) = @_; + + $self->SUPER::AdjustChildren($child1, $child2); + $child1->{speedX} *= 2; + $child1->{deltaX} -= 30; + $child1->{target} = $self->{target}; + $child2->{speedX} *= 2; + $child2->{deltaX} += 30; + $child2->{target} = $self->{target}; +} + +sub GiveMagic { +} + +sub Draw { + my $self = shift; + + $self->SUPER::Draw(); + my $guySurface = $self->{target}->{player}->{guySurface}; + my $srcrect = ($self->{w} <= 32) + ? SDL::Rect->new(320, 176, 16, 16) + : SDL::Rect->new(320, 128, 32, 32); + my $dstrect = SDL::Rect->new( + $self->{x} + $Games::PangZero::ScreenMargin + ($self->{w} - $srcrect->w()) / 2, + $self->{y} + $Games::PangZero::ScreenMargin + ($self->{h} - $srcrect->h()) / 2 + 2, $srcrect->w, $srcrect->h); + SDL::Video::blit_surface($guySurface, $srcrect, $Games::PangZero::App, $dstrect); +} + +1; diff --git a/lib/Games/PangZero/SlowEffect.pm b/lib/Games/PangZero/SlowEffect.pm new file mode 100644 index 0000000..fcaed4b --- /dev/null +++ b/lib/Games/PangZero/SlowEffect.pm @@ -0,0 +1,51 @@ +########################################################################## +package Games::PangZero::SlowEffect; +########################################################################## + +@ISA = qw(Games::PangZero::GameObject); +use strict; +use warnings; + +sub new { + my ($class) = @_; + my $self = Games::PangZero::GameObject->new(); + %{$self} = ( %{$self}, + 'timeout' => 1500, # Lasts for 15s + ); + # TODO Play a sound here + bless $self, $class; + return $self; +} + +sub RemoveSlowEffects { + @Games::PangZero::GameObjects = grep { ref $_ ne 'Games::PangZero::SlowEffect' } @Games::PangZero::GameObjects; +} + +sub Advance { + my ($self) = @_; + my ($timeout, $slowratio); + + $timeout = --$self->{timeout}; + if ( $timeout == 256 ) { + # TODO Play a sound here + } + if ( $timeout > 256 ) { + $Games::PangZero::GameSpeed = 0.2; + } elsif ( $timeout > 0 ) { + $Games::PangZero::Game->SetGameSpeed(); + $slowratio = int(256 - $timeout) / 256; + $Games::PangZero::GameSpeed = $Games::PangZero::GameSpeed * $slowratio + 0.2 * (1.0 - $slowratio); + } else { + $Games::PangZero::Game->SetGameSpeed(); + $self->Delete(); + return; + } +} + +sub Draw { +} + +sub Clear { +} + +1; diff --git a/lib/Games/PangZero/SuperBall.pm b/lib/Games/PangZero/SuperBall.pm new file mode 100644 index 0000000..b5a6d5c --- /dev/null +++ b/lib/Games/PangZero/SuperBall.pm @@ -0,0 +1,50 @@ +########################################################################## +package Games::PangZero::SuperBall; +########################################################################## + +@ISA = qw(Games::PangZero::Ball); +use strict; +use warnings; + +sub new { + my $class = shift; + my $self = Games::PangZero::Ball->new(@_); + $self->{effect} = 1; # 0 : superpause; 1 : superkill + bless $self, $class; + $self->SwitchEffect(); + return $self; +} + +sub SwitchEffect { + my $self = shift; + $self->{effect} = 1 - $self->{effect}; + $self->{surface} = $Games::PangZero::BallSurfaces{($self->{effect} ? 'gold' : 'green') . ($self->{w} > 64 ? 1 : 2)}; +} + +sub Bounce { + my $self = shift; + + $self->SwitchEffect(); +} + +sub SpawnChildren { + return (); +} + +sub Pop { + my $self = shift; + my ($poppedBy) = @_; + + $self->SUPER::Pop(@_); + if ($self->{effect} == 0) { + $Games::PangZero::GameEvents{superpause} = 1; + } else { + $Games::PangZero::GameEvents{superkill} = 1; + $Games::PangZero::GameEvents{superkillguy} = $poppedBy; + } +} + +sub GiveMagic { +} + +1; diff --git a/lib/Games/PangZero/TutorialGame.pm b/lib/Games/PangZero/TutorialGame.pm new file mode 100644 index 0000000..0c1f204 --- /dev/null +++ b/lib/Games/PangZero/TutorialGame.pm @@ -0,0 +1,41 @@ +########################################################################## +package Games::PangZero::TutorialGame; +########################################################################## + +@ISA = qw(Games::PangZero::ChallengeGame); +use strict; +use warnings; + +sub SetChallenge { + my ($self, $challenge) = @_; + + $self->{challenge} = $challenge; +} + +sub SetGameLevel { + my ($self, $level) = @_; + + $self->Games::PangZero::PlayableGameBase::SetGameLevel($level); + $self->SpawnChallenge(); +} + +sub AdvanceGame { + my ($self) = @_; + + if ($self->{nextlevel}) { + $self->{countDown} = 200; + delete $self->{nextlevel}; + } + if ($self->{playerspawned}) { + $self->SpawnChallenge(); + $self->{playerspawned} = 0; + } + if ($self->{countDown}) { + if (--$self->{countDown} < 1) { + $self->{abortgame} = 1; + } + } + $self->Games::PangZero::PlayableGameBase::AdvanceGame(); +} + +1; diff --git a/lib/Games/PangZero/UpsideDownBall.pm b/lib/Games/PangZero/UpsideDownBall.pm new file mode 100644 index 0000000..7f5e3fe --- /dev/null +++ b/lib/Games/PangZero/UpsideDownBall.pm @@ -0,0 +1,19 @@ +########################################################################## +package Games::PangZero::UpsideDownBall; +########################################################################## + +@ISA = qw( Games::PangZero::Ball ); +use strict; +use warnings; + +sub NormalAdvance { + my ($self) = @_; + + $self->{speedY} = -$self->{speedY}; + $self->{y} = $Games::PangZero::ScreenHeight - $self->{h} - $self->{y}; + $self->SUPER::NormalAdvance(); + $self->{speedY} = -$self->{speedY}; + $self->{y} = $Games::PangZero::ScreenHeight - $self->{h} - $self->{y}; +} + +1; diff --git a/lib/Games/PangZero/WaterBall.pm b/lib/Games/PangZero/WaterBall.pm new file mode 100644 index 0000000..80e9484 --- /dev/null +++ b/lib/Games/PangZero/WaterBall.pm @@ -0,0 +1,15 @@ +########################################################################## +package Games::PangZero::WaterBall; +########################################################################## + +@ISA = qw( Games::PangZero::Ball ); + +sub Bounce { + my $self = shift; + if ($self->{desc}->{nextgen}) { + $self->{bonus} = 0; + $self->Pop(undef, ''); + } +} + +1; diff --git a/lib/Games/PangZero/XmasBall.pm b/lib/Games/PangZero/XmasBall.pm new file mode 100644 index 0000000..e6cb1a6 --- /dev/null +++ b/lib/Games/PangZero/XmasBall.pm @@ -0,0 +1,47 @@ +########################################################################## +package Games::PangZero::XmasBall; +########################################################################## + +@ISA = qw(Games::PangZero::Ball); +use strict; +use warnings; + +sub SpawnChildren { + return (); +} + +sub Pop { + my $self = shift; + $self->SUPER::Pop(@_); + my $bonusdrop = Games::PangZero::BonusDrop->new($self); + my @collectedSubs = ( \&OnCollectedLife, \&OnCollectedScore, \&OnCollectedScore, \&OnCollectedInvulnerability, \&OnCollectedInvulnerability ); + if ($Games::PangZero::Game->Rand(2 * scalar @collectedSubs) < scalar @collectedSubs) { + $bonusdrop->{desc} = { 'srcRect' => SDL::Rect->new(0, 0, 32, 32), }; + $bonusdrop->SetOnCollectedSub( $collectedSubs[int $Games::PangZero::Game->Rand(scalar @collectedSubs)] ); + } + push @Games::PangZero::GameObjects, $bonusdrop; +} + +sub GiveMagic { +} +sub GiveBonus { +} + +sub OnCollectedLife { + my ($bonus, $guy) = @_; + $guy->{player}->{lives}++; + Games::PangZero::Music::PlaySound('bonuslife'); +} + +sub OnCollectedScore { + my ($bonus, $guy) = @_; + $guy->GiveScore(50000); + Games::PangZero::Music::PlaySound('score'); +} + +sub OnCollectedInvulnerability { + my ($bonus, $guy) = @_; + $guy->{invincible} = 500; +} + +1; diff --git a/lib/Games/PangZero.pm b/lib/Games/PangZero.pm new file mode 100644 index 0000000..e9e4dd6 --- /dev/null +++ b/lib/Games/PangZero.pm @@ -0,0 +1,406 @@ +package Games::PangZero; + +$Cheat = 0; +$VERSION = '1.4.1'; +$DataDir = ''; # Set it to a path to avoid autodetection (e.g. /opt/pangzero/data) + +=comment + +########################################################################## +# +# PANG ZERO +# Copyright (C) 2006 by UPi +# +########################################################################## + +This program is free software; you can redistribute it and//or modify +it under the terms of the GNU General Public License version 2, as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +########################################################################## +# TODO: +########################################################################## +* P4 Bonus probability is balldesc based. +* P3 Tour mode..? +* P5 Graphics and help for machine gun and power wire +* P5 Demo of beating the game at 'normal' difficulty +* P4 Even more forgiving collision detection (?) +* P4 Smooth numbers in the scoreboard +* P3 RotoZoomer smooth parameter to eliminate warning.. +* P3 Set DataDir with command line parameter. +* P2 Roll your own game +* P4 Reorg menu: MenuItem->Update(), MenuItem->Left(), MenuItem->Right(), ... + +Next release: +* Sound effect for matrix effect... +* Handle possible HST corruption if game exits while merging scores + + +########################################################################## +# QUICK GUIDE FOR WOULD-BE DEVELOPERS +########################################################################## + +' +This file contains the entire source code of Pang Zero. I know that this is +an odd design, but it works for me. You can split the file easily if you +want to. + +The parts of the file are organized like this: + +1. INITIALIZATION OF GLOBAL OBJECTS (configuration, balls, levels, etc) +2. HIGH SCORE TABLE +3. GAME OBJECT PACKAGES +4. UTILITY PACKAGES AND METHODS +5. GAMEBASE AND DESCENDENT PACKAGES (includes the menu) +6. "MAIN" PROGRAM LOOP +' +=cut + +use SDL ':init'; +use SDL::Surface; +use SDL::Palette; +use SDL::PixelFormat; +use SDL::Video; +use SDL::Event; +use SDL::Events; +use SDL::Color; +use SDL::Config; +use SDL::Cursor; +use SDL::GFX::Rotozoom; +use SDL::Joystick; +use SDL::Mouse; +use SDL::Image; +use SDLx::SFont; + +use Carp; + +# SDL objects + +use vars qw ( + $App $VERSION $RotoZoomer $Background $ScoreFont $MenuFont $GlossyFont + %BallSurfaces + $BorderSurface $WhiteBorderSurface $RedBorderSurface $BonusSurface $LevelIndicatorSurface $LevelIndicatorSurface2 + $WhiteHarpoonSurface + %Sounds $Mixer +); + +# Pang Zero variables and objects + +use vars qw ( + $DataDir $ScreenHeight $ScreenWidth $PhysicalScreenWidth $PhysicalScreenHeight $ScreenMargin + $SoundEnabled $MusicEnabled $FullScreen $ShowWebsite + $DeathBallsEnabled $EarthquakeBallsEnabled $WaterBallsEnabled $SeekerBallsEnabled $Slippery + @DifficultyLevels $DifficultyLevelIndex $DifficultyLevel + @WeaponDurations $WeaponDuration $WeaponDurationIndex + @GameObjects %GameEvents $GameSpeed $GamePause $Game + @Players @GuyImageFiles @GuyColors $NumGuys + @BallDesc %BallDesc @ChallengeLevels @PanicLevels + $UnicodeMode $LastUnicodeKey %Keys %Events %MenuEvents ); + + +use Games::PangZero::Globals; +use Games::PangZero::GameObject; +use Games::PangZero::Ball; +use Games::PangZero::BonusDrop; +use Games::PangZero::GameBase; +use Games::PangZero::PlayableGameBase; +use Games::PangZero::ChallengeGame; +use Games::PangZero::Config; +use Games::PangZero::DeadGuy; +use Games::PangZero::DeathBall; +use Games::PangZero::PanicGame; +use Games::PangZero::DemoGame; +use Games::PangZero::PlaybackGame; +use Games::PangZero::DemoPlaybackGame; +use Games::PangZero::RecordGame; +use Games::PangZero::DemoRecordGame; +use Games::PangZero::EarthquakeBall; +use Games::PangZero::FpsIndicator; +use Games::PangZero::FragileBall; +use Games::PangZero::GamePause; +use Games::PangZero::GameTimer; +use Games::PangZero::Graphics; +use Games::PangZero::Guy; +use Games::PangZero::Harpoon; +use Games::PangZero::HalfCutter; +use Games::PangZero::Hexa; +use Games::PangZero::Highscore; +use Games::PangZero::Joystick; +use Games::PangZero::MachineGun; +use Games::PangZero::Meltdown; +use Games::PangZero::Menu; +use Games::PangZero::MenuItem; +use Games::PangZero::Music; +use Games::PangZero::Palette; +use Games::PangZero::Pop; +use Games::PangZero::PowerWire; +use Games::PangZero::SeekerBall; +use Games::PangZero::SlowEffect; +use Games::PangZero::SuperBall; +use Games::PangZero::TutorialGame; +use Games::PangZero::UpsideDownBall; +use Games::PangZero::WaterBall; +use Games::PangZero::XmasBall; + +sub SaveScreenshot { + my $i = 0; + my $filename; + do { $filename = sprintf("screenshot%03d.bmp", $i); ++$i } while (-f $filename); + SDL::Video::save_BMP($App, $filename); +} + +sub Pause { + my $pausedSurface = SDL::Image::load("$DataDir/paused.png"); + my $event = SDL::Event->new(); + + SDL::Video::blit_surface($pausedSurface, SDL::Rect->new(0, 0, $pausedSurface->w, $pausedSurface->h), + $App, SDL::Rect->new(($PhysicalScreenWidth - $pausedSurface->w) / 2, $PhysicalScreenHeight / 2 - 100, 0, 0)); + $App->sync(); + $Keys = (); + $Events = (); + while (1) { # Paused, wait for keypress + SDL::Events::pump_events(); + SDL::Events::wait_event($event); + last if $event->type() == SDL_KEYDOWN and $event->key_sym == SDLK_p; + if ($event->type() == SDL_KEYDOWN and $event->key_sym == SDLK_ESCAPE) { + $Game->{abortgame} = 1; + last; + } + $Game->Exit() if $event->type() == SDL_QUIT; + } + SDL::Video::blit_surface($Background, SDL::Rect->new(0, 0, $App->w, $App->h), $App, SDL::Rect->new(0, 0, $App->w, $App->h)); + Games::PangZero::GameTimer::ResetTimer(); +} + +sub HandleEvents { + my ($readBothJoystickAxes) = @_; + my ($event, $type); + + $event = SDL::Event->new; + while (1) { + SDL::Events::pump_events(); + last unless SDL::Events::poll_event($event); + $type = $event->type(); + + if ($type == SDL_QUIT) { + $Game->Exit(); + } + elsif ($type == SDL_KEYDOWN) { + my $keypressed = $event->key_sym; + if ($keypressed == SDLK_ESCAPE) { + $Game->{abortgame} = 1; + } elsif ($keypressed == SDLK_F1) { + SaveScreenshot(); + } elsif ($keypressed == SDLK_p and not $UnicodeMode) { + Pause(); + } else { + $Keys{$keypressed} = 1; + $Events{$keypressed} = 1; + $MenuEvents{UP} = 1 if $keypressed == SDLK_UP(); + $MenuEvents{DOWN} = 1 if $keypressed == SDLK_DOWN(); + $MenuEvents{LEFT} = 1 if $keypressed == SDLK_LEFT(); + $MenuEvents{RIGHT} = 1 if $keypressed == SDLK_RIGHT(); + $MenuEvents{BUTTON} = 1 if $keypressed == SDLK_RETURN(); + $MenuEvents{BACKSP} = 1 if $keypressed == SDLK_BACKSPACE; + $LastUnicodeKey = $event->key_unicode() if $UnicodeMode; + } + } + elsif ($type == SDL_KEYUP) { + my $keypressed = $event->key_sym; + $Keys{$keypressed} = 0; + } + } + + Games::PangZero::Joystick::ReadJoystick($readBothJoystickAxes); +} + +sub DoMenu { + my $oldScreenHeight = $ScreenHeight; + my $oldScreenWidth = $ScreenWidth; + $ScreenWidth = $PhysicalScreenWidth - $ScreenMargin * 2; + $ScreenWidth = int($ScreenWidth / 32) * 32; + $Game = Games::PangZero::Menu->new(); + my $retval = $Game->Run(); + Games::PangZero::Config::SaveConfig(); + + $ScreenWidth = $oldScreenWidth; + $ScreenHeight = $oldScreenHeight; + + return $retval; +} + +sub DoDemo { + my $messages = $Game->{messages} = { + 1 => "Use harpoons to pop the balloons", + 160 => "Pop them, and they split in two", + 300 => "Pop them again and again", + 530 => "Popping the smallest ballons makes them disappear", + 630 => "The green Super Ball gives you a lot of free time", + 720 => "Use this time wisely!", + 1150 => "Making a lot of small balls is dangerous! Observe...", + 1600 => "Don't let the balloons touch you!", + 1708 => "Dying gives you some free time.", + 1900 => "So does shooting the flashing balloons.", + 2370 => "The yellow Super Ball destroys every balloon", + 2650 => "And now... THE SPECIAL BALL DEMO!", + 2950 => "The Bouncy Ball bounces twice as high as normal balls.", + 3620 => "See?", + 4222 => "The Hexa Ball is weightless and travels in a straight line.", + 4500 => "So does its offspring.", + 5210 => "The blue Water Ball splits every time it bounces.", + 5900 => "This can cause a tide of small balls!", + 6630 => "The Earthquake Ball will really shake you up.", + 7100 => "Its offspring is not as dangerous, but still annoying.", + 7800 => "Behold, the Death Ball. It cannot be killed!!!", + 8120 => "No, really, it can't! In fact, shooting it makes it multiply.", + 8220 => "If you avoid it for 20 secs, Deathballs will get bored and go away.", + 8320 => "Also, the yellow Super Ball will destroy the Deathballs for you.", + 8800 => "Shooting it too much will lead to the Deathball Meltdown.", + 9550 => "Last but not least: here's the Seeker Ball!", + 9900 => "This ball will stalk you forever.", + 10100 => "Whew! This concludes the Special Ball Demo. Have fun playing!", + }; + my $record = 0 x 23 . 1 x 18 . 0 x 19 . 2 x 7 . 0 x 31 . 4 x 1 . 0 x 44 . 2 x 43 . 0 x 7 . 4 x 1 . 0 x 22 . 1 x 10 . 0 x 17 . 2 x 38 . 0 x 16 . 2 x 22 . 0 x 42 . 4 x 1 . 0 x 54 . 1 x 43 . 0 x 2 . 4 x 1 . 0 x 28 . 1 x 27 . 0 x 8 . 4 x 1 . 0 x 98 . 2 x 19 . 0 x 11 . 4 x 1 . 0 x 27 . 1 x 24 . 5 x 1 . 1 x 1 . 0 x 17 . 1 x 9 . 0 x 2 . 4 x 1 . 0 x 51 . 2 x 19 . 0 x 14 . 4 x 1 . 0 x 48 . 1 x 14 . 0 x 2 . 4 x 1 . 0 x 51 . 1 x 8 . 0 x 25 . 4 x 1 . 0 x 49 . 2 x 25 . 0 x 3 . 4 x 1 . 0 x 53 . 1 x 12 . 0 x 9 . 4 x 1 . 0 x 101 . 1 x 9 . 0 x 4 . 4 x 1 . 0 x 68 . 1 x 7 . 5 x 1 . 0 x 75 . 2 x 14 . 0 x 2 . 4 x 1 . 0 x 64 . 2 x 38 . 0 x 3 . 4 x 1 . 0 x 13 . 2 x 13 . 0 x 25 . 2 x 25 . 0 x 5 . 4 x 1 . 0 x 54 . 4 x 1 . 0 x 69 . 1 x 3 . 0 x 15 . 4 x 1 . 0 x 19 . 2 x 17 . 0 x 94 . 2 x 28 . 0 x 27 . 2 x 52 . 0 x 22 . 4 x 1 . 0 x 34 . 1 x 28 . 0 x 34 . 1 x 29 . 0 x 24 . 4 x 1 . 0 x 80 . 1 x 15 . 0 x 116 . 1 x 10 . 5 x 1 . 1 x 1 . 0 x 808 . 2 x 35 . 0 x 16 . 4 x 1 . 0 x 55 . 1 x 46 . 5 x 1 . 1 x 2 . 0 x 368 . 8 x 1 . 0 x 487 . 1 x 27 . 0 x 48 . 2 x 8 . 6 x 1 . 2 x 7 . 0 x 7 . 2 x 18 . 6 x 1 . 2 x 11 . 0 x 119 . 1 x 1 . 0 x 167 . 8 x 1 . 0 x 1177 . 2 x 24 . 0 x 121 . 2 x 22 . 0 x 2 . 4 x 1 . 0 x 31 . 2 x 15 . 0 x 9 . 2 x 4 . 6 x 1 . 2 x 5 . 0 x 8 . 2 x 10 . 0 x 69 . 8 x 1 . 0 x 338 . 1 x 87 . 0 x 152 . 2 x 52 . 0 x 112 . 1 x 27 . 0 x 2 . 4 x 1 . 0 x 71 . 1 x 41 . 0 x 4 . 4 x 1 . 0 x 65 . 2 x 24 . 0 x 209 . 8 x 1 . 0 x 579 . 1 x 3 . 0 x 13 . 2 x 3 . 0 x 14 . 4 x 1 . 0 x 58 . 2 x 28 . 0 x 9 . 4 x 1 . 0 x 93 . 2 x 37 . 0 x 26 . 2 x 11 . 0 x 22 . 2 x 9 . 6 x 1 . 2 x 6 . 6 x 1 . 2 x 7 . 6 x 1 . 2 x 5 . 6 x 1 . 2 x 7 . 6 x 1 . 2 x 16 . 6 x 1 . 2 x 9 . 6 x 1 . 2 x 20 . 1 x 7 . 0 x 21 . 2 x 13 . 1 x 3 . 5 x 1 . 1 x 8 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 35 . 0 x 6 . 5 x 1 . 1 x 6 . 0 x 11 . 2 x 12 . 6 x 1 . 2 x 8 . 6 x 1 . 1 x 6 . 5 x 1 . 1 x 3 . 0 x 3 . 4 x 1 . 1 x 3 . 0 x 3 . 5 x 1 . 1 x 4 . 0 x 15 . 1 x 2 . 5 x 1 . 1 x 4 . 0 x 4 . 5 x 1 . 1 x 7 . 5 x 1 . 1 x 4 . 0 x 5 . 1 x 6 . 0 x 2 . 4 x 1 . 1 x 4 . 0 x 4 . 4 x 1 . 0 x 3 . 1 x 4 . 0 x 3 . 4 x 1 . 0 x 10 . 2 x 14 . 6 x 1 . 2 x 2 . 1 x 5 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 5 . 5 x 1 . 1 x 2 . 0 x 3 . 4 x 1 . 1 x 3 . 0 x 3 . 4 x 1 . 1 x 3 . 0 x 2 . 1 x 2 . 5 x 1 . 1 x 4 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 7 . 5 x 1 . 1 x 7 . 0 x 2 . 2 x 4 . 6 x 1 . 2 x 4 . 0 x 2 . 2 x 2 . 6 x 1 . 2 x 6 . 6 x 1 . 2 x 7 . 1 x 5 . 5 x 1 . 1 x 1 . 0 x 5 . 2 x 6 . 6 x 1 . 2 x 2 . 0 x 4 . 1 x 3 . 5 x 1 . 1 x 1 . 0 x 8 . 2 x 4 . 6 x 1 . 2 x 1 . 0 x 3 . 1 x 4 . 0 x 7 . 2 x 6 . 6 x 1 . 2 x 8 . 6 x 1 . 2 x 6 . 6 x 1 . 2 x 3 . 0 x 3 . 1 x 3 . 0 x 10 . 2 x 7 . 0 x 2 . 1 x 1 . 5 x 1 . 1 x 5 . 0 x 2 . 4 x 1 . 1 x 2 . 0 x 4 . 4 x 1 . 0 x 2 . 1 x 2 . 0 x 3 . 1 x 1 . 5 x 1 . 1 x 5 . 5 x 1 . 1 x 3 . 0 x 4 . 5 x 1 . 1 x 1 . 0 x 4 . 4 x 1 . 1 x 2 . 0 x 4 . 4 x 1 . 1 x 1 . 0 x 6 . 4 x 1 . 1 x 1 . 0 x 5 . 1 x 1 . 5 x 1 . 1 x 2 . 0 x 3 . 1 x 1 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 7 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 7 . 0 x 12 . 2 x 7 . 0 x 2 . 4 x 1 . 2 x 2 . 0 x 4 . 4 x 1 . 0 x 135 . 8 x 1 . 0 x 252 . 1 x 57 . 0 x 199 . 2 x 37 . 0 x 3 . 1 x 1 . 5 x 1 . 1 x 29 . 0 x 21 . 1 x 30 . 0 x 37 . 4 x 1 . 0 x 77 . 1 x 17 . 0 x 4 . 2 x 126 . 3 x 1 . 1 x 52 . 5 x 1 . 1 x 64 . 0 x 39 . 8 x 1 . 0 x 140; + my $rand = [2199.02,1.12,0.11,1.24,0.11,1.21,0.33,0.19,0.16,0.12,0.07,0.28,0.68]; + + Games::PangZero::Config::SaveConfig(); + $Game = Games::PangZero::DemoPlaybackGame->new( 1, 3, $record, $rand, $messages ); + $Game->Run(); + Games::PangZero::Config::LoadConfig(); + $Game->RestoreGameSettings(); +} + +sub DoRecordDemo { + my ($numguys, $difficulty) = ($NumGuys, $DifficultyLevelIndex); + + $NumGuys = 1; + Games::PangZero::Config::SetDifficultyLevel(3); + $Game = Games::PangZero::DemoRecordGame->new(); + $Game->Run(); + print "\n\$record = '", $Game->{record}, "';\n"; + print "\$rand = [", join( ', ', @{$Game->{rand}} ), "];\n\n"; + $NumGuys = $numguys; + Games::PangZero::Config::SetDifficultyLevel($difficulty); +} + + +########################################################################## +# MAIN PROGRAM STARTS HERE +########################################################################## + +sub Initialize { + + eval { SDL::init(SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) }; + die "Unable to initialize SDL: $@" if $@; + + Games::PangZero::Config::FindDataDir(); + Games::PangZero::Config::LoadConfig(); + print "Data directory is at '$DataDir'\n"; + my $sdlFlags; + if (Games::PangZero::Config::IsMicrosoftWindows()) { + $sdlFlags = SDL_ANYFORMAT; + } else { + if ($Games::PangZero::FullScreen) { + $sdlFlags = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | SDL_ANYFORMAT | SDL_FULLSCREEN; + } else { + $sdlFlags = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | SDL_ANYFORMAT; + } + } + + ($PhysicalScreenWidth, $PhysicalScreenHeight) = Games::PangZero::Graphics::FindVideoMode(); + + my $icon = SDL::Video::load_BMP("$DataDir/icon.bmp"); + SDL::Video::set_color_key($icon, SDL_SRCCOLORKEY, SDL::Color->new(0, 255, 0)); + SDL::Video::wm_set_icon($icon); + $App = SDL::Video::set_video_mode($PhysicalScreenWidth, + $PhysicalScreenHeight, + 32, $sdlFlags); + SDL::Video::wm_set_caption("Pang Zero $VERSION", "Pang Zero $VERSION"); + SDL::Mouse::show_cursor(0); + + $Background = SDL::Surface->new( Games::PangZero::Config::IsMicrosoftWindows() ? SDL_SWSURFACE() : SDL_HWSURFACE(), $App->w, $App->h, 16); + $Background = SDL::Video::display_format($Background); + $ScoreFont = SDLx::SFont->new("$DataDir/brandybun3.png"); + $MenuFont = SDLx::SFont->new("$DataDir/font2.png"); + $GlossyFont = SDLx::SFont->new("$DataDir/glossyfont.png"); + + Games::PangZero::Graphics::LoadSurfaces(); + Games::PangZero::Music::LoadSounds(); + Games::PangZero::Joystick::InitJoystick(); +} + +sub MainLoop { + my $menuResult = DoMenu(); + if ($menuResult eq 'demo') { + DoDemo(); + } + + #$Game = Games::PangZero::DemoRecordGame->new(); + $Game = ($menuResult eq 'challenge') + ? Games::PangZero::ChallengeGame->new() + : Games::PangZero::PanicGame->new(); + @Games::PangZero::Highscore::UnsavedHighScores = (); + $Game->Run(); + + bless $Game, 'Games::PangZero::Menu'; + $Games::PangZero::MenuFont->use(); + Games::PangZero::Highscore::MergeUnsavedHighScores($menuResult eq 'challenge' ? 'Cha' : 'Pan'); + + return; + + my ($filename, $i) = ('', 1); + do { $filename = sprintf("record%03d.txt", $i); ++$i } while (-f $filename); + open RECORD, ">$filename"; + print RECORD "NumGuys = $NumGuys;\nDifficultyLevelIndex = $DifficultyLevelIndex;\nrecord = '$Game->{record}';\n", + "DeathBallsEnabled = $DeathBallsEnabled;\nEarthquakeBallsEnabled = $EarthquakeBallsEnabled;\n", + "WaterBallsEnabled = $WaterBallsEnabled;\nSeekerBallsEnabled = $SeekerBallsEnabled;\n", + 'rand = [', join(',', @{$Game->{rand}}), "];\n\n"; + close RECORD; + + $Game = Games::PangZero::DemoPlaybackGame->new($NumGuys, $DifficultyLevelIndex, $Game->{record}, $Game->{rand}, {}); + $Game->Run(); + $Game->RestoreGameSettings(); +} + +sub ShowErrorMessage { + my ($message) = @_; + print "Pang Zero $VERSION died:\n$message\n"; +} + +sub ShowWebPage { + my ($url) = @_; + + return if $ENV{PANGZERO_TEST}; + + if (Games::PangZero::Config::IsMicrosoftWindows()) { + my $ws = "$DataDir/website.html"; + $ws =~ s/\//\\\\/g; + exec 'cmd', '/c', $ws; + exit; + } elsif ($ENV{'DISPLAY'}) { + my @tryCommands = ( + "which gnome-open > /dev/null 2>&1 && (gnome-open $url&)", + "which mozilla-firefox > /dev/null 2>&1 && (mozilla-firefox $url&)", + "which firefox > /dev/null 2>&1 && (firefox $url&)", + "which mozilla > /dev/null 2>&1 && (mozilla $url&)", + "which konqueror > /dev/null 2>&1 && (konqueror $url&)", + ); + foreach (@tryCommands) { + return if system($_) == 0; + } + } else { + print "Visit $url for more info about Pang Zero $Games::PangZero::VERSION\n"; + } +} + +1; diff --git a/t/00-run.t b/t/00-run.t new file mode 100644 index 0000000..ded6d8c --- /dev/null +++ b/t/00-run.t @@ -0,0 +1,16 @@ +use strict; +use warnings; +use Test::More; +use Games::PangZero; + +$ENV{PANGZERO_TEST} = 1; + +$ENV{SDL_VIDEODRIVER} = 'dummy'; +Games::PangZero::Initialize(); +$Games::PangZero::Game = Games::PangZero::PanicGame->new(); +@Games::PangZero::Highscore::UnsavedHighScores = (); +$Games::PangZero::Game->Run(); + +delete $ENV{SDL_VIDEODRIVER}; +pass('Game Ran!!'); +done_testing();