質問編集履歴

1

2019/08/10 17:19

投稿

carnage0216
carnage0216

スコア194

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,260 @@
1
+ 以下はコード全体です。
2
+
3
+ ```
4
+
5
+ #include "DxLib.h"
6
+
7
+
8
+
9
+ // コマの横/縦数
10
+
11
+ #define FRAME_WIDTH 5
12
+
13
+ #define FRAME_HEIGHT 5
14
+
15
+
16
+
17
+ // コマの描画幅/高さ
18
+
19
+ #define CELL_WIDTH 49
20
+
21
+ #define CELL_HEIGHT 66
22
+
23
+
24
+
25
+ // 描画マージン
26
+
27
+ #define FIELD_MARGIN_X 50
28
+
29
+ #define FIELD_MARGIN_Y 50
30
+
31
+
32
+
33
+ typedef struct Player_t {
34
+
35
+ int x;
36
+
37
+ int y;
38
+
39
+ int handle;
40
+
41
+ } Player;
42
+
43
+
44
+
45
+ // コマ(x,y)に外枠を描く[おまけ]
46
+
47
+ int box_draw(int x, int y) {
48
+
49
+ return DrawBox(x * CELL_WIDTH + FIELD_MARGIN_X, y * CELL_HEIGHT + FIELD_MARGIN_Y,
50
+
51
+ (x + 1) * CELL_WIDTH + FIELD_MARGIN_X, (y + 1) * CELL_HEIGHT + FIELD_MARGIN_Y,
52
+
53
+ GetColor(255, 255, 255), FALSE);
54
+
55
+ }
56
+
57
+
58
+
59
+ // コマ(x,y)に画像を描く
60
+
61
+ int cell_draw(int x, int y, int handle) {
62
+
63
+ return DrawGraph(x * CELL_WIDTH + FIELD_MARGIN_X, y * CELL_HEIGHT + FIELD_MARGIN_Y, handle, FALSE);
64
+
65
+ }
66
+
67
+
68
+
69
+ int Key[256]; // キーが押されているフレーム数を格納する
70
+
71
+
72
+
73
+ // キーの入力状態を更新する
74
+
75
+ int gpUpdateKey() {
76
+
77
+ char tmpKey[256]; // 現在のキーの入力状態を格納する
78
+
79
+ GetHitKeyStateAll(tmpKey); // 全てのキーの入力状態を得る
80
+
81
+ for (int i = 0; i < 256; i++) {
82
+
83
+ if (tmpKey[i] != 0) { // i番のキーコードに対応するキーが押されていたら
84
+
85
+ Key[i]++; // 加算
86
+
87
+ }
88
+
89
+ else { // 押されていなければ
90
+
91
+ Key[i] = 0; // 0にする
92
+
93
+ }
94
+
95
+ }
96
+
97
+ return 0;
98
+
99
+ }
100
+
101
+
102
+
103
+ void Player_update(Player* p) {
104
+
105
+ int dx = 0;
106
+
107
+ int dy = 0;
108
+
109
+
110
+
111
+ if (Key[KEY_INPUT_RIGHT] == 1) {
112
+
113
+ dx = dx + 1;
114
+
115
+ p->handle = 2;
116
+
117
+ }
118
+
119
+ if (Key[KEY_INPUT_LEFT] == 1) {
120
+
121
+ dx = dx - 1;
122
+
123
+ p->handle = 1;
124
+
125
+ }
126
+
127
+ if (Key[KEY_INPUT_UP] == 1) {
128
+
129
+ dy = dy - 1;
130
+
131
+ p->handle = 5;
132
+
133
+ }
134
+
135
+ if (Key[KEY_INPUT_DOWN] == 1) {
136
+
137
+ dy = dy + 1;
138
+
139
+ p->handle = 11;
140
+
141
+ }
142
+
143
+ if (dx == 0 && dy == 0) {
144
+
145
+ p->handle = 8;
146
+
147
+ }
148
+
149
+
150
+
151
+ /* 新たな位置へ移動可能であるならplayerの位置を更新する */
152
+
153
+ int newX = p->x + dx;
154
+
155
+ int newY = p->y + dy;
156
+
157
+ if (0 <= newX && newX < FRAME_WIDTH && 0 <= newY && newY < FRAME_HEIGHT) {
158
+
159
+ p->x = newX;
160
+
161
+ p->y = newY;
162
+
163
+ }
164
+
165
+ else {
166
+
167
+ p->handle = 8; // 動けないなら正面を向く
168
+
169
+ }
170
+
171
+ }
172
+
173
+
174
+
175
+ void Player_draw(const Player* p, const int* gh) {
176
+
177
+ cell_draw(p->x, p->y, gh[p->handle]);
178
+
179
+ }
180
+
181
+
182
+
183
+ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
184
+
185
+ SetGraphMode(1300, 680, 32); // ウィンドウの大きさを指定
186
+
187
+ ChangeWindowMode(TRUE);
188
+
189
+
190
+
191
+ if (DxLib_Init() == -1) {
192
+
193
+ return -1;
194
+
195
+ }
196
+
197
+
198
+
199
+ //グラフィックハンドル格納用配列
200
+
201
+ int gh[12];
202
+
203
+ LoadDivGraph("charall.png", 12, 3, 4, 49, 66, gh);
204
+
205
+
206
+
207
+ Player player;
208
+
209
+ player.x = FRAME_WIDTH / 2;
210
+
211
+ player.y = FRAME_HEIGHT / 2;
212
+
213
+
214
+
215
+ SetDrawScreen(DX_SCREEN_BACK);
216
+
217
+
218
+
219
+ while (ProcessMessage() == 0) {
220
+
221
+ gpUpdateKey();
222
+
223
+
224
+
225
+ Player_update(&player);
226
+
227
+
228
+
229
+ // ここから表現
230
+
231
+ ClearDrawScreen();
232
+
233
+ for (int x = 0; x < FRAME_WIDTH; ++x)
234
+
235
+ for (int y = 0; y < FRAME_HEIGHT; ++y)
236
+
237
+ box_draw(x, y);
238
+
239
+ Player_draw(&player, gh);
240
+
241
+ ScreenFlip();
242
+
243
+ }
244
+
245
+
246
+
247
+ DxLib_End();
248
+
249
+ return 0;
250
+
251
+ }
252
+
253
+ ```
254
+
255
+
256
+
1
- 書くプログラムを解読したいと思い質問します。
257
+ プログラムを解読したいと思い質問します。
2
258
 
3
259
  1、
4
260
 
@@ -16,7 +272,7 @@
16
272
 
17
273
  ```
18
274
 
19
- 関数void Player_updateが引数に関数Player* pを持ってきて、int型の変数dxは4バイトを占める値0とint型の変数dyは4バイトを占める値0に引数である関数Player* pを渡しますと思いますが、この関数Player* p自体が何を持った関数かなのかわからないのですが、なんでしょうか?①
275
+ 関数void Player_updateが引数に関数Player* pを持ってきて、int型の変数dx値0とint型の変数dy値0に引数である関数Player* pを渡すと思いますが、この関数Player* p自体が何を持った関数かなのかわからないのですが、なんでしょうか?①
20
276
 
21
277
 
22
278