少于64行的C ++ Breakout游戏克隆(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/a-c-breakout-game-clone-in-less-than-64-lines-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 3 分钟阅读 - 1343 个词 阅读量 0少于64行的C ++ Breakout游戏克隆(译文)
原文地址:https://www.codeproject.com/Articles/17734/A-C-Breakout-Game-Clone-in-Less-than-64-Lines
原文作者:Ronounours
译文由本站 robot-v1.0 翻译
前言
I propose a simple version of a Breakout (or Arkanoid) game in few C++ lines.
我用几行C ++语言提出了一个Breakout(或Arkanoid)游戏的简单版本.
介绍(Introduction)
我在这里提出了一个著名的Breakout游戏(或Arkanoid,如果您愿意的话)的跨平台C ++版本.有趣的是,它用不到64行的C ++代码进行编码.尽管代码非常紧凑,但仍易于阅读.秘密?我用(I propose here a cross-platform C++ version of the well known Breakout game (or Arkanoid if you prefer). The interesting thing here is that it is coded in less than 64 lines of C++ code. While the code is quite compact, it stays easily readable. The secret ? I use the) CImg图书馆(CImg Library) 对图像执行所有必要的操作.的(to perform all necessary operations on images. The) CImg
库是一种易于使用的C ++模板图像处理库,具有完全适合单个头文件的特殊性.这意味着通过一个包含,您就可以处理图像并对其执行许多操作(显示,过滤,绘制等).(Library is an easy-to-use C++ template image processing library that has the particularity to entirely fit in one single header file. It means that with a single include, you are able to deal with images and perform many operations on it (display, filtering, drawing, …).)
这项工作是在我之前提交的有关"(This work follows my previous submission on “) 俄罗斯方块不到128行代码(Tetris in less than 128 lines of code) “,已在CodeProject上提出.(”, already proposed on CodeProject.)
说明(Explanation)
该代码分为两个不同的部分.第一个使用原始的绘图功能从头开始创建游戏图形(彩色砖块,球,球拍和背景图像).(The code is divided into two distinct parts. The first one creates games graphics (colored bricks, ball, racket and background image) from scratch, using the primitive drawing functions of the) CImg
图书馆.(Library.)
第二部分包括主事件循环,捕获用户事件并计算球/球拍运动和可能的碰撞.实际上,这里没有特别困难,但是所有内容都以紧凑的方式进行编码.(The second part consists of the main event loop, catching the user’s events and computing the ball/racket motion and the possible collisions. In fact, there’s nothing specially difficult here, but all is coded in quite a compact way.)
这是一个很好的方法,可以查看使用(This is a good way to see how simple it is to code small animations using the) CImg图书馆(CImg Library) .还值得注意的是,源代码是跨平台的,您可以在Unix或Mac OS X上进行编译而无需修改任何一行.我希望这可以为那些不愿意使用C ++源代码进行基本图像操作的相对代码复杂性的人提供一些参考.(. It is also worth noticing that the source is cross-platform and you may compile it on Unix or Mac OS X without modifying a single line. I hope this may give some idea for people that are discouraged because of the relative code complexity needed when one wants to do basic image operations inside C++ source codes.)
拟议的档案(Proposed Archive)
建议的存档包含游戏的小源代码(文件”(The proposed archive contains the small source code of the game (file ‘)breakout.cpp(breakout.cpp)'),('), the) CImg
库头文件’(Library header file ‘)浓度(CImg.h),编译所需的可执行文件(Win32)和用于编译的Visual Express 2005解决方案.因此,存档应该是独立的.(’ needed for the compilation, as well as the compiled executable (Win32) and the Visual Express 2005 solution used to compile. So, the archive should be self-contained.)
希望您会喜欢.(Hope you’ll enjoy it.)
历史(History)
- 23(23)rd(rd)2007年2月:初始职位(February, 2007: Initial post)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC7.0 VC7.1 VC6 WinXP Win2003 Win2K VS2005 Visual-Studio VS.NET2003 Dev 新闻 翻译