从零开始的纪念碑谷引擎复刻:(一)
前言:何为Ebitengine
超简单
In Ebitengine, everything is an image: the screen, data from an image file, and even offscreen items are all represented as image objects. Most rendering operations consist of drawing one image on top of another.
在Ebitengine中,一切都只是一张图片:不论是图像文件中的画面和数据,亦或是不在画面中的物品,都以图片数据格式组织。大多数渲染操作都只是在一张图片上绘制另一张图片
跨平台
Ebitengine games work on desktop (Windows, macOS, Linux, and FreeBSD), web browsers (through WebAssembly), and even on mobile (Android and iOS)! Plus, Ebitengine is implemented in pure Go on Windows, so Windows developers do not need to install a C compiler. Nintendo Switch™ is also supported!
Ebitengine游戏支持桌面端(Windows、MacOS、Linux和FreeBSD),浏览器(通过WASM)和手机端(安卓和苹果)。此外,由于Ebitengine完全由Go编写,所以Windows开发者不需要额外安装C语言编译器。任天堂也是支持的噢!
高性能
While Ebitengine's drawing API is very simple, Ebitengine games run very fast with GPU power. Multiple images are integrated into a texture atlas internally, and drawing operations are automatically performed in batch when possible.
Ebitengine不仅有着超简单的图形绘制API,还能借助GPU的算力跑得飞快。引擎内部会将多张图像整合成一张,并尽可能地自动批量绘制
蓄势待发
Ebitengine has been used to develop production-level games. One such example is Bear's Restaurant, a mobile application that has been downloaded over 1,000,000 times.
Ebitengine已被用于开发生产级别的游戏。比如棕熊餐厅这款下载量已达一百万次的移动端游戏
Hello Rhombus(菱形)
等距投影
纪念碑谷所使用的投影方式是正交投影中的等距投影,而Ebitengine是2D引擎。这里需要从三维逻辑坐标(以z作为逻辑深度)映射至二维坐标
X = (x - z) cos(θ) ; \newline
Y = (x + z) sin(θ) + y
M = \begin{bmatrix}
cos(alpha) & 0 & -cos(alpha) \\
sin(alpha) & 1 & sin(alpha)
\end
\begin{bmatrix}
x \\
y \\
z
\end{bmatrix}
\cdot
\begin{bmatrix}
cos(alpha) & 0 & -cos(alpha) \\
sin(alpha) & 1 & sin(alpha)
\end
\begin{bmatrix}
x\cdot cos(alpha) & 0 & -z\cdot cos(alpha) \\
x\cdot sin(alpha) & y & -z\cdot sin(alpha)
\end