1. clach04
  2. battle_pong

Commits

clach04  committed 837fb67 Draft

Import (and cleanup) of http://dl.openhandhelds.org/cgi-bin/dingoo.cgi?0,0,0,0,27,359 by icculus, ported by Warpedflash and z_man3007

  • Participants
  • Branches default

Comments (0)

Files changed (34)

File AUTHORS

View file
+
+Programming:
+Dana Olson (dolson) <dana@mandrakeusers.org>
+
+Artwork:
+Dana Olson (dolson) <dana@mandrakeusers.org>
+
+Sound:
+Dana Olson (dolson) <dana@mandrakeusers.org>
+
+Music:
+Machinae Supremacy (www.machinaesupremacy.com) <contact@machinaesupremacy.com>
+
+Alpha/Beta Testers:
+Dan McCombs (overridex) <overridex@punkass.com>
+Palle Raabjerg (PRaabjerg) <shark@post.cybercity.dk>
+
+Ported by Rowan Murphy <Warpedflash>

File Battle Pong.dsp

View file
+# Microsoft Developer Studio Project File - Name="Battle Pong" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Battle Pong - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "Battle Pong.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "Battle Pong.mak" CFG="Battle Pong - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "Battle Pong - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "Battle Pong - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "Battle Pong - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF  "$(CFG)" == "Battle Pong - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c
+# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib sdl.lib sdlmain.lib sdl_image.lib sdl_ttf.lib sdl_mixer.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF 
+
+# Begin Target
+
+# Name "Battle Pong - Win32 Release"
+# Name "Battle Pong - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\ball.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\collide.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\game.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\init.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\menu.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\player.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\randgen.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\sound.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\ball.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\collide.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\game.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\gamedefs.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\init.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\menu.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\player.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\randgen.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sound.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project

File Battle Pong.dsw

View file
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "Battle Pong"=".\Battle Pong.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+

File Battle Pong.prj

View file
+<!DOCTYPE kate_project>
+<kate_project version="1" name="project_name_here" >
+ <file path="/home/dana/Documents/CPP/battlepong/gamedefs.h" />
+ <file path="/home/dana/Documents/CPP/battlepong/randgen.h" />
+ <file path="/home/dana/Documents/CPP/battlepong/randgen.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/player.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/player.h" />
+ <file path="/home/dana/Documents/CPP/battlepong/Makefile" />
+ <file path="/home/dana/Documents/CPP/battlepong/init.h" />
+ <file path="/home/dana/Documents/CPP/battlepong/game.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/menu.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/ball.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/init.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/ball.h" />
+ <file path="/home/dana/Documents/CPP/battlepong/menu.h" />
+ <file path="/home/dana/Documents/CPP/battlepong/main.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/game.h" />
+ <file path="/home/dana/Documents/CPP/battlepong/sound.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/sound.h" />
+ <file path="/home/dana/Documents/CPP/battlepong/collide.cpp" />
+ <file path="/home/dana/Documents/CPP/battlepong/collide.h" />
+</kate_project>

File GPL

View file
+		    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.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    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.
+
+  <signature of Ty Coon>, 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.

File LICENSE

View file
+Battle Pong - a pong game with some extra features
+Copyright (C) 2003 Dana Olson
+
+    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
+
+For the full text of the GNU Public License, see the GPL file included in
+this archive.
+
+January 6th, 2003

File Makefile

View file
+TOOLCHAINDIR := /dingux
+BINPATH := $(TOOLCHAINDIR)/bin
+LIBPATH := $(TOOLCHAINDIR)/lib
+
+INCLUDES := -I${TOOLCHAINDIR}/mipsel-linux-uclibc/include/SDL
+
+ARCH	:= mipsel-linux-uclibc-
+CC		:= ${BINPATH}/$(ARCH)g++
+
+CFLAGS  := -O2 -Wall $(INCLUDES) $(shell $(BINPATH)/sdl-config --cflags)
+LDFLAGS := -O2 -Wall $(shell $(BINPATH)/sdl-config --libs) -lSDL_gfx -lSDL_image
+
+
+LIBS=-lm `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer
+OBJS=sound.o collide.o ball.o game.o menu.o player.o randgen.o init.o main.o
+OUTPUT=battlepong.dge
+
+default: clean all
+
+PHONY: clean run default
+
+clean:
+	@echo Cleaning...
+	rm -f $(OUTPUT) $(OBJS)
+	rm -f *~
+	@echo Done.
+
+run: clean all
+	@echo Runing...
+	./$(OUTPUT)
+
+all: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) -o $(OUTPUT) $(LIBS)
+
+main.o:	 main.cpp gamedefs.h randgen.h init.h menu.h game.h
+	$(CC) $(CFLAGS) -c main.cpp
+
+sound.o: sound.cpp sound.h
+	$(CC) $(CFLAGS) -c sound.cpp
+
+randgen.o: randgen.cpp randgen.h
+	$(CC) $(CFLAGS) -c randgen.cpp
+
+collide.o: collide.cpp collide.h
+	$(CC) $(CFLAGS) -c collide.cpp
+
+game.o: game.cpp game.h gamedefs.h init.h
+	$(CC) $(CFLAGS) -c game.cpp
+
+menu.o: menu.cpp menu.h gamedefs.h init.h
+	$(CC) $(CFLAGS) -c menu.cpp
+
+init.o: init.cpp init.h gamedefs.h randgen.h player.h ball.h
+	$(CC) $(CFLAGS) -c init.cpp
+
+player.o: player.cpp player.h gamedefs.h
+	$(CC) $(CFLAGS) -c player.cpp
+
+ball.o: ball.cpp ball.h gamedefs.h randgen.h collide.h player.h
+	$(CC) $(CFLAGS) -c ball.cpp

File README

View file
+---------------
+- Battle Pong -
+---------------
+Dana Olson
+http://battlepong.sourceforge.net/
+
+Beta 3 Readme file
+
+Licensed under the GNU Public License
+Read LICENSE for more details.
+
+
+Making it run:
+--------------
+
+You've obviously extracted the archive and you are reading this
+file, so I'll skip that step.
+
+Next thing to do is to edit the file gamedefs.h.
+
+There is now keyboard support in Battle Pong. You have to define the keys
+at compile time, and the keyboard support works in addition to the game pad
+support, so you can play two players with no game pads, one game pad, or
+two game pads. If you wish to enable keyboard support, find the line that
+says ENABLE_KEYBOARD and set that to ENABLE_KEYBOARD 1. If you wish to
+disable keyboard support, set it to say ENABLE_KEYBOARD 0.
+
+You can then edit the keys that you would use for the players. The defaults
+are the preferred keys, but some people (laptop users in particular) may
+not have a keypad to use, so they would want to redefine the keys for
+player two.
+
+Next, you will have to decide which you would like to use, a hat or an axis on
+your game pad. If you want to use a hat, or on some game pads, the directional pad,
+set the line that says USE_HAT to 1. If you want to use an axis, set it to
+say USE_HAT 0.
+
+Next, find the line that says PADAXIS and set it to the hat number you would
+like to use, starting at 0, or the axis on the game pad you would like to use.
+
+Note that sometimes, the same game pad will use a particular piece of the pad
+as either a hat or an axis, depending on the operating system you are using,
+and what the driver is set up to use it as.
+
+For example: To use the directional pad of the Interact Hammerhead FX game pad
+under Linux, you would set USE_HAT to 0 and PADAXIS to 5. Under Windows, with
+the latest drivers from Interact, you would have to set USE_HAT to 1 and set
+PADAXIS to 0.
+
+If you are unsure, you can try the default settings of USE_HAT 0 and PADAXIS 1.
+This usually works for most game pads.
+
+If you don't have a game pad, you can just leave the default settings for USE_HAT
+and for PADAXIS.
+
+Now find the line that says WIN32_VERSION 0. If you are compiling under Windows,
+set this to say WIN32_VERSION 1.
+
+If the line ICEBOX_ONLY is 1, then change it to ICEBOX_ONLY 0.
+
+Next thing to do is to go into the snd directory and execute the getmusic.sh
+script:
+
+cd snd/
+sh getmusic.sh
+
+This will download two OGG files, which you need for the sound track. If
+you are using Windows, you'll have to get the OGG files yourself and
+rename them appropriately. Note that they will soon be available for download
+directly from our website.
+
+Alternately, you can use your own files, just so long as you create the
+proper symlinks in this directory.
+
+If you're using Windows, open up the Battle Pong project file in Visual C++
+and compile it like a normal program, otherwise, if you're in Linux, type
+cd .. to go back to the main directory.
+
+Type in make and hit enter to compile and run the game.
+
+If it fails, you're probably missing a library. You'll need SDL, SDL_ttf,
+SDL_image, and SDL_mixer, plus any libraries that they require. Look at
+http://www.libsdl.org/ for the necessary files.
+
+
+Controls:
+---------
+
+Navigate the menu using the game pad, and press button 1 to select your
+option. If you are using keyboard support, navigate up with the A key,
+and navigate down with the Z key. Make your selections with the X key.
+
+Use the game pad to move the player up and down. If you are using keyboard
+support, player one moves up with the A key, and moves down with the Z key.
+Player two moves up with the 4 on the keypad, and moves down with the 1 on
+the keypad by default.
+
+When the screen says "Faceoff!", press button two on the gamepad as rapidly as
+you can, so that you can win the faceoff. If keyboard support is enabled,
+player one should use the C key, and player two use the 3 on the keypad to
+do the faceoff.
+
+Eventually, button one will shoot freeze missiles, but they aren't in Battle
+Pong as of yet. With keyboard support enabled, player one would shoot with
+the X key, and player two would use the 2 on the keypad.
+
+To quit out of a game, press the last button on your gamepad, or just wait until
+you or your opponent hits 5 points. You can also press ESC on the keyboard,
+assuming you have keyboard support enabled.

File ball.cpp

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#include "ball.h"
+
+Ball::Ball()
+{
+    xSpeed = 0;
+    ySpeed = 0;
+    pause = 3;
+    resetBall(3);
+}
+
+Ball::~Ball()
+{
+}
+
+void Ball::setWorldPos(Sint16 x, Sint16 y)
+{
+    location.x = x;
+    location.y = y;
+}
+
+int Ball::move(float scaleIt)
+{
+  pause -= (scaleIt/20.0);
+  if (pause > 0) { return 0; } /* This allows the ball to freeze for a while */
+
+  location.x+=Sint16(xSpeed * scaleIt);
+  location.y+=Sint16(ySpeed * scaleIt);
+
+  if (location.x<=0-location.w)
+  {
+    resetBall(2);
+    //printf("Score on player 1\n");
+    return 2; /* Player 2 scored a point */
+  }
+
+  if (location.x>SCREEN_WIDE+location.w)
+  {
+    resetBall(2);
+    //printf("Score on player 2\n");
+    return 1; /* Player 1 scored a point */
+  }
+
+  if (location.y < SCR_TOP) { bounceY(SCR_TOP); return -1; }
+  if (location.y > (SCR_BOT-location.h-5)) { bounceY(SCR_BOT-location.h-5); return -1; }
+
+return 0;
+}
+
+int Ball::isPaused()
+{
+  if (pause > 0) { return (int)pause+1; }
+return 0;
+}
+
+void Ball::resetBall(int delay)
+{
+  /* Initialize the position of the pong ball */
+  setWorldPos((SCREEN_WIDE/2)-(sprDims.w/2),(SCREEN_HIGH/2)-(sprDims.h/2));
+
+  /* Reset the speeds */
+  setSpeed(BSPEEDMAX,BSPEEDMAX);
+
+  /* Keep it still for a few seconds */
+  pause = delay;
+}
+
+void Ball::bounceX(int offset)
+{
+  xSpeed=-xSpeed;
+  location.x=offset;
+  /* Set a random y speed */
+  ySpeed=getRandom(BSPEEDMAX);
+}
+
+void Ball::bounceY(int offset)
+{
+  ySpeed=-ySpeed;
+  location.y=offset;
+}
+
+void Ball::setSpeed(double x, double y)
+{
+  xSpeed = x;
+  ySpeed = y;
+}
+

File ball.h

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#ifndef _BP_BALL_H_
+#define _BP_BALL_H_
+
+#include <math.h>
+#include "randgen.h"
+#include "player.h"
+
+class Ball
+{
+public:
+    Ball();
+    ~Ball();
+
+    void setWorldPos(Sint16, Sint16);
+    int move(float);
+    void setSpeed(double, double);
+    void bounceX(int);
+    void bounceY(int);
+    void resetBall(int);
+    int isPaused();
+
+    SDL_Rect sprDims;  /* dimensions of ball sprite                     */
+    SDL_Rect location; /* location of ball                              */
+    double xSpeed;     /* this is a double because it can be a fraction */
+    double ySpeed;     /* this is a double because it can be a fraction */
+
+
+protected:
+    double pause;  /* this is the time to delay the ball */
+};
+
+
+#endif

File battlepong.png

Added
New image

File collide.cpp

View file
+#include "collide.h"
+
+/* Checks centerpoint of box2 to see if it's in box1 */
+int collisionDetectPIR(SDL_Rect box1, SDL_Rect box2)
+{
+  int midx=box2.x+(box2.w/2);
+  int midy=box2.y+(box2.h/2);
+
+  if ((midx>box1.x)&&(midx<box1.x+box1.w)&&(midy>box1.y)&&(midy<box1.y+box1.h)) return 1;
+
+return 0;
+}
+
+/* Checks if two rectangles overlap */
+int collisionDetectRIR(SDL_Rect box1, SDL_Rect box2)
+{
+  if ((box2.x>box1.x)&&((box1.x+box1.w)>box2.x))
+    if ((box2.y>box1.y)&&((box1.y+box1.h)>box2.y)) return 1;
+
+return 0;
+}
+
+/* Checks if two rectangles overlap w/ X and W modifiers for box1 */
+int collisionDetectRIRmW(SDL_Rect box1, SDL_Rect box2, int xMod, int wMod)
+{
+  box1.x += xMod; box1.w += wMod; /* Apply modifiers */
+  if ((box2.x>box1.x)&&((box1.x+box1.w)>box2.x))
+    if ((box2.y>box1.y)&&((box1.y+box1.h)>box2.y)) return 1;
+
+return 0;
+}

File collide.h

View file
+#ifndef _BP_COLLIDE_H_
+#define _BP_COLLIDE_H_
+
+#include <stdlib.h>
+#include "SDL.h"
+
+int collisionDetectPIR(SDL_Rect box1, SDL_Rect box2);
+int collisionDetectRIR(SDL_Rect box1, SDL_Rect box2);
+int collisionDetectRIRmW(SDL_Rect box1, SDL_Rect box2, int xMod, int wMod);
+
+#endif

File game.cpp

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                                            */
+/* For more info, read the LICENSE file                             */
+
+#include "game.h"
+
+SDL_Surface *sprites;
+SDL_Surface *bgGame;
+SND_Data hitSound, wallSound;
+int resetGame(1);
+
+void startGame()
+{
+    if (loadImages() != 0) {
+        printf("Error loading images. Aborting.\n");
+        exit(1);
+    }
+
+    if (loadSounds() != 0) {
+        printf("Error loading sounds. Aborting.\n");
+        exit(1);
+    }
+
+    quitFlag = 0;
+
+    /* Reset all game data */
+    resetAll();
+
+    while (quitFlag==0) /* Main Game Loop */
+    {
+        updateInputs(); /* Update the input devices                                                                     */
+        updateState();    /* This takes care of calling the movement routines and so on */
+        checkWinConditions(); /* Duh */
+        drawScreen();     /* This takes care of drawing everything onto the screen.         */
+    } /* End Main Game Loop */
+
+    /* If someone won the game, do the gameover screen */
+    if (quitFlag==1) {
+        /* Show the game over screen now */
+        drawGameOver(ONE);
+    } else if (quitFlag==2) {
+        /* Show the game over screen now */
+        drawGameOver(TWO);
+    } else { Mix_FadeOutMusic(1000); } /* Fade music for one second */
+
+    /* Finish playing last sound */
+    while(Mix_Playing(-1)>0) { SDL_Delay(100); }
+
+    /* Free all sound buffers */
+    Mix_FreeChunk(hitSound.sample); hitSound.sample = NULL;
+    Mix_FreeChunk(wallSound.sample); wallSound.sample = NULL;
+
+    /* Free all the surfaces when we're done */
+    SDL_FreeSurface(scoreText[ONE]);
+    SDL_FreeSurface(scoreText[TWO]);
+    SDL_FreeSurface(bgGame);
+    SDL_FreeSurface(sprites);
+}
+
+void resetAll()
+{
+    Players[ONE].reset();
+    Players[TWO].reset();
+    resetGame=1; /* This fixes the TimeScaler problem I was having in updateState() */
+    initPlayers(); /* This will reset the pong ball and all dimensions of player/ball sprites */
+}
+
+void checkWinConditions()
+{
+    if (Players[ONE].getScore()>=MAXSCORE) { quitFlag=1; }
+    if (Players[TWO].getScore()>=MAXSCORE) { quitFlag=2; }
+}
+
+void updateInputs()
+{
+    Uint8 *keys;
+    /* Someone on IRC told me to do this because of memory leaks */
+    { SDL_Event ev; while(SDL_PollEvent(&ev)); }
+
+    SDL_PumpEvents();
+    keys = SDL_GetKeyState(NULL);
+
+/* Keyboard movement */
+    if (keys[KEY_P1_DOWN]) {
+	Players[ONE].setSpeed(PSPEEDMAX);}
+    else if (keys[KEY_P1_UP]){
+	Players[ONE].setSpeed(-PSPEEDMAX);}
+    else {
+	Players[ONE].setSpeed(0);}
+
+	if(numPlayers==2){
+		if (keys[KEY_P2_DOWN]) {
+		Players[TWO].setSpeed(PSPEEDMAX);}
+		else if (keys[KEY_P2_UP]) {
+		Players[TWO].setSpeed(-PSPEEDMAX);}
+		else {
+		Players[TWO].setSpeed(0);}
+	}
+	
+	else if(numPlayers==1){
+	aiUpdate(); /* Unless it's a single-player game, in which case, the AI handles it */
+	}
+
+    if (PongBall.isPaused())
+    {
+		if (getRandom(2)>2) { PongBall.xSpeed=-BSPEEDMAX; } /* Random chance for AI to win draw */
+		if (getRandom(2)==2) { PongBall.ySpeed=-BSPEEDMAX; }
+    }
+
+    if (keys[KEY_EXIT]) { quitFlag=-1; }
+}
+
+void aiUpdate()
+{
+    int midBall = PongBall.location.y+PongBall.location.h/2;
+    int midPaddle = Players[TWO].location.y+Players[TWO].location.h/2;
+    int diff=abs(midPaddle-midBall);
+    int movement=(PSPEEDMAX);
+
+    /* This should stop the shakey AI */
+    if (diff<PSPEEDMAX) { movement=diff; }
+
+    if (PongBall.isPaused()) {
+        /* Center the paddle if the ball is stopped */
+        if ((SCREEN_HIGH/2)>midPaddle) { Players[TWO].setSpeed(movement); }
+        else if ((SCREEN_HIGH/2)<midPaddle) { Players[TWO].setSpeed(-movement); }
+        else { Players[TWO].setSpeed(0); }
+    } else {
+        /* Follow the ball as closely as possible */
+        if (midBall>midPaddle) { Players[TWO].setSpeed(movement); }
+        else if (midBall<midPaddle) { Players[TWO].setSpeed(-movement); }
+        else { Players[TWO].setSpeed(0); }
+    }
+}
+
+void updateState()
+{
+    /* for keeping track of timing */
+    static int lastTime(0);
+    int thisTime = SDL_GetTicks();
+
+    if (resetGame!=0) {    /* safety precaution */
+        lastTime = thisTime-30;
+        resetGame=0; /* Fixed the bug I had with the TimeScaler */
+    }
+
+    thisTime = SDL_GetTicks();
+    timeScaler = (float)(thisTime-lastTime)/60;
+
+    Players[ONE].move(timeScaler);
+    Players[TWO].move(timeScaler);
+    int result=PongBall.move(timeScaler);
+    if (result>0) {
+        Players[result-1].incScore();
+    } else if (result<0) {
+        if (playSound(&wallSound)!=0) { printf("Mix_PlayChannel: %s\n",Mix_GetError()); }
+    }
+
+    if (collisionDetectRIRmW(Players[ONE].location, PongBall.location, -PongBall.location.w, 0))
+    { PongBall.bounceX((int)Players[ONE].location.x+Players[ONE].location.w);
+        /* Set the angle then play the sound */
+        hitSound.angle=270;
+        if (playSound(&hitSound)!=0) { printf("Mix_PlayChannel: %s\n",Mix_GetError()); }
+    }
+
+    if (collisionDetectRIRmW(Players[TWO].location, PongBall.location, 0, PongBall.location.w))
+    { PongBall.bounceX((int)Players[TWO].location.x-PongBall.location.w);
+        /* Set the angle then play the sound */
+        hitSound.angle=90;
+        if (playSound(&hitSound)!=0) { printf("Mix_PlayChannel: %s\n",Mix_GetError()); }
+    }
+
+    lastTime = thisTime;
+}
+
+void drawScreen()
+{
+    drawBackground();
+    drawHUD();
+    drawPlayers();
+    drawBall();
+    if (PongBall.isPaused()) { drawFaceoff(); }
+    SDL_Flip(screen);
+}
+
+void drawFaceoff()
+{
+    if ((PongBall.isPaused()<=INITIALDELAY+1) && ((Players[ONE].getScore()<MAXSCORE)&&(Players[TWO].getScore()<MAXSCORE))) {
+        src.x=1; src.y=127; src.w=139; src.h=27;
+    } else {
+        src.x=142; src.y=127; src.w=83; src.h=27;
+    }
+    dest=src; dest.x=SCREEN_WIDE/2-dest.w/2; dest.y=SCREEN_HIGH-dest.h-2;
+    SDL_BlitSurface(sprites, &src, screen, &dest);
+}
+
+void drawBackground()
+{
+    src.x=0; src.y=0; src.w=bgGame->w; src.h=bgGame->h;
+    dest=src;
+    SDL_BlitSurface(bgGame, &src, screen, &src);
+}
+
+void drawHUD()
+{
+    char numVal[8];
+
+    /* Some guy on IRC said this would work - don't ask me */
+    sprintf(numVal, "%i", Players[ONE].getScore());
+    /* Print the text onto the surface now */
+    scoreText[ONE] = TTF_RenderText_Solid(font,numVal,txtClr);
+    dest.x = 112; dest.y = -1; dest.w = scoreText[ONE]->w; dest.h = scoreText[ONE]->h;
+    SDL_BlitSurface(scoreText[ONE],NULL,screen,&dest); /* Draw player one's score */
+
+    sprintf(numVal, "%i", Players[TWO].getScore());
+    /* Print the text onto the surface now */
+    scoreText[TWO] = TTF_RenderText_Solid(font,numVal,txtClr);
+    dest.x = SCREEN_WIDE-dest.x-scoreText[TWO]->w; dest.y = 0; dest.w = scoreText[TWO]->w; dest.h = scoreText[TWO]->h;
+    SDL_BlitSurface(scoreText[TWO],NULL,screen,&dest); /* Draw player two's score */
+}
+
+void drawPlayers()
+{
+    SDL_BlitSurface(sprites, &Players[ONE].sprDims, screen, &Players[ONE].location);
+    SDL_BlitSurface(sprites, &Players[TWO].sprDims, screen, &Players[TWO].location);
+}
+
+void drawBall()
+{
+    SDL_BlitSurface(sprites, &PongBall.sprDims, screen, &PongBall.location);
+}
+
+void drawGameOver(int playerNum)
+{
+    src.x=23; src.y=102; src.w=11; src.h=src.w; dest=src;
+    for(int x(0); x < SCREEN_WIDE; x+=src.w)
+    {
+        for (int y(0); y < SCREEN_HIGH; y+=src.h)
+        {
+            dest.x=x;dest.y=y;
+            SDL_BlitSurface(sprites, &src, screen, &dest);
+        }
+    }
+
+    src.x=49; src.y=1; src.w=349; src.h=27; dest=src;
+    dest.x=SCREEN_WIDE/2-dest.w/2; dest.y=SCREEN_HIGH/2-dest.h-5;
+    SDL_BlitSurface(sprites, &src, screen, &dest);
+
+    dest.h=src.h; src.y=58-(playerNum*(src.h+1));
+    dest.y=SCREEN_HIGH/2+dest.h+5;
+    SDL_BlitSurface(sprites, &src, screen, &dest);
+
+    SDL_Flip(screen);
+    SDL_Delay(5000);
+}
+
+int loadImages()
+{
+    /* Load the background PNG file */
+    bgGame = IMG_Load("img/game.png");
+    if (bgGame == NULL) {
+        printf("Unable to load a necessary PNG file.\n");
+        return 1;
+    }
+
+    /* Load the sprites PNG file */
+    sprites = IMG_Load("img/game-sprites.png");
+    if (sprites == NULL) {
+        printf("Unable to load a necessary PNG file.\n");
+        return 1;
+    }
+return 0;
+}
+
+int loadSounds()
+{
+    /* Load the sounds up into the buffers */
+    hitSound.sample=Mix_LoadWAV("snd/bounce.wav");
+    if(hitSound.sample == NULL) {
+        printf("Mix_LoadWAV error occurred: %s\n", Mix_GetError());
+        return 1;
+    }
+    hitSound.volume=255; hitSound.angle=0;
+    hitSound.distance=0; hitSound.channel=1;
+    hitSound.loops=0;
+
+    wallSound.sample=Mix_LoadWAV("snd/bounce.wav");
+    if(wallSound.sample == NULL) {
+        printf("Mix_LoadWAV error occurred: %s\n", Mix_GetError());
+        return 1;
+    }
+
+    wallSound.volume=255; wallSound.angle=0;
+    wallSound.distance=0; wallSound.channel=2;
+    wallSound.loops=0;
+
+return 0;
+}

File game.h

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#ifndef _BP_GAME_H_
+#define _BP_GAME_H_
+
+#include "SDL_image.h"
+#include "init.h"
+#include "collide.h"
+
+void startGame();
+
+void drawScreen();
+void drawFaceoff();
+void drawBackground();
+void drawHUD();
+void drawPlayers();
+void drawBall();
+void checkWinConditions();
+void drawGameOver(int);
+void updateState();
+void updateInputs();
+void aiUpdate();
+int loadImages();
+int loadSounds();
+void resetAll();
+
+#endif

File gamedefs.h

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#ifndef _BP_GAMEDEFS_H_
+#define _BP_GAMEDEFS_H_
+
+/* Enable quick and dirty keyboard support? */
+#define ENABLE_KEYBOARD 1
+
+/* if so, define the keys */
+  #define KEY_BTN1 SDLK_RETURN
+  #define KEY_BTN2 SDLK_TAB
+  #define KEY_EXIT SDLK_ESCAPE
+  #define KEY_P1_UP SDLK_UP
+  #define KEY_P1_DOWN SDLK_DOWN
+  #define KEY_P2_UP SDLK_SPACE
+  #define KEY_P2_DOWN SDLK_LALT
+
+/* Sound settings */
+#define STEREO 2
+#define MONO 1
+#define SND_FREQUENCY 44100
+#define SND_FORMAT 16
+#define SND_CHUNKSIZE 4096
+#define SND_NEXTCHAN -1
+#define SND_MAXCHANS 4
+#define SND_INFINITELOOP -1
+#define SND_NOLOOP 0
+#define SND_MUSIC_VOL 64
+
+/* We can use PI in our forumulas with this. */
+#define PI (3.141592654F)
+
+/* these are to use for the players */
+#define ONE 0
+#define TWO 1
+
+/* Paddle and ball speeds */
+#define PSPEEDMAX 11
+#define BSPEEDMAX 14
+
+/* Initial ball pause */
+#define INITIALDELAY 2
+
+/* End game after this score */
+#define MAXSCORE 5
+
+/* Number of different pong balls */
+#define DIFFBALLS 4
+
+/* Screen size */
+#define SCREEN_WIDE 320
+#define SCREEN_HIGH 240
+
+/* Screen depth */
+#define SCREEN_DEPTH 32
+
+/* Top and bottom screen limits */
+#define SCR_TOP 12
+#define SCR_BOT SCREEN_HIGH-6
+
+/* This is the font to use */
+#define FONT_NAME "img/hyperfont.ttf"
+
+#endif

File img/game-sprites.png

Added
New image

File img/game.png

Added
New image

File img/hyperfont.ttf

Binary file added.

File img/menu-opts.png

Added
New image

File img/menu.png

Added
New image

File init.cpp

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                                            */
+/* For more info, read the LICENSE file                             */
+
+#include "init.h"
+
+Player Players[2];
+Ball PongBall;
+int numPlayers(2);
+int maxPlayers(2);
+SDL_Surface *screen;
+SDL_Surface *scoreText[2];
+TTF_Font *font;
+SDL_Color txtClr = { 0x00, 0x00, 0x00, 0 };
+SDL_Rect src, dest;
+float timeScaler(1);
+int quitFlag;
+int ballType(0);
+
+int initGame()
+{
+        if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0) {
+                printf("Couldn't initialize SDL: %s\n", SDL_GetError());
+                return 1;
+        }
+
+        if (initSound() != 0) {
+            printf("Error during sound init.\n");
+            return 1;
+        }
+	
+	screen = SDL_SetVideoMode ( 320, 240, 0, SDL_SWSURFACE );
+	SDL_ShowCursor(SDL_DISABLE);
+
+        if (screen == NULL) {
+            printf("Unable to set video mode: %s\n",SDL_GetError());
+            return 1;
+        }
+
+        if (TTF_Init() < 0)
+        { printf("Error initializing TTF library. %s\n",SDL_GetError());
+            return 1;
+        }
+
+        font = TTF_OpenFont(FONT_NAME, 15);    //
+        if ( font == NULL )
+        { printf("Error loading font. %s\n", SDL_GetError());
+            return 1;
+        }
+
+	maxPlayers=1;
+	return 0;
+}
+
+void printVersion()
+{
+    SDL_version compileVersion;
+    SDL_VERSION(&compileVersion);
+    printf("Compiled with SDL version: %d.%d.%d\n",
+        compileVersion.major,
+        compileVersion.minor,
+        compileVersion.patch);
+}
+
+void initPlayers()
+{
+        /* Set up the dimensions of the player sprites */
+        Players[ONE].sprDims.x=1;    Players[ONE].sprDims.y=1; Players[ONE].sprDims.w=11; Players[ONE].sprDims.h=50;
+        Players[TWO].sprDims = Players[ONE].sprDims; Players[TWO].sprDims.x=25;
+
+        /* The width and height won't change */
+        Players[ONE].location.w=Players[ONE].sprDims.w; Players[ONE].location.h=Players[ONE].sprDims.h;
+        Players[TWO].location.w=Players[TWO].sprDims.w; Players[TWO].location.h=Players[TWO].sprDims.h;
+
+        /* Set the dimensions of the paddle surface for collision detection */
+        /* Try modifying the x and w coords for better collision detection??? */
+		Players[ONE].dims.x = 3; Players[ONE].dims.y = 6; Players[ONE].dims.w = 8; Players[ONE].dims.h = 39;
+		Players[TWO].dims = Players[ONE].dims; Players[ONE].dims.x = 27; Players[ONE].dims.y = 6;
+
+        /* Set the starting locations for the players */
+        Players[ONE].location.x=1;
+        Players[ONE].location.y=(SCREEN_HIGH/2)-(Players[ONE].sprDims.h/2);
+
+        Players[TWO].location.x=SCREEN_WIDE-Players[TWO].sprDims.w-2;
+        Players[TWO].location.y=(SCREEN_HIGH/2)-(Players[TWO].sprDims.h/2);
+
+        /* Set up the dimensions of the ball sprite */
+        PongBall.sprDims.x=1+(ballType*13); PongBall.sprDims.y=114; PongBall.sprDims.w=12; PongBall.sprDims.h=12;
+        PongBall.location.w=PongBall.sprDims.w; PongBall.location.h=PongBall.sprDims.h;
+
+        /* Initialize the position of the pong ball - MOVE TO SEPARATE RESET BALL FUNCTION */
+        PongBall.resetBall(INITIALDELAY+1);
+}
+
+void quitGame()
+{
+        Mix_CloseAudio();
+        SDL_Quit();
+        TTF_Quit();
+        printf("SDL, SDL_mixer, and TTF have been shut down.\n");
+}

File init.h

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#ifndef _BP_INIT_H_
+#define _BP_INIT_H_
+
+#include <stdlib.h>
+#include "SDL.h"
+#include "SDL_ttf.h"
+#include "randgen.h"
+#include "sound.h"
+#include "player.h"
+#include "ball.h"
+
+int initGame();
+void printVersion();
+void initPlayers();
+void quitGame();
+
+/* Global variables */
+extern Player Players[2];
+extern Ball PongBall;
+extern int numPlayers;
+extern int maxPlayers;
+extern SDL_Surface *screen;
+extern SDL_Surface *scoreText[2];
+extern TTF_Font *font;
+extern SDL_Color txtClr;
+extern SDL_Rect src, dest;
+extern SDL_Event event;
+extern float timeScaler;
+extern int quitFlag;
+extern int ballType;
+
+#endif

File main.cpp

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#include "SDL.h"
+#include <stdlib.h>
+#include "gamedefs.h"
+#include "randgen.h"
+#include "init.h"
+#include "menu.h"
+#include "game.h"
+
+int main(int argc, char *argv[])
+{
+    /* set up the random seed generator */
+    initRandom();
+
+    int result;
+    result = initGame();
+    if (result != 0) {
+		printf("Some errors occurred during initialization.\n");
+		return 1;
+    }
+
+    /* Start of super main loop */
+    while (numPlayers != 0)
+    {
+		showMenu(); /* Show menu, which sets numPlayers */
+		if (numPlayers != 0) { startGame(); } /* Start the game! */
+    } /* End the super main loop */
+
+    quitGame();
+
+    printf("Battle Pong is exiting normally.\n");
+    return 0;
+}

File menu.cpp

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#include "menu.h"
+
+SDL_Surface *bgMenu;
+SDL_Surface *menuOpts;
+
+int showMenu()
+{
+  printf("Showing menu now\n");
+
+  /* Load the background PNG file */
+  bgMenu = IMG_Load("img/menu.png");
+  if (bgMenu == NULL) {
+    printf("Unable to load a necessary PNG file.\n");
+    numPlayers = 0;
+    return 1;
+  }
+
+  /* Load the sprites PNG file */
+  menuOpts = IMG_Load("img/menu-opts.png");
+  if (menuOpts == NULL) {
+    printf("Unable to load a necessary PNG file.\n");
+    numPlayers = 0;
+    return 1;
+  }
+  
+  SND_Data menuSound;
+  menuSound.sample=Mix_LoadWAV("snd/menu-opt.wav");
+  if(menuSound.sample == NULL) {
+    printf("Unable to load a necessary sound file.\n");
+    numPlayers = 0;
+    return 1;
+  }
+    
+  menuSound.volume=255; menuSound.angle=0;
+  menuSound.distance=100; menuSound.channel=2;
+  menuSound.loops=0;
+
+  src.x=0;  src.y=0;  src.w=bgMenu->w;  src.h=bgMenu->h;
+  dest=src;
+
+  SDL_BlitSurface(bgMenu, &src, screen, &dest);
+
+  int optSel(0); /* Default option is the first one */
+
+  switchOption(optSel);
+
+  quitFlag = 0;
+  Uint8 *keys;
+  int lockFlagKb(1);
+  
+
+  while(quitFlag==0)
+  {
+    /* Someone on IRC told me to do this because of memory leaks */
+    { SDL_Event ev; while(SDL_PollEvent(&ev)); }
+
+    SDL_PumpEvents();
+    keys = SDL_GetKeyState(NULL);
+
+    if ((keys[KEY_BTN1])||(keys[SDLK_LCTRL]))
+    {
+      if (optSel==0) {
+        numPlayers=1;
+        quitFlag=1;
+      } else if (optSel==1) {
+        numPlayers=2;
+        quitFlag=1;
+      } else {
+        numPlayers=0;
+        quitFlag=1;
+      }
+      //PLAY A SOUND HERE???
+    }
+
+    if (keys[KEY_BTN2]) {
+      ballType++;
+      if (ballType>=DIFFBALLS) { ballType=0; }
+    }
+
+    if ((keys[KEY_P1_UP])||(keys[KEY_P1_DOWN]))
+    {
+      if (lockFlagKb==0)
+      {
+        lockFlagKb=1;
+        if (keys[KEY_P1_DOWN]) {
+          optSel++; if (optSel>2) { optSel=0; }
+        } else {
+            optSel--; if (optSel<0) { optSel=2; }
+        }
+        switchOption(optSel);
+        if (playSound(&menuSound)!=0) { printf("Mix_PlayChannel: %s\n",Mix_GetError()); }
+      }
+    } else { lockFlagKb=0; }
+
+    SDL_Flip(screen);
+  } /* End menu loop */
+
+  /* Finish playing last sound */
+  while(Mix_Playing(-1)>0) { SDL_Delay(100); }
+
+  /* Free up resources */
+  Mix_FreeChunk(menuSound.sample); menuSound.sample=NULL;
+  SDL_FreeSurface(bgMenu);
+  SDL_FreeSurface(menuOpts);
+  printf("Exiting menu.\n");
+
+return 0;
+}
+
+void switchOption(int option)
+{
+  /* x,y,h for the three source sprites, and then the
+     same for the destination surface.
+     w will always be menu_opts->w
+     [src][option][dim]                               */
+  int optDims[2][3][3]={{{0,0,16},{0,33,16},{0,66,menuOpts->h-66}},
+                        {{63,78,16},{63,111,16},{63,144,menuOpts->h-66}}};
+
+  SDL_BlitSurface(bgMenu, &dest, screen, &dest);
+
+  src.x=optDims[0][option][0];  src.y=optDims[0][option][1];  src.w=menuOpts->w;  src.h=optDims[0][option][2];
+  dest.x=optDims[1][option][0]; dest.y=optDims[1][option][1]; dest.w=menuOpts->w; dest.h=optDims[1][option][2];
+
+  SDL_BlitSurface(menuOpts, &src, screen, &dest);
+}

File menu.h

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#ifndef _BP_MENU_H_
+#define _BP_MENU_H_
+
+#include "SDL_image.h"
+#include "init.h"
+
+int showMenu();
+void switchOption(int);
+
+#endif

File player.cpp

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#include "player.h"
+
+Player::Player()
+{
+}
+
+Player::~Player()
+{
+}
+
+void Player::reset()
+{
+    speed = 0;
+    score = 0;
+}
+
+void Player::setWorldPos(Sint16 x, Sint16 y)
+{
+    location.x = x;
+    location.y = y;
+}
+
+int Player::getScore()
+{
+  return (int)score;
+}
+
+void Player::move(float scaleIt)
+{
+  /* Move the player's coordinates */
+  location.y+=Sint16(speed * scaleIt);
+
+  /* If the player hits the top, stop movement */
+  if (location.y+dims.y/2+2<=SCR_TOP)
+  {
+    setSpeed(0);
+    location.y=SCR_TOP-dims.y/2-2;
+  }
+
+  /* If the player hits the bottom, stop movement */
+  if (location.y>=SCR_BOT-sprDims.h+dims.y/2)
+  {
+    setSpeed(0);
+    location.y=SCR_BOT-sprDims.h+dims.y/2;
+  }
+}
+
+void Player::setSpeed(double i)
+{
+  speed = i;
+}
+
+void Player::incScore()
+{
+  score++;
+}
+

File player.h

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#ifndef _BP_PLAYER_H_
+#define _BP_PLAYER_H_
+
+#include <stdlib.h>
+#include "SDL.h"
+#include "gamedefs.h"
+
+class Player
+{
+public:
+    Player();
+    ~Player();
+
+    void reset();
+    void setWorldPos(Sint16, Sint16);
+    void move(float);
+    void setSpeed(double);
+    void incScore();
+    int getScore();
+
+    SDL_Rect sprDims;  /* Dimensions of player sprite */
+    SDL_Rect dims;     /* Dimensions of player ship   */
+    SDL_Rect location; /* Location of player ship     */
+
+protected:
+    double speed;           /* this is a double because it can be a fraction */
+    double score;           /* player's score */
+};
+
+
+#endif

File randgen.cpp

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#include "randgen.h"
+
+static Sint32 seed = 0;
+
+void initRandom()
+{
+    seed = time(NULL);
+}
+
+unsigned int getRandom(int max)
+{
+    /* This algorithm is provided by Loki and John Hall */
+    /* in the book Programming Linux Games.             */
+    Sint32 p1 = 1103515245;
+    Sint32 p2 = 12345;
+    seed = (seed*p1+p2) % 2147483647;
+    return (unsigned)seed/3 % max;
+}

File randgen.h

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#ifndef _RANDGEN_H_
+#define _RANDGEN_H_
+
+#include <time.h>
+#include "SDL.h"
+
+void initRandom(); /* Call this to initialize the random number generator */
+unsigned int getRandom(int); /* call this with a parameter to return a random number between 0 and n-1 */
+
+#endif

File snd/bounce.wav

Binary file added.

File snd/menu-opt.wav

Binary file added.

File sound.cpp

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#include "sound.h"
+
+int initSound()
+{
+  SDL_version compileVersion;
+  MIX_VERSION(&compileVersion);
+  printf("Compiled with SDL_mixer version: %d.%d.%d\n",
+    compileVersion.major,
+    compileVersion.minor,
+    compileVersion.patch);
+
+  if(Mix_OpenAudio(SND_FREQUENCY, MIX_DEFAULT_FORMAT, STEREO, SND_CHUNKSIZE)==-1) {
+    printf("Mix_OpenAudio error: %s\n", Mix_GetError());
+    return 1;
+  }
+
+  /* Allocate the channels we want */
+  Mix_AllocateChannels(SND_MAXCHANS);
+
+return 0;
+}
+
+int playSound(SND_Data *sndSetup)
+{
+
+  Mix_Volume(sndSetup->channel,sndSetup->volume);
+
+  if(!Mix_SetPosition(sndSetup->channel, sndSetup->angle, sndSetup->distance)) {
+    printf("Mix_SetPosition: %s\n", Mix_GetError());
+    return 1;
+  }
+
+  if(Mix_PlayChannel(sndSetup->channel, sndSetup->sample, sndSetup->loops)==-1)
+  {
+    printf("Mix_PlayChannel: %s\n",Mix_GetError());
+    return 1;
+  }
+
+return 0;
+}

File sound.h

View file
+/* Battle Pong - a pong game with some extra features */
+/* Copyright (C) 2003 Dana Olson                      */
+/* For more info, read the LICENSE file               */
+
+#ifndef _BP_SOUND_H_
+#define _BP_SOUND_H_
+
+#include "SDL_mixer.h"
+#include "gamedefs.h"
+
+typedef struct {
+  Uint8 volume;   /* 0-255                         */
+  Uint8 distance; /* 0-255                         */
+  Sint16 angle;   /* 0-360, 0 in front, 90 to left */
+  Mix_Chunk *sample;
+  int channel;
+  int loops;
+} SND_Data;
+
+int initSound();
+int playSound(SND_Data*);
+
+#endif
+
+/*
+
+TODO
+
+- load sample
+- play it in left channel when ball hits player1
+- play it in right channel when ball his player2
+- load other sample
+- play it in
+
+REMEMBER
+
+To wait for a sound to finish playing, do this:
+while(Mix_Playing(-1)>0) { SDL_Delay(100); }
+
+
+for the chunk size, do this:
+
+sampling rate / 11025 = factor1
+format / 8 = factor2
+channels = factor3
+
+chunksize = 256 * factor1 * factor2 * factor3
+
+Here is a sample to play a sound:
+
+  ///////////////////START////////////////////////
+  SND_Data testdata;
+  testdata.sample=Mix_LoadWAV("snd/bounce.wav");
+  if(testdata.sample == NULL) {
+    printf("Mix_LoadWAV error occurred: %s\n", Mix_GetError());
+    return 1;
+  }
+
+  testdata.volume=255; testdata.angle=270;
+  testdata.distance=0; testdata.channel=1;
+  testdata.loops=0;
+  if(playSound(&testdata)!=0) { printf("Mix_PlayChannel: %s\n",Mix_GetError()); }
+
+  while(Mix_Playing(-1)>0) { SDL_Delay(100); }
+
+  Mix_FreeChunk(testdata.sample); testdata.sample=NULL;
+  ///////////////////END////////////////////////
+
+
+*/