00. Home
This tutorial describes how to write a more or less full-featured Arkanoid (Breakout) clone.
本教程讲的是如何编写一个功能基本完整的 Arkanoid(又称 Breakout)克隆版。
Here are several screenshots from various stages of the development process:
以下是开发过程中不同阶段的一些截图:
The intended audience are people, who have basic programming experience, but have trouble structuring their code for projects bigger than "Hello World". An Arkanoid, while simple, contains many elements found in more elaborate games. My aim is to introduce a typical code structure, and to provide a starting point for further modifications.
本教程面向的是已经具备基础编程经验、但在组织“Hello World”之外项目代码时会感到吃力的人。Arkanoid 虽然简单,但包含了许多更复杂游戏里也常见的元素。我的目标是介绍一种典型的代码结构,并提供一个可继续扩展和修改的起点。
Lua programming language and LÖVE framework are used. Basic programming experience is assumed. Familiarity with Lua and LÖVE is beneficial but not necessary. Some non-obvious Lua idioms are briefly explained.
本教程使用 Lua 语言和 LÖVE 框架。默认读者已经具备基础编程经验。熟悉 Lua 和 LÖVE 会有帮助,但不是必要条件。文中也会简要解释一些不太直观的 Lua 习惯用法。
Installation
The code can be downloaded using git
代码可以通过 git 下载:
cd /your-path/
git clone https://github.com/noooway/love2d_arkanoid_tutorialor by Github's "Clone or download -> Download ZIP" button.
也可以通过 Github 的 "Clone or download -> Download ZIP" 按钮下载。
Each step can be run with the LÖVE interpreter by issuing a love command followed by the folder name, for example
每一步都可以用 LÖVE 解释器运行,只需执行 love 命令并跟上对应文件夹名,例如:
cd /your-path/love2d_arkanoid_tutorial
love 1-01_TheBallTheBrickThePlatformContents
Chapter 1 describes how to build a prototype for an Arkanoid-type game in the most straightforward way, without relying too much on any external libraries or advanced language features.
Chapter 1 讲的是如何用最直接的方式搭建一个 Arkanoid 类游戏的原型,尽量少依赖外部库或高级语言特性。
Chapter 2 expands the prototype, introducing gamestates, basic graphics and sound. At the end of this chapter, the general frame of the game is complete. What is left is to fill it with the details.
Chapter 2 在原型的基础上继续扩展,引入游戏状态、基础图形与声音。到本章结束时,游戏的整体框架已经完整,剩下的就是填充细节。
Chapter 3 proceeds to add functionality to achieve a full-featured game. While the first two chapters are rather general, material in this chapter is mostly specific for Arkanoid-type games.
Chapter 3 继续补齐功能,最终完成一个功能完整的游戏。前两章相对通用,而本章内容则主要针对 Arkanoid 类游戏本身。
Appendices - which are not written yet 😃 - demonstrate some additional topics, such as how to use environments to define Lua modules, classes, and so on.
Appendices(目前还没写 😃 )会展示一些额外话题,比如如何使用环境来定义 Lua 模块、类等。
I realize that the length of the tutorial - almost 30 parts - is probably a bit too much. On the other hand, the amount of work necessary to write a game is commonly underestimated and this tutorial clearly shows what it actually takes to develop even a simple one.
我知道这套教程的长度——将近 30 篇——可能有点太长了。另一方面,写一个游戏真正需要的工作量常常被低估,而这套教程恰好能清楚展示:即便是一个简单的游戏,也需要投入多少实际工作。
One last thing before we start: feedback is crucial. If you have any critique, suggestions, improvements or just any other ideas, please let me know.
在开始之前还有一句话:反馈非常重要。如果你有任何批评、建议、改进意见或其它想法,请一定告诉我。
Chapter 1: Prototype
- The Ball, The Brick, The Platform
- Game Objects as Lua Tables
- Bricks and Walls
- Detecting Collisions
- Resolving Collisions
- Levels
Appendix A: Storing Levels as Strings
Appendix B: Optimized Collision Detection (draft)
Chapter 2: General Code Structure
- Splitting Code into Several Files
- Loading Levels from Files
- Straightforward Gamestates
- Advanced Gamestates
- Basic Tiles
- Different Brick Types
- Basic Sound
- Game Over
Appendix B: Stricter Modules
Appendix C-1: Intro to Classes
Appendix C-2: Chapter 2 Using Classes.
Chapter 3 (deprecated): Details
- Improved Ball Rebounds
- Ball Launch From Platform (Two Objects Moving Together)
- Mouse Controls
- Spawning Bonuses
- Bonus Effects
- Glue Bonus
- Add New Ball Bonus
- Life and Next Level Bonuses
- Random Bonuses
- Menu Buttons
- Wall Tiles
- Side Panel
- Score
- Fonts
- More Sounds
- Final Screen
- Packaging
Beyond Programming:




