質問編集履歴

2

提示コードを追加

2021/02/09 06:42

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -62,14 +62,336 @@
62
62
 
63
63
 
64
64
 
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
65
  }
74
66
 
75
67
  ```
68
+
69
+
70
+
71
+ ```cpp
72
+
73
+ #ifndef ___STAGE_HPP_
74
+
75
+ #define ___STAGE_HPP_
76
+
77
+
78
+
79
+ #include "MapObject.hpp"
80
+
81
+ #include "Object.hpp"
82
+
83
+ #include "../Entry.hpp"
84
+
85
+
86
+
87
+
88
+
89
+ #include <iostream>
90
+
91
+
92
+
93
+ // 画面のセルの数
94
+
95
+ #define SCREEN_WIDTH_CELL ((int)((int)SCREEN_WIDTH / CELL))
96
+
97
+ #define SCREEN_HEIGHT_CELL ((int)((int)SCREEN_HEIGHT / CELL))
98
+
99
+
100
+
101
+
102
+
103
+ class Stage : Actor_2D
104
+
105
+ {
106
+
107
+ public:
108
+
109
+ Stage(Entry* e);
110
+
111
+
112
+
113
+ ~Stage();
114
+
115
+
116
+
117
+ void Update() override;
118
+
119
+ void Draw()override;
120
+
121
+
122
+
123
+ std::vector<MapObject> getMapObject(); //マップオブジェクトを取得
124
+
125
+
126
+
127
+ private:
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+ std::vector<MapObject> Area;
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+ };
144
+
145
+
146
+
147
+ #endif;
148
+
149
+
150
+
151
+ ```
152
+
153
+
154
+
155
+ ```cpp
156
+
157
+ #include "../../Header/Game/Stage.hpp"
158
+
159
+
160
+
161
+
162
+
163
+ //コンストラクタ
164
+
165
+ Stage::Stage(Entry* e) : Actor_2D()
166
+
167
+ {
168
+
169
+
170
+
171
+ std::shared_ptr<TextureData> sprite = LoadTexture("Assets/Block.png");
172
+
173
+ std::shared_ptr<TextureData> Item_sprite = LoadTexture("Assets/Item.png");
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+ // printf("X: %f\n", SCREEN_WIDTH / (float)CELL);
182
+
183
+ // printf("Y: %f\n",SCREEN_HEIGHT / (float)CELL);
184
+
185
+
186
+
187
+
188
+
189
+ // ステージ
190
+
191
+ int Map[SCREEN_HEIGHT_CELL][SCREEN_WIDTH_CELL] =
192
+
193
+ {
194
+
195
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
196
+
197
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
198
+
199
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
200
+
201
+ {0,0,0,0,0,0,3,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
202
+
203
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
204
+
205
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0},
206
+
207
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
208
+
209
+ {0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
210
+
211
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0},
212
+
213
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
214
+
215
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
216
+
217
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
218
+
219
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0},
220
+
221
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
222
+
223
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
224
+
225
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
226
+
227
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
228
+
229
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
230
+
231
+ };
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+ for (int y = 0; y < SCREEN_HEIGHT_CELL; y++)
240
+
241
+ {
242
+
243
+ for (int x = 0; x < SCREEN_WIDTH_CELL; x++)
244
+
245
+ {
246
+
247
+
248
+
249
+ // ブロック
250
+
251
+ if (Map[y][x] == 1)
252
+
253
+ {
254
+
255
+ Box_Collision_2D col;
256
+
257
+ col.setEnable(true);
258
+
259
+ col.setPosition(glm::ivec2(CELL * x,( -CELL * y)));
260
+
261
+ col.setSize(glm::ivec2(CELL, CELL));
262
+
263
+ TextureUV uv;
264
+
265
+ uv.start = glm::vec2(0, 0);
266
+
267
+ uv.end = glm::vec2(CELL, CELL);
268
+
269
+
270
+
271
+ Area.push_back(MapObject(e, ObjectType::Brick, sprite, uv, glm::ivec2(CELL * x, (-CELL * y)), col));
272
+
273
+
274
+
275
+ //レンガ
276
+
277
+ }else if (Map[y][x] == 2)
278
+
279
+ {
280
+
281
+ Box_Collision_2D col;
282
+
283
+ col.setEnable(true);
284
+
285
+ col.setPosition(glm::ivec2(CELL * x, (-CELL * y)));
286
+
287
+ col.setSize(glm::ivec2(CELL, CELL));
288
+
289
+ TextureUV uv;
290
+
291
+ uv.start = glm::vec2(CELL, CELL);
292
+
293
+ uv.end = glm::vec2(CELL * 2, CELL * 2);
294
+
295
+
296
+
297
+ Area.push_back(MapObject(e, ObjectType::Block, sprite, uv, glm::ivec2(CELL * x, (-CELL * y)), col));
298
+
299
+ }
300
+
301
+
302
+
303
+ // アイテム
304
+
305
+ else if (Map[y][x] == 3)
306
+
307
+ {
308
+
309
+
310
+
311
+ Box_Collision_2D col;
312
+
313
+ col.setEnable(true);
314
+
315
+ col.setPosition(glm::ivec2(CELL * x, (-CELL * y)));
316
+
317
+ col.setSize(glm::ivec2(CELL, CELL));
318
+
319
+ TextureUV uv;
320
+
321
+ uv.start = glm::vec2(0, 0);
322
+
323
+ uv.end = glm::vec2(CELL , CELL);
324
+
325
+
326
+
327
+ Area.push_back(MapObject(e, ObjectType::Item, Item_sprite, uv, glm::ivec2(CELL * x, (-CELL * y)), col));
328
+
329
+ }
330
+
331
+ }
332
+
333
+ }
334
+
335
+ }
336
+
337
+
338
+
339
+
340
+
341
+ std::vector<MapObject> Stage::getMapObject()
342
+
343
+ {
344
+
345
+ return Area;
346
+
347
+ }
348
+
349
+
350
+
351
+
352
+
353
+ void Stage::Update()
354
+
355
+ {
356
+
357
+ for (std::vector<MapObject>::iterator itr = Area.begin(); itr != Area.end(); itr++)
358
+
359
+ {
360
+
361
+ itr->Update();
362
+
363
+ }
364
+
365
+ }
366
+
367
+
368
+
369
+ void Stage::Draw()
370
+
371
+ {
372
+
373
+ for (std::vector<MapObject>::iterator itr = Area.begin(); itr != Area.end(); itr++)
374
+
375
+ {
376
+
377
+ itr->Draw();
378
+
379
+ }
380
+
381
+ }
382
+
383
+
384
+
385
+ //デストラクタ
386
+
387
+ Stage::~Stage()
388
+
389
+ {
390
+
391
+
392
+
393
+ }
394
+
395
+
396
+
397
+ ```

1

文章を修正

2021/02/09 06:42

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 提示コードですが。コメント部のコードでアクセスエラーになります。どうすればいいのでしょうか?
1
+ 提示コードですが。コメント部のコードでアクセスエラーになります。どうすればいいのでしょうか?stage->getMapObject();はマップのベクターなのですがその要素を指定した要素を削除するコードなのですが削除する例外が出てしまいます。どうすればいいのでしょか?
2
2
 
3
3
 
4
4