Class gridpp::GridEngine¶
ClassList > gridpp > GridEngine
建立視窗並管理遊戲物件、碰撞、繪製與主迴圈。
#include <GridEngine.h>
Public Static Attributes¶
| Type | Name |
|---|---|
| constexpr int | kMaxWindowSize = 8192 |
Public Functions¶
| Type | Name |
|---|---|
| void | AddOverlay (Overlay * overlay) 加入畫面覆蓋層並接管其所有權。 |
| void | ClearObjects () 刪除所有遊戲物件;不影響 Overlay 與已載入的素材。 |
| void | Destroy (GridObject * object) 刪除引擎擁有的物件。 |
| void | DrawCell (const std::string & asset_name, int grid_x, int grid_y, int direction=0, Color tint=WHITE) 在指定網格座標繪製素材;素材不存在時繪製紅色方塊。 |
| GridEngine (int cols, int rows, int grid_size=32) 建立遊戲引擎與視窗。 |
|
| GridEngine (const GridEngine & other) = delete |
|
| void | LoadAssets (const std::filesystem::path & database_path) 載入素材包並取代目前素材。 |
| void | Run () 執行遊戲主迴圈,直到視窗關閉。 |
| GridObject * | Spawn (GridObject * object) 將物件加入遊戲並接管其所有權。 |
| GridObject * | Spawn (const std::string & asset_name, int x, int y, CallbackGridObject::UpdateFn update, CallbackGridObject::CollideFn collide=nullptr) 建立並加入函式版物件。 |
| Color | background_color () const |
| int | cols () const |
| int | grid_size () const |
| GridEngine & | operator= (const GridEngine & other) = delete |
| int | rows () const |
| void | set_background_color (Color color) |
| void | set_show_grid (bool show) |
| bool | show_grid () const |
| ~GridEngine () |
Public Static Attributes Documentation¶
variable kMaxWindowSize¶
Public Functions Documentation¶
function AddOverlay¶
加入畫面覆蓋層並接管其所有權。
Parameters:
overlay使用new建立且尚未屬於任何引擎的 Overlay。
Exception:
std::invalid_argument若 overlay 是 nullptr。std::logic_error若 overlay 已屬於一個引擎。
function ClearObjects¶
刪除所有遊戲物件;不影響 Overlay 與已載入的素材。
function Destroy¶
刪除引擎擁有的物件。
主迴圈內呼叫時,物件會立即停止更新、碰撞與繪製,並在幀末釋放。
Parameters:
object要刪除的借用指標;nullptr 或不屬於此引擎的指標不會產生效果。
function DrawCell¶
在指定網格座標繪製素材;素材不存在時繪製紅色方塊。
inline void gridpp::GridEngine::DrawCell (
const std::string & asset_name,
int grid_x,
int grid_y,
int direction=0,
Color tint=WHITE
)
Parameters:
asset_name素材名稱。grid_x網格 x 座標。grid_y網格 y 座標。direction逆時針旋轉的 90 度倍數。tint繪製時套用的顏色。
function GridEngine [1/2]¶
建立遊戲引擎與視窗。
Parameters:
cols網格欄數。rows網格列數。grid_size每格的像素寬度與高度。
Exception:
std::invalid_argument若任一參數小於 1,或視窗寬、高超過 kMaxWindowSize。
function GridEngine [2/2]¶
function LoadAssets¶
載入素材包並取代目前素材。
Parameters:
database_path素材包路徑。
Exception:
std::runtime_error若檔案無法讀取或素材包格式無效。
function Run¶
執行遊戲主迴圈,直到視窗關閉。
function Spawn [1/2]¶
將物件加入遊戲並接管其所有權。
主迴圈外會立即呼叫 GridObject::OnSpawn()。主迴圈內加入的物件會在幀末呼叫 OnSpawn(),並從 下一幀開始更新、碰撞與繪製。
Parameters:
object使用new建立且尚未屬於任何引擎的物件。
Returns:
指向已加入物件的借用指標;呼叫端不可 delete。
Exception:
std::invalid_argument若 object 是 nullptr。std::logic_error若 object 已屬於一個引擎。
function Spawn [2/2]¶
建立並加入函式版物件。
inline GridObject * gridpp::GridEngine::Spawn (
const std::string & asset_name,
int x,
int y,
CallbackGridObject::UpdateFn update,
CallbackGridObject::CollideFn collide=nullptr
)
Parameters:
asset_name繪製時使用的素材名稱。x初始網格 x 座標。y初始網格 y 座標。update每幀呼叫的函式;可以是 nullptr。collide發生碰撞時呼叫的函式;可以是 nullptr。
Returns:
指向已加入物件的借用指標;呼叫端不可 delete。
function background_color¶
function cols¶
function grid_size¶
function operator=¶
function rows¶
function set_background_color¶
function set_show_grid¶
function show_grid¶
function ~GridEngine¶
The documentation for this class was generated from the following file GridEngine.h