├── audio ├── die.ogg ├── ping_1.ogg ├── zap_1.ogg ├── boing_1.ogg ├── boing_2.ogg ├── ready_go.ogg ├── game_over_1.ogg ├── ready_go_2.ogg ├── wall_bounce_1.ogg └── level_complete.ogg ├── gfx ├── intro.png ├── level_1.jpg ├── level_10.jpg ├── level_2.jpg ├── level_3.jpg ├── level_4.jpg ├── level_5.jpg ├── level_6.jpg ├── level_7.jpg ├── level_8.jpg ├── level_9.jpg └── game_over.jpg ├── fonts └── TerminusTTF.ttf ├── package.lisp ├── levels ├── level_0.dat ├── level_1.dat ├── level_10.dat ├── level_2.dat ├── level_3.dat ├── level_4.dat ├── level_5.dat ├── level_6.dat ├── level_7.dat ├── level_8.dat └── level_9.dat ├── breakout.asd ├── README.md ├── LICENSE └── breakout.lisp /audio/die.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/die.ogg -------------------------------------------------------------------------------- /gfx/intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/intro.png -------------------------------------------------------------------------------- /audio/ping_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/ping_1.ogg -------------------------------------------------------------------------------- /audio/zap_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/zap_1.ogg -------------------------------------------------------------------------------- /gfx/level_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_1.jpg -------------------------------------------------------------------------------- /gfx/level_10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_10.jpg -------------------------------------------------------------------------------- /gfx/level_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_2.jpg -------------------------------------------------------------------------------- /gfx/level_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_3.jpg -------------------------------------------------------------------------------- /gfx/level_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_4.jpg -------------------------------------------------------------------------------- /gfx/level_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_5.jpg -------------------------------------------------------------------------------- /gfx/level_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_6.jpg -------------------------------------------------------------------------------- /gfx/level_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_7.jpg -------------------------------------------------------------------------------- /gfx/level_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_8.jpg -------------------------------------------------------------------------------- /gfx/level_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/level_9.jpg -------------------------------------------------------------------------------- /audio/boing_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/boing_1.ogg -------------------------------------------------------------------------------- /audio/boing_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/boing_2.ogg -------------------------------------------------------------------------------- /audio/ready_go.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/ready_go.ogg -------------------------------------------------------------------------------- /gfx/game_over.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/gfx/game_over.jpg -------------------------------------------------------------------------------- /audio/game_over_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/game_over_1.ogg -------------------------------------------------------------------------------- /audio/ready_go_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/ready_go_2.ogg -------------------------------------------------------------------------------- /fonts/TerminusTTF.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/fonts/TerminusTTF.ttf -------------------------------------------------------------------------------- /audio/wall_bounce_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/wall_bounce_1.ogg -------------------------------------------------------------------------------- /audio/level_complete.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebity/breakout/HEAD/audio/level_complete.ogg -------------------------------------------------------------------------------- /package.lisp: -------------------------------------------------------------------------------- 1 | ;;;; package.lisp 2 | 3 | (defpackage #:breakout 4 | (:use #:cl) 5 | (:export #:start)) 6 | 7 | -------------------------------------------------------------------------------- /levels/level_0.dat: -------------------------------------------------------------------------------- 1 | 000000000000000 2 | 000000000000000 3 | 000000000000000 4 | 000000000000000 5 | 000000000000000 6 | 000000000000000 7 | 000000000000000 8 | 000000000000000 9 | 000000000000000 10 | 000000000000000 11 | 000000000000000 12 | 000000000000000 13 | 000000000000000 14 | 000000000000000 15 | 000000000000000 16 | -------------------------------------------------------------------------------- /levels/level_1.dat: -------------------------------------------------------------------------------- 1 | 000000000000000 2 | 000000000000000 3 | 000000000000000 4 | 000000000000000 5 | 333333333333333 6 | 222222222222222 7 | 111111111111111 8 | 000000000000000 9 | 000000000000000 10 | 000000000000000 11 | 000000000000000 12 | 000000000000000 13 | 000000000000000 14 | 000000000000000 15 | 000000000000000 16 | -------------------------------------------------------------------------------- /levels/level_10.dat: -------------------------------------------------------------------------------- 1 | 000000000000000 2 | 080000000000080 3 | 008123454321800 4 | 003800000008300 5 | 004081111180400 6 | 005013333310500 7 | 006013666310600 8 | 007013686310700 9 | 006013666310600 10 | 005013333310500 11 | 004081111180400 12 | 003800000008300 13 | 008123454321800 14 | 080000000000080 15 | 000000000000000 16 | -------------------------------------------------------------------------------- /levels/level_2.dat: -------------------------------------------------------------------------------- 1 | 000000000000000 2 | 000000000000000 3 | 000000010000000 4 | 000000222000000 5 | 000003333300000 6 | 000011111110000 7 | 000222222222000 8 | 003333333333300 9 | 000222222222000 10 | 000011111110000 11 | 000003333300000 12 | 000000222000000 13 | 000000010000000 14 | 000000000000000 15 | 000000000000000 16 | -------------------------------------------------------------------------------- /levels/level_3.dat: -------------------------------------------------------------------------------- 1 | 000000000000000 2 | 000000000000000 3 | 111100111001111 4 | 222200222002222 5 | 333300333003333 6 | 444400444004444 7 | 333300333003333 8 | 222200222002222 9 | 111100111001111 10 | 000000000000000 11 | 000000000000000 12 | 000000000000000 13 | 000000000000000 14 | 000000000000000 15 | 000000000000000 16 | -------------------------------------------------------------------------------- /levels/level_4.dat: -------------------------------------------------------------------------------- 1 | 000044000000000 2 | 000340000000000 3 | 003300005500000 4 | 003300025000000 5 | 013340025000000 6 | 013344020000000 7 | 143344220000000 8 | 143344220000000 9 | 113344020000000 10 | 013340020000000 11 | 013344025000000 12 | 003300025000000 13 | 003300005500000 14 | 003300000000000 15 | 000040000000000 16 | -------------------------------------------------------------------------------- /levels/level_5.dat: -------------------------------------------------------------------------------- 1 | 000000000000000 2 | 011000000001100 3 | 010100000010100 4 | 000011111100000 5 | 000112222110000 6 | 000122222210000 7 | 000128228210000 8 | 000122222210000 9 | 000122882210000 10 | 000122222210000 11 | 000012112100000 12 | 000001001000000 13 | 000001001000000 14 | 000001001000000 15 | 000011001100000 16 | -------------------------------------------------------------------------------- /levels/level_6.dat: -------------------------------------------------------------------------------- 1 | 000000000000000 2 | 000000000000000 3 | 000000000000000 4 | 282233113322820 5 | 303000000003030 6 | 003000000003000 7 | 003001133003000 8 | 001001133001000 9 | 001001223001000 10 | 002001223002000 11 | 002001133002000 12 | 003001133003000 13 | 003000000003000 14 | 001000000001000 15 | 002113333112000 16 | -------------------------------------------------------------------------------- /levels/level_7.dat: -------------------------------------------------------------------------------- 1 | 100000000000000 2 | 120000000000000 3 | 123000000000000 4 | 123400000000000 5 | 123450000000000 6 | 123456000000000 7 | 123456700000000 8 | 123456710000000 9 | 123456712000000 10 | 123456712300000 11 | 123456712340000 12 | 123456712345000 13 | 123456712345600 14 | 123456712345670 15 | 123456712345671 16 | -------------------------------------------------------------------------------- /levels/level_8.dat: -------------------------------------------------------------------------------- 1 | 000080000800000 2 | 080000000000800 3 | 000011661100000 4 | 000811661180000 5 | 801177667711080 6 | 001177667711000 7 | 006666546666000 8 | 006666456666000 9 | 001177667711000 10 | 801177667711080 11 | 000811661180000 12 | 000011661100000 13 | 080000000000800 14 | 000080000800000 15 | 000000000000000 16 | -------------------------------------------------------------------------------- /levels/level_9.dat: -------------------------------------------------------------------------------- 1 | 000000080000000 2 | 008000080000800 3 | 000000666000000 4 | 008000676000800 5 | 000000676000000 6 | 008002444200800 7 | 008002444200800 8 | 008222332222800 9 | 008223333522800 10 | 000088000880000 11 | 000000010000000 12 | 000000141000000 13 | 000001484100000 14 | 000001484100000 15 | 000014505410000 16 | -------------------------------------------------------------------------------- /breakout.asd: -------------------------------------------------------------------------------- 1 | ;;;; breakout.asd 2 | 3 | (asdf:defsystem #:breakout 4 | :description "A Remake of the Classic Game Breakout" 5 | :author "Jan Tatham " 6 | :license "GPL v2" 7 | :depends-on (#:lispbuilder-sdl 8 | #:lispbuilder-sdl-ttf 9 | #:lispbuilder-sdl-mixer) 10 | :serial t 11 | :components ((:file "package") 12 | (:file "breakout"))) 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Breakout 2 | ======== 3 | 4 | A Remake of the Classic Game Breakout in Common Lisp 5 | 6 | ## Dependencies 7 | 8 | - [LISPBUILDER-SDL](https://code.google.com/p/lispbuilder/wiki/LispbuilderSDL) 9 | 10 | ## Quickstart 11 | 12 | To run this game place the files somewhere [Quicklisp](http://www.quicklisp.org/) can find it, and execute the following in the REPL: 13 | 14 | ```lisp 15 | (ql:quickload :breakout) 16 | (breakout:start) 17 | ``` 18 | 19 | ## Controls 20 | 21 | To control the paddle use the `Left` and `Right` arrows keys. 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /breakout.lisp: -------------------------------------------------------------------------------- 1 | ;;;; breakout.lisp 2 | 3 | (in-package #:breakout) 4 | 5 | ;;; "breakout" goes here. Hacks and glory await! 6 | 7 | (defparameter *data-root* (asdf:system-source-directory 'breakout)) 8 | (defparameter *font-root* (merge-pathnames "fonts/" *data-root*)) 9 | (defparameter *audio-root* (merge-pathnames "audio/" *data-root*)) 10 | (defparameter *gfx-root* (merge-pathnames "gfx/" *data-root*)) 11 | (defparameter *level-root* (merge-pathnames "levels/" *data-root*)) 12 | 13 | ;;;; Game Params 14 | (defparameter *game-width* 480) 15 | (defparameter *game-height* 600) 16 | (defparameter *game-state* 0) ; 0=menu, 1:ready, 2:in-game, 3:win-lose 17 | 18 | (defparameter *level-width* 15) ;25 19 | (defparameter *level-height* 15) ;20 20 | (defparameter *level* nil) 21 | (defparameter *tile-width* 32) ;32 22 | (defparameter *tile-height* 20) ;20 23 | 24 | 25 | (defparameter *player* nil) 26 | (defparameter *player-score* 0) 27 | (defparameter *player-lives* 3) 28 | (defparameter *level-number* 1) 29 | 30 | (defparameter *ball* nil) 31 | (defparameter *pause* 0) 32 | (defparameter *get-ready* 0) 33 | (defparameter *get-ready-count* 0) 34 | 35 | (defparameter *bricks-in-level* 0) 36 | 37 | ;;;; Sound Params 38 | (defparameter *mixer-opened* nil) 39 | (defparameter *music* nil) 40 | (defparameter *soundfx* nil) 41 | 42 | ;;;; GFX Params 43 | (defparameter *gfx-breakout* (merge-pathnames "intro.png" *gfx-root*)) 44 | (defparameter *gfx-game-over* (merge-pathnames "game_over.jpg" *gfx-root*)) 45 | 46 | ;;;; Font Params 47 | (defparameter *terminus-ttf-12* 48 | (make-instance 'SDL:ttf-font-definition 49 | :size 12 50 | :filename (merge-pathnames "TerminusTTF.ttf" *font-root*))) 51 | 52 | (defparameter *terminus-ttf-18* 53 | (make-instance 'SDL:ttf-font-definition 54 | :size 18 55 | :filename (merge-pathnames "TerminusTTF.ttf" *font-root*))) 56 | 57 | (defparameter *terminus-ttf-24* 58 | (make-instance 'SDL:ttf-font-definition 59 | :size 24 60 | :filename (merge-pathnames "TerminusTTF.ttf" *font-root*))) 61 | 62 | (defparameter *terminus-ttf-32* 63 | (make-instance 'SDL:ttf-font-definition 64 | :size 32 65 | :filename (merge-pathnames "TerminusTTF.ttf" *font-root*))) 66 | 67 | (defparameter *ttf-font-small* nil) 68 | (defparameter *ttf-font-normal* nil) 69 | (defparameter *ttf-font-large* nil) 70 | (defparameter *ttf-font-huge* nil) 71 | 72 | 73 | ;;;; PADDLE class 74 | 75 | (defclass paddle () 76 | ((x :accessor x :initarg :x) 77 | (y :accessor y :initarg :y) 78 | (w :accessor w :initarg :w) 79 | (h :accessor h :initarg :h) 80 | (r :accessor r :initarg :r) 81 | (g :accessor g :initarg :g) 82 | (b :accessor b :initarg :b) 83 | (spd :accessor spd :initarg :spd))) 84 | 85 | ;;;; BALL class 86 | 87 | (defclass ball () 88 | ((x :accessor x :initarg :x) 89 | (y :accessor y :initarg :y) 90 | (w :accessor w :initarg :w) 91 | (h :accessor h :initarg :h) 92 | (r :accessor r :initarg :r) 93 | (g :accessor g :initarg :g) 94 | (b :accessor b :initarg :b) 95 | (dx :accessor dx :initarg :dx) 96 | (dy :accessor dy :initarg :dy) 97 | (spd :accessor spd :initarg :spd))) 98 | 99 | 100 | ;;;; CONTINUABLE macro 101 | 102 | (defmacro continuable (&body body) 103 | `(restart-case 104 | (progn ,@body) 105 | (continue () :report "Continue"))) 106 | 107 | 108 | ;;;; UPDATE-SWANK function 109 | 110 | (defun update-swank () 111 | (continuable 112 | (let ((connection (or swank::*emacs-connection* 113 | (swank::default-connection)))) 114 | (when connection 115 | (swank::handle-requests connection t))))) 116 | 117 | 118 | ;;;;;;;;;;;;;;;;;;;;;;;; PRIMITIVES ;;;;;;;;;;;;;;;;;;;;;;;; 119 | 120 | 121 | ;;;; DRAW-TEXT function 122 | 123 | (defun draw-text (string x y r g b &optional (font *ttf-font-normal*)) 124 | (sdl:draw-string-solid-* string 125 | x y 126 | :color (sdl:color :r r :g g :b b) 127 | :font font)) 128 | 129 | 130 | ;;;; DRAW-BOX function 131 | 132 | (defun draw-box (x y w h r g b) 133 | (sdl:draw-box-* x y w h 134 | :color (sdl:color :r r :g g :b b))) 135 | 136 | 137 | ;;;; DRAW-LINE function 138 | 139 | (defun draw-line (x0 y0 x1 y1 r g b) 140 | (sdl:draw-line-* x0 y0 x1 y1 141 | :color (sdl:color :r r :g g :b b))) 142 | 143 | 144 | ;;;; PLAY-SOUND function 145 | 146 | (defun play-sound (s) 147 | (sdl-mixer:play-sample (aref *soundfx* s))) 148 | 149 | 150 | ;;;;;;;;;;;;;;;;;;;;;;;; LEVEL ;;;;;;;;;;;;;;;;;;;;;;;; 151 | 152 | 153 | ;;;; MAKE-LEVEL function 154 | 155 | (defun make-level () 156 | (setf *level* (make-array (list *level-height* *level-width*)))) 157 | 158 | 159 | ;;;; PARSE-LEVEL function 160 | 161 | (defun parse-level (lines) 162 | (setf *level-width* (length (first lines))) 163 | (setf *level-height* (length lines)) 164 | (make-level) 165 | (let* ((width *level-width*) 166 | (height *level-height*)) 167 | (loop for y below height 168 | for line in lines 169 | do (loop for x below width 170 | as element = (aref line x) 171 | do (progn (setf (aref *level* y x) element) 172 | (unless (or (equalp element #\0) (equalp element #\8)) 173 | (setf *bricks-in-level* (incf *bricks-in-level*)))))))) 174 | 175 | 176 | ;;;; LOAD-LEVEL function 177 | 178 | (defun load-level (level) 179 | (let ((filename (format nil "~alevel_~1,'0d.dat" *level-root* level))) 180 | (with-open-file (stream filename) 181 | (loop as line = (read-line stream nil nil) 182 | until (null line) 183 | collect line into lines 184 | finally (return (parse-level lines)))))) 185 | 186 | 187 | 188 | ;;;; DRAW-TILE function 189 | 190 | (defun draw-tile (tile x y) 191 | (let ((pos-x (* x *tile-width*)) 192 | (pos-y (* y *tile-height*))) 193 | (case tile 194 | ((#\1) (draw-box pos-x pos-y (- *tile-width* 2) (- *tile-height* 2) 209 17 65)) 195 | 196 | ((#\2) (draw-box pos-x pos-y (- *tile-width* 2) (- *tile-height* 2) 0 177 89)) 197 | 198 | ((#\3) (draw-box pos-x pos-y (- *tile-width* 2) (- *tile-height* 2) 0 174 219)) 199 | 200 | ((#\4) (draw-box pos-x pos-y (- *tile-width* 2) (- *tile-height* 2) 243 119 53)) 201 | 202 | ((#\5) (draw-box pos-x pos-y (- *tile-width* 2) (- *tile-height* 2) 255 196 37)) 203 | 204 | ((#\6) (draw-box pos-x pos-y (- *tile-width* 2) (- *tile-height* 2) 114 0 172)) 205 | 206 | ((#\7) (draw-box pos-x pos-y (- *tile-width* 2) (- *tile-height* 2) 99 47 0)) 207 | 208 | ((#\8) (draw-box pos-x pos-y (- *tile-width* 2) (- *tile-height* 2) 192 192 192))))) 209 | 210 | ;;;; DISPLAY-LEVEL function 211 | 212 | (defun display-level () 213 | (loop for y below *level-height* 214 | do (progn (fresh-line) 215 | (loop for x below *level-width* 216 | for tile = (aref *level* y x) 217 | do (draw-tile tile x y))))) 218 | 219 | 220 | ;;;; DISPLAY-BACKGROUND function 221 | 222 | (defun display-background () 223 | (sdl:draw-surface-at-* 224 | (sdl:load-image (format nil "~alevel_~a.jpg" *gfx-root* *level-number*)) 0 0)) 225 | 226 | 227 | 228 | ;;;; DISPLAY-GET-READY function 229 | 230 | (defun display-get-ready () 231 | (if (>= *get-ready-count* 100) 232 | (progn (setf *get-ready* 0) 233 | (setf *pause* 0)) 234 | (setf *get-ready-count* (incf *get-ready-count*))) 235 | 236 | (if (= *get-ready-count* 1) 237 | (play-sound 5)) 238 | 239 | (if (< *get-ready-count* 60) 240 | (draw-text "READY!" 180 300 255 255 255 *ttf-font-huge*) 241 | (draw-text "GO!" 200 300 255 255 255 *ttf-font-huge*))) 242 | 243 | ;;;;;;;;;;;;;;;;;;;;;;;; BALL ;;;;;;;;;;;;;;;;;;;;;;;; 244 | 245 | ;;;; CREATE-BALL function 246 | 247 | (defun create-ball () 248 | (setf *ball* (make-instance 'ball 249 | :x (- (/ *game-width* 2) 3) :y (- *game-height* 57) 250 | :w 5 :h 5 251 | :r 255 :g 255 :b 255 252 | :dx (- (random 5) 2) :dy -2 :spd 2))) 253 | 254 | 255 | ;;;; RESET-BALL function 256 | (defun reset-ball (b) 257 | (setf (x b) (- (/ *game-width* 2) 3)) 258 | (setf (y b) (- *game-height* 57)) 259 | (setf (dy b) -2) 260 | (setf (dx b) (- (random 7) 3))) 261 | 262 | 263 | ;;;; DISPLAY-BALL function 264 | 265 | (defun display-ball (b) 266 | (draw-box (x b) (y b) (w b) (h b) (r b) (g b) (b b))) 267 | 268 | 269 | ;;;;;;;;;;;;;;;;;;;;;;;; BALL PHYSICS ;;;;;;;;;;;;;;;;;;;;;;;; 270 | 1 271 | 272 | ;;;; UPDATE-BALL function 273 | 274 | (defun update-ball (b p) 275 | (setf (x b) (+ (x b) (* (dx b) (spd b)))) 276 | (setf (y b) (+ (y b) (* (dy b) (spd b)))) 277 | 278 | ; Bricks 279 | (collide-brick b) 280 | 281 | ; Left Wall 282 | (if (<= (x b) 0) 283 | (progn (setf (dx b) (abs (dx b))) 284 | (play-sound 2))) 285 | 286 | ; Right Wall 287 | (if (>= (+ (x b) (w b)) *game-width*) 288 | (progn (setf (dx b) (- (dx b))) 289 | (play-sound 2))) 290 | 291 | ; Top Wall 292 | (if (<= (y b) 0) 293 | (progn (setf (dy b) (abs (dy b))) 294 | (play-sound 2))) 295 | 296 | ; Paddle 297 | (if (and (<= (x p) (x b)) 298 | (>= (+ (x p) (w p)) (+ (x b) (w b))) 299 | (<= (y p) (+ (y b) (h b))) 300 | (>= (+ (y p) (h p)) (+ (y b) (h b)))) 301 | (handle-paddle-collision p b)) 302 | 303 | ; Fall Out 304 | (if (> (+ (y b) (h b)) (- *game-height* 30)) 305 | (progn (setf *player-lives* (decf *player-lives*)) 306 | (if (zerop *player-lives*) 307 | (progn (play-sound 6) 308 | (change-game-state)) 309 | (progn (play-sound 4) 310 | (reset-level)))))) 311 | 312 | 313 | ;;;; COLLIDE-BRICK function 314 | 315 | (defun collide-brick (b) 316 | (loop for y below *level-height* 317 | do (loop for x below *level-width* 318 | for brick = (aref *level* y x) 319 | do (if (equalp brick #\0) 320 | t 321 | (handle-brick-collision brick x y b))))) 322 | 323 | 324 | ;;;; HANDLE-BRICK-COLLISION function 325 | 326 | (defun handle-brick-collision (brick x y b) 327 | (let* ((w *tile-width*) 328 | (h *tile-height*)) 329 | 330 | ;top 331 | (cond ((and (<= (* y h) (+ (y b) (h b))) 332 | (>= (* y h) (y b)) 333 | (<= (* x w) (x b)) 334 | (>= (+ (* x w) w) (+ (x b) (w b)))) 335 | (progn (setf (dy b) (- (dy b))) 336 | (update-score brick x y))) 337 | 338 | ; bottom 339 | ((and (>= (+ (* y h) h) (y b)) 340 | (<= (+ (* y h) h) (+ (y b) (h b))) 341 | (<= (* x w) (x b)) 342 | (>= (+ (* x w) w) (+ (x b) (w b)))) 343 | (progn (setf (dy b) (- (dy b))) 344 | (update-score brick x y))) 345 | 346 | ; left 347 | ((and (<= (* y h) (y b)) 348 | (>= (+ (* y h) h) (+ (y b) (h b))) 349 | (>= (* x w) (x b)) 350 | (<= (* x w) (+ (x b) (w b)))) 351 | (progn (setf (dx b) (- (dx b))) 352 | (update-score brick x y))) 353 | 354 | ; right 355 | ((and (<= (* y h) (y b)) 356 | (>= (+ (* y h) h) (+ (y b) (h b))) 357 | (>= (+ (* x w) w) (x b)) 358 | (<= (+ (* x w) w) (+ (x b) (w b)))) 359 | (progn (setf (dx b) (- (dx b))) 360 | (update-score brick x y)))))) 361 | 362 | 363 | ;;;; HANDLE-PADDLE-COLLISION function 364 | 365 | (defun handle-paddle-collision (p b) 366 | (let* ((pw-div (/ (w p) 4)) 367 | (b-mid (+ (x b) (/ (w b) 2)))) 368 | 369 | (cond ((and (<= (x p) b-mid) 370 | (>= (+ (x p) pw-div) b-mid) 371 | (<= (y p) (+ (y b) (h b))) 372 | (>= (y p) (- (y b) (h b)))) 373 | (progn (setf (dy b) (- (dy b))) 374 | (if (sdl:get-key-state :sdl-key-left) 375 | (setf (dx b) -3) 376 | (setf (dx b) -2)) 377 | (play-sound 1))) 378 | 379 | ((and (<= (+ (x p) pw-div) b-mid) 380 | (>= (+ (x p) (* pw-div 2)) b-mid) 381 | (<= (y p) (+ (y b) (h b))) 382 | (>= (y p) (- (y b) (h b)))) 383 | (progn (setf (dy b) (- (dy b))) 384 | (setf (dx b) -1) 385 | (play-sound 1))) 386 | 387 | ((and (<= (+ (x p) (* pw-div 2)) b-mid) 388 | (>= (+ (x p) (* pw-div 3)) b-mid) 389 | (<= (y p) (+ (y b) (h b))) 390 | (>= (y p) (- (y b) (h b)))) 391 | (progn (setf (dy b) (- (dy b))) 392 | (setf (dx b) 1) 393 | (play-sound 1))) 394 | 395 | ((and (<= (+ (x p) (* pw-div 3)) b-mid) 396 | (>= (+ (x p) (w p)) b-mid) 397 | (<= (y p) (+ (y b) (h b))) 398 | (>= (y p) (- (y b) (h b)))) 399 | (progn (setf (dy b) (- (dy b))) 400 | (if (sdl:get-key-state :sdl-key-right) 401 | (setf (dx b) 3) 402 | (setf (dx b) 2)) 403 | (play-sound 1))) 404 | 405 | (t (progn (setf (dy b) (- (dy b))) 406 | (setf (dx b) 0)))))) 407 | 408 | 409 | ;;;;;;;;;;;;;;;;;;;;;;;; SCORING ;;;;;;;;;;;;;;;;;;;;;;;; 410 | 411 | ;;;; UPDATE-SCORE function 412 | 413 | (defun update-score (brick x y) 414 | 415 | (unless (equalp brick #\8) 416 | (progn (setf (aref *level* y x) #\0) 417 | (setf *bricks-in-level* (decf *bricks-in-level*)))) 418 | 419 | (cond ((equalp brick #\1) 420 | (progn (play-sound 0) 421 | (setf *player-score* (+ *player-score* (* 10 *player-lives*))))) 422 | 423 | ((equalp brick #\2) 424 | (progn (play-sound 0) 425 | (setf *player-score* (+ *player-score* (* 20 *player-lives*))))) 426 | 427 | ((equalp brick #\3) 428 | (progn (play-sound 0) 429 | (setf *player-score* (+ *player-score* (* 30 *player-lives*))))) 430 | 431 | ((equalp brick #\4) 432 | (progn (play-sound 0) 433 | (setf *player-score* (+ *player-score* (* 40 *level-number*))))) 434 | 435 | ((equalp brick #\5) 436 | (progn (play-sound 0) 437 | (setf *player-score* (+ *player-score* (* 50 *player-lives*))))) 438 | 439 | ((equalp brick #\6) 440 | (progn (play-sound 0) 441 | (setf *player-score* (+ *player-score* (* 60 *player-lives*))))) 442 | 443 | ((equalp brick #\7) 444 | (progn (play-sound 0) 445 | (setf *player-score* (+ *player-score* (* 70 *player-lives*)))))) 446 | 447 | (if (zerop *bricks-in-level*) 448 | (progn (setf *player-score* 449 | (+ *player-score* (* 1000 *player-lives* *level-number*))) 450 | (setf *level-number* (incf *level-number*)) 451 | (play-sound 3) 452 | (load-new-level)))) 453 | 454 | 455 | ;;;;;;;;;;;;;;;;;;;;;;;; PLAYER ;;;;;;;;;;;;;;;;;;;;;;;; 456 | 457 | 458 | ;;;; CREATE-PLAYER function 459 | 460 | (defun create-player () 461 | (setf *player* (make-instance 'paddle 462 | :x (/ *game-width* 2) :y (- *game-height* 50) 463 | :w 60 :h 12 464 | :r 255 :g 0 :b 0 465 | :spd 5))) 466 | 467 | 468 | ;;;; RESET-PLAYER function 469 | 470 | (defun reset-player () 471 | (setf (x *player*) (- (/ *game-width* 2) (/ (w *player*) 2)))) 472 | 473 | 474 | ;;;; DISPLAY-PLAYER function 475 | 476 | (defun display-player (p) 477 | (draw-box (x p) (y p) (w p) (h p) (r p) (g p) (b p))) 478 | 479 | 480 | ;;;; MOVE-PLAYER function 481 | 482 | (defun move-player (direction) 483 | (unless (= *pause* 1) 484 | (cond ((eq direction 'left) 485 | (unless (<= (x *player*) -5) 486 | (setf (x *player*) (- (x *player*) (spd *player*))))) 487 | 488 | ((eq direction 'right) 489 | (unless (>= (+ (x *player*) (w *player*)) (+ *game-width* 5)) 490 | (setf (x *player*) (+ (x *player*) (spd *player*)))))))) 491 | 492 | 493 | ;;;;;;;;;;;;;;;;;;;;;;;; SCREENS ;;;;;;;;;;;;;;;;;;;;;;;; 494 | 495 | 496 | ;;;; DISPLAY-UI function 497 | 498 | (defun display-ui () 499 | (draw-box 0 (- *game-height* 30) *game-width* *game-height* 0 0 0) 500 | (draw-line 0 (- *game-height* 30) *game-width* (- *game-height* 30) 20 20 20) 501 | 502 | (draw-text "Level:" 20 (- *game-height* 25) 255 255 255 *ttf-font-normal*) 503 | (draw-text (format nil "~a" *level-number*) 85 (- *game-height* 25) 255 255 0 *ttf-font-normal*) 504 | 505 | (draw-text "Score:" 150 (- *game-height* 25) 255 255 255 *ttf-font-normal*) 506 | (draw-text (format nil "~a" *player-score*) 215 (- *game-height* 25) 255 255 0 *ttf-font-normal*) 507 | 508 | (draw-text (format nil "Lives: ~a" *player-lives*) 509 | 375 (- *game-height* 25) 255 255 255 *ttf-font-normal*)) 510 | 511 | 512 | ;;;; DISPLAY-END-GAME function 513 | 514 | (defun display-end-game () 515 | (sdl:draw-surface-at-* (sdl:load-image *gfx-game-over*) 0 0) 516 | 517 | (draw-text "BREAKOUT" 180 20 255 255 0 *ttf-font-huge*) 518 | 519 | (if (and (zerop *bricks-in-level*) (= *level* 10)) 520 | (draw-text "CONGRATULATIONS!!! YOU WON!!!" 100 100 255 255 0 *ttf-font-huge*) 521 | (progn (draw-text "GAME OVER!" 160 130 255 255 255 *ttf-font-huge*) 522 | (draw-text (format nil "YOUR SCORE IS ~a" *player-score*) 523 | 100 250 255 0 0 *ttf-font-huge*))) 524 | (draw-text "Press SPACE to Continue..." 120 560 255 255 255)) 525 | 526 | 527 | ;;;; DISPLAY-MENU function 528 | 529 | (defun display-menu () 530 | (sdl:draw-surface-at-* (sdl:load-image *gfx-breakout*) 0 0) 531 | ;(sdl:draw-surface-at-* (sdl:load-image *gfx-logo*) 5 50) 532 | ;(draw-text "BREAKOUT" 180 20 255 255 0 *ttf-font-huge*) 533 | (draw-text "Press SPACE to Start..." 120 560 255 255 255)) 534 | 535 | 536 | ;;;;;;;;;;;;;;;;;;;;;;;; GAME STATE ;;;;;;;;;;;;;;;;;;;;;;;; 537 | 538 | ;;;; CONTINUE-OPTION function 539 | 540 | (defun continue-option () 541 | (cond ((zerop *game-state*) (change-game-state)) 542 | ((= *game-state* 2) (change-game-state)) 543 | (t ()))) 544 | 545 | 546 | ;;;; CHANGE-GAME-STATE function 547 | 548 | (defun change-game-state () 549 | (cond ((zerop *game-state*) (progn (reset-game) 550 | (setf *game-state* 1))) 551 | ((= *game-state* 1) (setf *game-state* 2)) 552 | ((= *game-state* 2) (setf *game-state* 0)) 553 | (t ()))) 554 | 555 | 556 | ;;;;;;;;;;;;;;;;;;;;;;;; THE GAME ;;;;;;;;;;;;;;;;;;;;;;;; 557 | 558 | 559 | ;;;; RENDER function 560 | 561 | (defun render () 562 | (update-swank) 563 | (sdl:clear-display sdl:*black*) 564 | 565 | (cond ((= *game-state* 1) 566 | (display-background) 567 | (display-level) 568 | (if (zerop *pause*) 569 | (update-ball *ball* *player*)) 570 | (display-player *player*) 571 | (display-ball *ball*) 572 | (if (= *get-ready* 1) 573 | (display-get-ready)) 574 | (display-ui)) 575 | 576 | ((= *game-state* 2) 577 | (display-end-game)) 578 | 579 | (t (display-menu))) 580 | 581 | (sdl:update-display)) 582 | 583 | 584 | ;;;; RESET-GAME function 585 | 586 | (defun reset-level () 587 | (reset-player) 588 | (reset-ball *ball*) 589 | (setf *get-ready-count* 0) 590 | (setf *get-ready* 1) 591 | (setf *pause* 1)) 592 | ;(play-sound 5)) 593 | 594 | 595 | ;;;; LOAD-NEW-LEVEL function 596 | 597 | (defun load-new-level () 598 | (setf *bricks-in-level* 0) 599 | (load-level *level-number*) 600 | (reset-player) 601 | (reset-ball *ball*)) 602 | 603 | 604 | ;;;; RESET-GAME function 605 | 606 | (defun reset-game () 607 | (setf *player-score* 0) 608 | (setf *player-lives* 3) 609 | (setf *level-number* 1) 610 | (setf *get-ready-count* 0) 611 | (setf *get-ready* 1) 612 | (setf *pause* 1) 613 | (load-new-level)) 614 | 615 | 616 | ;;;; INITIALIZE-GAME function 617 | 618 | (defun initialize-game () 619 | (setf *game-state* 0) 620 | (create-player) 621 | (create-ball)) 622 | 623 | 624 | ;;;; SETUP-FONTS function 625 | 626 | (defun setup-fonts () 627 | (unless (sdl:initialise-default-font *terminus-ttf-18*) 628 | (error "FONT-EXAMPLE: Cannot initialize the default font.")) 629 | 630 | (setf *ttf-font-small* (sdl:initialise-font *terminus-ttf-12*)) 631 | (setf *ttf-font-normal* (sdl:initialise-font *terminus-ttf-18*)) 632 | (setf *ttf-font-large* (sdl:initialise-font *terminus-ttf-24*)) 633 | (setf *ttf-font-huge* (sdl:initialise-font *terminus-ttf-32*))) 634 | 635 | 636 | ;;;; SETUP-AUDIO function 637 | 638 | (defun setup-audio () 639 | (setf *soundfx* (make-array 7)) 640 | (sdl-mixer:init-mixer :mp3) 641 | (setf *mixer-opened* (sdl-mixer:OPEN-AUDIO :chunksize 1024 :enable-callbacks nil)) 642 | (when *mixer-opened* 643 | (setf (aref *soundfx* 0) (sdl-mixer:load-sample (sdl:create-path "zap_1.ogg" *audio-root*))) 644 | (setf (aref *soundfx* 1) (sdl-mixer:load-sample (sdl:create-path "ping_1.ogg" *audio-root*))) 645 | (setf (aref *soundfx* 2) (sdl-mixer:load-sample (sdl:create-path "wall_bounce_1.ogg" *audio-root*))) 646 | (setf (aref *soundfx* 3) (sdl-mixer:load-sample (sdl:create-path "level_complete.ogg" *audio-root*))) 647 | (setf (aref *soundfx* 4) (sdl-mixer:load-sample (sdl:create-path "die.ogg" *audio-root*))) 648 | (setf (aref *soundfx* 5) (sdl-mixer:load-sample (sdl:create-path "ready_go_2.ogg" *audio-root*))) 649 | (setf (aref *soundfx* 6) (sdl-mixer:load-sample (sdl:create-path "game_over_1.ogg" *audio-root*))) 650 | (sample-finished-action) 651 | (sdl-mixer:allocate-channels 16))) 652 | 653 | 654 | ;;; SAMPLE-FINISHED-ACTION function 655 | 656 | (defun sample-finished-action () 657 | (sdl-mixer:register-sample-finished 658 | (lambda (channel) 659 | (declare (ignore channel)) 660 | nil))) 661 | 662 | 663 | ;;;; CLEAN-UP function 664 | 665 | (defun clean-up () 666 | (when (sdl-mixer:sample-playing-p nil) 667 | (sdl-mixer:pause-sample t) 668 | (sdl-mixer:Halt-sample :channel t)) 669 | 670 | (loop for s below (length *soundfx*) 671 | do (if (equal (aref *soundfx* s) 0) 672 | t 673 | (progn (sdl:free (aref *soundfx* s)) 674 | (setf (aref *soundfx* s) 0)))) 675 | 676 | (when *mixer-opened* 677 | (sdl-mixer:Close-Audio t) 678 | (setf *mixer-opened* nil)) 679 | (sdl-mixer:quit-mixer)) 680 | 681 | 682 | ;;;; START function 683 | 684 | (defun start () 685 | (initialize-game) 686 | (reset-game) 687 | (sdl:with-init (sdl:sdl-init-video sdl:sdl-init-audio) 688 | (sdl:window *game-width* *game-height* :title-caption "Breakout") 689 | (setf (sdl:frame-rate) 60) 690 | 691 | (setup-audio) 692 | 693 | (setup-fonts) 694 | 695 | (sdl:with-events () 696 | (:quit-event () 697 | (clean-up) 698 | t) 699 | (:key-down-event (:key key) 700 | (case key 701 | (:sdl-key-q (if (= *game-state* 1) 702 | (change-game-state))) 703 | (:sdl-key-space (continue-option)) 704 | (:sdl-key-escape (sdl:push-quit-event)))) 705 | (:key-up-event (:key key) 706 | (case key)) 707 | (:idle () 708 | (when (sdl:get-key-state :sdl-key-left) (move-player 'left)) 709 | (when (sdl:get-key-state :sdl-key-right) (move-player 'right)) 710 | (render))))) 711 | --------------------------------------------------------------------------------