@@ -49,112 +49,112 @@ e.g.
49
49
定義了每一個階梯物件,
50
50
51
51
52
- #### ` void rise()`
52
+ #### void rise()
53
53
每次執行 Game.cpp 的 `updating()` 函數中,會讓每個階梯執行一次 `rise()` 函數
54
54
55
- #### ` bool isOutOfScreen()`
55
+ #### bool isOutOfScreen()
56
56
Game 的 `updating()` 函數會對最上面的階梯呼叫此函數,檢查是否超出螢幕上方,如果超出會回傳 true
57
57
58
- #### ` void takeEffect()`
58
+ #### void takeEffect()
59
59
在玩家站上某一個階梯後,會呼叫該階梯的 `takeEffect()` 函數,此函數透過 `stair_type` 判斷自己的階梯種類,並做出對應的效果,詳細內容請參考 `Stair.cpp` 的函數實作
60
60
61
61
注意:若玩家一直站在該階梯上,`takeEffect()` 會被呼叫很多次
62
62
63
- #### ` Stair::Stair()`
63
+ #### Stair::Stair()
64
64
65
65
定義了創造 stair`的過程
66
66
67
67
遊戲每隔 `STAIR_GENERATE_PERIOD` (定義在 `Parameter.h` 中) 次數,就會互叫這個建構者(constructor)創造一個新的 stair
68
68
69
- #### ` StairType stair_type`
69
+ #### StairType stair\_type
70
70
決定這個 stair 的種類,所有的種類定義在 `Stair.h`
71
71
```cpp
72
72
enum StairType {
73
73
normal_stair, spike_stair, left_roll_stair, right_roll_stair,
74
74
NUM_OF_STAIR_TYPE // This value is intented to keep the number of elements in this enum.
75
75
};
76
76
```
77
- #### ` bool has_taken_effect`
77
+ #### bool has_taken_effect
78
78
79
79
如果這個 stair 已經被呼叫或一次 `takeEffect()`,則此值為 `true `
80
80
81
81
因為只要玩家站上某一個階梯後,便會不停呼叫該階梯的 `takeEffect()` 函,因此可以善加利用這個變數來避免重複執行很多次效果
82
82
83
- #### ` int width ()` and ` int height()`
83
+ #### int width () and int height()
84
84
85
85
回傳寬、高
86
86
87
87
## Player
88
88
89
- #### ` void moveLeft ()` and ` void moveRight()`
89
+ #### void moveLeft () and void moveRight()
90
90
91
91
player 向左右移動時,呼叫此函數,並根據 `left_moving_speed`、`right_moving_speed` 移動
92
92
93
- #### ` void fall ()`
93
+ #### void fall ()
94
94
95
95
player 沒有站在任何 stair 上,則執行 `fall()` 函數,根據 `falling_speed` 決定移動距離
96
96
97
- #### ` void rise ()`
97
+ #### void rise ()
98
98
99
99
player 站在任一 stair 上,`updating()` 不會執行 `fall()` 而會執行 `rise()`,讓 player 位置上升
100
100
101
101
102
- #### ` int width ()` and ` int height()`
102
+ #### int width () and int height()
103
103
104
104
回傳寬、高
105
105
106
106
## Game
107
107
108
- #### ` void updating ()`
108
+ #### void updating ()
109
109
110
110
本遊戲最重要的核心函數,每隔 `FRAME_DELAY` 毫秒會呼叫一次,處理所有遊戲邏輯
111
111
112
- #### ` int key`
112
+ #### int key
113
113
114
114
紀錄玩家按過的按鍵,在 `updating()` 的前半段可以看到如何判斷按鍵
115
115
116
- #### ` int elapsed_frames`
116
+ #### int elapsed\_frames
117
117
118
118
紀錄遊戲執行了幾次 `updating()` 函數,最大值為 2147483647 ,超過的話會變成負的
119
119
120
- #### ` Stair\* getStairWherePlayerStandingOn ()`
120
+ #### Stair\* getStairWherePlayerStandingOn ()
121
121
122
122
檢查玩家是否站在螢幕中某一個 stair 上,若有則回傳該 stair 的指標,若無則回傳 `nullptr`
123
123
124
- #### ` void reset ()`
124
+ #### void reset ()
125
125
126
126
在遊戲初次開始、玩家死亡時,會呼叫此函數
127
127
128
- #### ` void updatingStairs ()`
128
+ #### void updatingStairs ()
129
129
130
130
`updating()` 最後的步驟,處理所有 stair 的移動、刪除、產生
131
131
132
132
133
133
## 共通的函數
134
134
135
- #### ` int x ()`、` int y()`
135
+ #### int x ()、 int y()
136
136
137
137
回傳此物件的 x, y 值,物件如果是長方形的話會回傳左上角的頂演座標
138
138
139
- #### ` void setPos (int new_x , int new_y)`
139
+ #### void setPos (int new \_ x , int new \_ y)
140
140
141
141
將物件的位置設定到 ` (new_x, new_y) ` 座標上,** 所有物件的移動都是仰賴這個函數**
142
142
143
- #### ` setZValue(int order) `
143
+ #### setZValue(int order)
144
144
145
145
設定物件的 z 座標 z 座標越大會顯示的順序越前面,詳細定義在 ` Parameter.h ` 的 ` ITEM_ORDER ` 中,
146
146
147
- #### ` setPixmap(QPixmap("images/player.png").scaled(width, height)) `
147
+ #### setPixmap(QPixmap("images/player.png").scaled(width, height))
148
148
149
149
將目前的物件圖片換成 ` images/player.png ` ,並把圖片縮放成指定的寬(width)高(height)
150
150
151
151
注意:Score, Health 不能使用此函數
152
152
153
- #### ` extern Game * game; `
153
+ #### extern Game * game;
154
154
155
155
只要程式開頭全域變數的地方加上這個,並 ` #include "Game.h" ` ,就能透過以下函數操作各個物件:
156
156
157
- ```
157
+ ``` cpp
158
158
game->health->getHealth ()
159
159
game->score->getScore()
160
160
game->player->setPos(94, 87)
0 commit comments