質問編集履歴
2
更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -686,6 +686,10 @@
|
|
686
686
|
|
687
687
|
```c
|
688
688
|
|
689
|
+
```c
|
690
|
+
|
691
|
+
```c
|
692
|
+
|
689
693
|
|
690
694
|
|
691
695
|
#include "../PlayScene/Utility.h"
|
@@ -1074,15 +1078,11 @@
|
|
1074
1078
|
|
1075
1079
|
}
|
1076
1080
|
|
1077
|
-
|
1081
|
+
|
1078
1082
|
|
1079
1083
|
```
|
1080
1084
|
|
1081
|
-
|
1085
|
+
|
1082
|
-
|
1083
|
-
```
|
1084
|
-
|
1085
|
-
```
|
1086
1086
|
|
1087
1087
|
|
1088
1088
|
|
1
ミス
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,49 +1,1091 @@
|
|
1
|
+
```c
|
2
|
+
|
3
|
+
#include<math.h> //計算のh
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
#include "Player.h"
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
#include"../GameMain.h"
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
//プレイヤーの状態
|
18
|
+
|
19
|
+
enum PLAYER_STATE
|
20
|
+
|
21
|
+
{
|
22
|
+
|
23
|
+
PLAYER_STATE_ACTIVE, //操作できる状態
|
24
|
+
|
25
|
+
PLAYER_STATE_BOMB, //やられ状態
|
26
|
+
|
27
|
+
};
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
//飛行機の画像切り取り情報
|
32
|
+
|
33
|
+
#define PLAYER_RECT_X1 0
|
34
|
+
|
35
|
+
#define PLAYER_RECT_Y1 0
|
36
|
+
|
37
|
+
#define PLAYER_RECT_X2 32
|
38
|
+
|
39
|
+
#define PLAYER_RECT_Y2 32
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
//移動スピード
|
44
|
+
|
45
|
+
#define PLAYER_VEL 3.0f
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
//弾の発射感覚
|
50
|
+
|
51
|
+
#define PLAYER_BULLET_INTERVAL 5
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
//初期の残機
|
56
|
+
|
57
|
+
#define PLAYER_STOCK_DEFAULT 3
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
//プレイヤーの当たり判定
|
62
|
+
|
63
|
+
#define PLAYER_RADIUS 5.0f
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
// プレイヤーのジャンプ力
|
68
|
+
|
69
|
+
#define PLAYER_JUMP -15.0f;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
// プレイヤーの偽重力
|
74
|
+
|
75
|
+
#define PLAYER_GRAVITY 0.1f
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
/*---------------------------
|
82
|
+
|
83
|
+
初期化
|
84
|
+
|
85
|
+
----------------------------*/
|
86
|
+
|
87
|
+
void Player::Initialize(int textureHandle, BulletManager* pBulletManager)
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
//状態の初期化
|
92
|
+
|
93
|
+
mState = PLAYER_STATE_ACTIVE;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
//画像の設定
|
98
|
+
|
99
|
+
/*mSprite.SetTexture(textureHandle);
|
100
|
+
|
101
|
+
mSprite.src.x = PLAYER_RECT_X1;
|
102
|
+
|
103
|
+
mSprite.src.y = PLAYER_RECT_Y1;
|
104
|
+
|
105
|
+
mSprite.size.x = PLAYER_RECT_X2;
|
106
|
+
|
107
|
+
mSprite.size.y = PLAYER_RECT_Y2;*/
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
mSprite.SetTexture(textureHandle);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
mSprite.src.x = 0;
|
118
|
+
|
119
|
+
mSprite.src.y = 64;
|
120
|
+
|
121
|
+
mSprite.size.x = PLAYER_RECT_X2;
|
122
|
+
|
123
|
+
mSprite.size.y = PLAYER_RECT_Y2;
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
mSprite.scale.x = 1.0f;
|
130
|
+
|
131
|
+
mSprite.scale.y = 1.0f;
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
mSprite.alpha = 1.0f;
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
//画像に座標を反映
|
148
|
+
|
149
|
+
mSprite.pos.x = mPos.x;
|
150
|
+
|
151
|
+
mSprite.pos.y = mPos.y;
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
//弾の管理者のポインタ(連絡先)を保存
|
156
|
+
|
157
|
+
mpBulletManager = pBulletManager;
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
//弾の発射感覚管理用タイマーの初期化
|
164
|
+
|
165
|
+
mShootIntervalTimer = 0;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
//残機の初期化
|
170
|
+
|
171
|
+
mStock = PLAYER_STOCK_DEFAULT;
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
//爆破用タイマーの初期化
|
176
|
+
|
177
|
+
mBombTimer = 0;
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
//pleyer無敵時間用のタイマー
|
182
|
+
|
183
|
+
mPTimer = 0;
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
//モーションタイマー
|
188
|
+
|
189
|
+
mMotionTimer = 0;
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
//当たり判定の初期化
|
194
|
+
|
195
|
+
mCollision.mRadius = PLAYER_RADIUS;
|
196
|
+
|
197
|
+
mCollision.mPos.x = mPos.x;
|
198
|
+
|
199
|
+
mCollision.mPos.y = mPos.y;
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
////初期座標の設定
|
206
|
+
|
207
|
+
mPos.x = SCREEN_LEFT - 100;
|
208
|
+
|
209
|
+
mPos.y = 240;
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
//mPosX = SCREEN_CENTER_X;
|
214
|
+
|
215
|
+
//mPosY = SCREEN_CENTER_X; // 適当な数字
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
mVelX = 0.0f;
|
222
|
+
|
223
|
+
mVelY = 0.0f;
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
mIsJump = FALSE;
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
/*--------------------------------
|
236
|
+
|
237
|
+
更新
|
238
|
+
|
239
|
+
-------------------------------*/
|
240
|
+
|
241
|
+
void Player::Update(void)
|
242
|
+
|
243
|
+
{
|
244
|
+
|
245
|
+
switch (mState)
|
246
|
+
|
247
|
+
{
|
248
|
+
|
249
|
+
//操作できる状態 =============
|
250
|
+
|
251
|
+
case PLAYER_STATE_ACTIVE:
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
if (mMotionTimer <= 20) //タイマーが20より上になるまでタイマーを進める
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
mMotionTimer++;
|
260
|
+
|
261
|
+
mPos.x += mMotionTimer; //プレイヤーのx座標を増やす
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
else if (mMotionTimer >= 20)
|
268
|
+
|
269
|
+
{
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
//タイマー処理
|
280
|
+
|
281
|
+
++mShootIntervalTimer %= PLAYER_BULLET_INTERVAL;
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
// 移動処理
|
286
|
+
|
287
|
+
Move();
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
//弾の発射処理
|
292
|
+
|
293
|
+
if (mShootIntervalTimer == 1 && IsButtonDown(PAD_INPUT_1) == TRUE)
|
294
|
+
|
295
|
+
{
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
mpBulletManager->Shot(BULLET_TYPE_PLAYER_NORMAL,
|
300
|
+
|
301
|
+
SHOOTER_TYPE_PLAYER, mPos);
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
PlaySoundMem(mShooting1, DX_PLAYTYPE_BACK); //弾発射で音再生
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
if (mShootIntervalTimer == 0 && IsButtonDown(PAD_INPUT_2) == TRUE)//
|
316
|
+
|
317
|
+
{
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
mpBulletManager->Shot(BULLET_TYPE_PLAYER_POWER_LEFT, //
|
322
|
+
|
323
|
+
SHOOTER_TYPE_PLAYER, mPos);
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
PlaySoundMem(mShooting2, DX_PLAYTYPE_BACK); //弾発射で音再生//
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
if (mShootIntervalTimer == 0 && IsButtonDown(PAD_INPUT_3) == TRUE)//
|
336
|
+
|
337
|
+
{
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
mpBulletManager->Shot(BULLET_TYPE_PLAYER_POWER_RIGHT, //
|
342
|
+
|
343
|
+
SHOOTER_TYPE_PLAYER, mPos);
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
PlaySoundMem(mShooting2, DX_PLAYTYPE_BACK); //弾発射で音再生//
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
break;
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
//やられ状態 =====================
|
362
|
+
|
363
|
+
case PLAYER_STATE_BOMB:
|
364
|
+
|
365
|
+
{
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
//タイマーをすすめる
|
370
|
+
|
371
|
+
mBombTimer++;
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
if (mBombTimer == 5)
|
378
|
+
|
379
|
+
{
|
380
|
+
|
381
|
+
mSprite.src.x = 48; //切り取り座標のx
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
else if (mBombTimer == 10)
|
386
|
+
|
387
|
+
{
|
388
|
+
|
389
|
+
mSprite.src.x = 64;
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
else if (mBombTimer == 15)
|
394
|
+
|
395
|
+
{
|
396
|
+
|
397
|
+
mSprite.src.x = 80;
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
else if (mBombTimer == 20)
|
404
|
+
|
405
|
+
{
|
406
|
+
|
407
|
+
mSprite.alpha = 0.0f;
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
else if (mBombTimer >= 40)//mSprite.alpha=0.0f
|
412
|
+
|
413
|
+
{
|
414
|
+
|
415
|
+
mSprite.src.x = PLAYER_RECT_X1;
|
416
|
+
|
417
|
+
mSprite.src.y = PLAYER_RECT_Y1;
|
418
|
+
|
419
|
+
mSprite.size.x = PLAYER_RECT_X2;
|
420
|
+
|
421
|
+
mSprite.size.y = PLAYER_RECT_Y2;
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
mSprite.scale.x = 1.0f;
|
426
|
+
|
427
|
+
mSprite.scale.y = 1.0f;
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
mSprite.alpha = 1.0f;
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
//爆発タイマーの初期化
|
436
|
+
|
437
|
+
mBombTimer = 0;
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
//操作可能状態へ
|
442
|
+
|
443
|
+
mState = PLAYER_STATE_ACTIVE;
|
444
|
+
|
445
|
+
}
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
break;
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
//画像に座標を反映
|
458
|
+
|
459
|
+
mSprite.pos.x = mPos.x;
|
460
|
+
|
461
|
+
mSprite.pos.y = mPos.y;
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
//当たり判定に座標を反映
|
466
|
+
|
467
|
+
mCollision.mPos.x = mPos.x;
|
468
|
+
|
469
|
+
mCollision.mPos.y = mPos.y;
|
470
|
+
|
471
|
+
}
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
/*-----------------------------------------
|
476
|
+
|
477
|
+
描画
|
478
|
+
|
479
|
+
----------------------------------------*/
|
480
|
+
|
481
|
+
void Player::Draw(void)
|
482
|
+
|
483
|
+
{
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
//自機の表示
|
488
|
+
|
489
|
+
mSprite.Draw();
|
490
|
+
|
491
|
+
}
|
492
|
+
|
493
|
+
/*----------------------------------
|
494
|
+
|
495
|
+
プレイヤーの移動処理
|
496
|
+
|
497
|
+
----------------------------------*/
|
498
|
+
|
499
|
+
void Player::Move(void)
|
500
|
+
|
501
|
+
{
|
502
|
+
|
503
|
+
/*if (IsButtonDown(PAD_INPUT_10) == TRUE)
|
504
|
+
|
505
|
+
{
|
506
|
+
|
507
|
+
mPos.x = 0.0f;
|
508
|
+
|
509
|
+
mPos.y = 0.0f;
|
510
|
+
|
511
|
+
}*/
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
// 移動処理
|
516
|
+
|
517
|
+
if (IsButtonDown(PAD_INPUT_LEFT) == TRUE)
|
518
|
+
|
519
|
+
{
|
520
|
+
|
521
|
+
mPTimer++;
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
if (mPTimer == 0) {
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
mSprite.src.x = 32;
|
530
|
+
|
531
|
+
mSprite.src.y = 32;
|
532
|
+
|
533
|
+
}
|
534
|
+
|
535
|
+
else if (mPTimer == 15) {
|
536
|
+
|
537
|
+
mSprite.src.x = 64;
|
538
|
+
|
539
|
+
mSprite.src.y = 32;
|
540
|
+
|
541
|
+
}
|
542
|
+
|
543
|
+
else if (mPTimer >= 30) {
|
544
|
+
|
545
|
+
mSprite.src.x = 0;
|
546
|
+
|
547
|
+
mSprite.src.y = 32;
|
548
|
+
|
549
|
+
mSprite.size.x = PLAYER_RECT_X2;
|
550
|
+
|
551
|
+
mSprite.size.y = PLAYER_RECT_Y2;
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
mSprite.scale.x = 1.0f;
|
558
|
+
|
559
|
+
mSprite.scale.y = 1.0f;
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
mSprite.alpha = 1.0f;
|
564
|
+
|
565
|
+
mPTimer = 0;
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
}
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
mVelX = -PLAYER_VEL;
|
578
|
+
|
579
|
+
}
|
580
|
+
|
581
|
+
else if (IsButtonDown(PAD_INPUT_RIGHT) == TRUE)
|
582
|
+
|
583
|
+
{
|
584
|
+
|
585
|
+
mPTimer++;
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
if(mPTimer==0)
|
590
|
+
|
591
|
+
mSprite.src.x =32;
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
else if (mPTimer == 15)
|
596
|
+
|
597
|
+
mSprite.src.x = 64;
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
else if (mPTimer >= 30) {
|
602
|
+
|
603
|
+
mSprite.src.x = 0;
|
604
|
+
|
605
|
+
mSprite.src.y = 64;
|
606
|
+
|
607
|
+
mSprite.size.x = PLAYER_RECT_X2;
|
608
|
+
|
609
|
+
mSprite.size.y = PLAYER_RECT_Y2;
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
mSprite.scale.x = 1.0f;
|
616
|
+
|
617
|
+
mSprite.scale.y = 1.0f;
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
mSprite.alpha = 1.0f;
|
622
|
+
|
623
|
+
mPTimer = 0;
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
}
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
mVelX = PLAYER_VEL;
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
}
|
640
|
+
|
641
|
+
else if (IsButtonDown(PAD_INPUT_UP) == TRUE) //上キーが押されているときは重力を0にする
|
642
|
+
|
643
|
+
{
|
644
|
+
|
645
|
+
mPos.y += -PLAYER_VEL;
|
646
|
+
|
647
|
+
mVelY = 0;
|
648
|
+
|
649
|
+
|
650
|
+
|
651
|
+
}
|
652
|
+
|
653
|
+
else if (IsButtonDown(PAD_INPUT_UP) == FALSE) //上キーが押されていないときに重力をかける
|
654
|
+
|
655
|
+
{
|
656
|
+
|
657
|
+
mVelY += PLAYER_GRAVITY;
|
658
|
+
|
659
|
+
|
660
|
+
|
661
|
+
}
|
662
|
+
|
663
|
+
|
664
|
+
|
665
|
+
|
666
|
+
|
667
|
+
else if (IsButtonDown(PAD_INPUT_DOWN) == TRUE)
|
668
|
+
|
669
|
+
{
|
670
|
+
|
671
|
+
mPos.y += PLAYER_VEL;
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
}
|
676
|
+
|
677
|
+
else
|
678
|
+
|
679
|
+
{
|
680
|
+
|
681
|
+
mVelX = 0.0f;
|
682
|
+
|
683
|
+
}
|
684
|
+
|
685
|
+
**↓ヘッダー**
|
686
|
+
|
687
|
+
```c
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
#include "../PlayScene/Utility.h"
|
692
|
+
|
693
|
+
#include "Database.h"
|
694
|
+
|
695
|
+
#include "Collision.h"
|
696
|
+
|
697
|
+
|
698
|
+
|
699
|
+
//前方宣言
|
700
|
+
|
701
|
+
struct Player; //
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
//弾を発射した対象
|
708
|
+
|
709
|
+
enum SHOOTER_TYPE
|
710
|
+
|
711
|
+
{
|
712
|
+
|
713
|
+
SHOOTER_TYPE_PLAYER, //プレイヤー
|
714
|
+
|
715
|
+
SHOOTER_TYPE_ENEMY, //敵
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
SHOOTER_TYPE_NUM, //発射対象の総数
|
720
|
+
|
721
|
+
};
|
722
|
+
|
723
|
+
|
724
|
+
|
725
|
+
struct Bullet
|
726
|
+
|
727
|
+
{
|
728
|
+
|
729
|
+
//変数=========================-
|
730
|
+
|
731
|
+
|
732
|
+
|
733
|
+
//弾の種類
|
734
|
+
|
735
|
+
int mBulletType;
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
//発射対象
|
740
|
+
|
741
|
+
int mShooterType;
|
742
|
+
|
743
|
+
|
744
|
+
|
745
|
+
//画像描画構造体
|
746
|
+
|
747
|
+
SpriteData mSprite;
|
748
|
+
|
749
|
+
|
750
|
+
|
751
|
+
//座標
|
752
|
+
|
753
|
+
Float2 mPos;
|
754
|
+
|
755
|
+
|
756
|
+
|
757
|
+
//速度
|
758
|
+
|
759
|
+
Float2 mVel;
|
760
|
+
|
761
|
+
|
762
|
+
|
763
|
+
//使用されているかのフラグ
|
764
|
+
|
765
|
+
BOOL mIsActive;
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
//威力
|
770
|
+
|
771
|
+
int mPower;
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
//円の当たり判定情報
|
776
|
+
|
777
|
+
CircleCollider mCollision;
|
778
|
+
|
779
|
+
|
780
|
+
|
781
|
+
|
782
|
+
|
783
|
+
|
784
|
+
|
785
|
+
|
786
|
+
|
787
|
+
|
788
|
+
|
789
|
+
|
790
|
+
|
791
|
+
//関数======================
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
//初期化
|
796
|
+
|
797
|
+
void Initialize(int textureHandle, int bulletType, int shooterType, Float2
|
798
|
+
|
799
|
+
pos);
|
800
|
+
|
801
|
+
|
802
|
+
|
803
|
+
//更新
|
804
|
+
|
805
|
+
void Update(void);
|
806
|
+
|
807
|
+
|
808
|
+
|
809
|
+
//描画
|
810
|
+
|
811
|
+
void Draw(void);
|
812
|
+
|
813
|
+
};
|
814
|
+
|
815
|
+
```c
|
816
|
+
|
817
|
+
|
818
|
+
|
819
|
+
#include "Bullet.h"
|
820
|
+
|
821
|
+
|
822
|
+
|
823
|
+
#include "../GameMain.h"
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
#include "../PlayScene/Player.h"//
|
828
|
+
|
829
|
+
|
830
|
+
|
831
|
+
|
832
|
+
|
833
|
+
|
834
|
+
|
835
|
+
// 弾が生存している画面外プラスαの範囲
|
836
|
+
|
837
|
+
#define BULLET_ALIVE_AREA 50
|
838
|
+
|
839
|
+
#define SECOND 2
|
840
|
+
|
841
|
+
/*-----------------------------------
|
842
|
+
|
843
|
+
初期化
|
844
|
+
|
845
|
+
引数 :int textureHandle(弾の画像ハンドル)、 int bulletType(弾の種類),
|
846
|
+
|
847
|
+
Float2 pos(弾の座標)
|
848
|
+
|
849
|
+
---------------------------------*/
|
850
|
+
|
851
|
+
void Bullet::Initialize(int textureHandle, int bulletType, int shooterType,
|
852
|
+
|
853
|
+
Float2 pos)
|
854
|
+
|
855
|
+
{
|
856
|
+
|
857
|
+
//弾の種類を保存
|
858
|
+
|
859
|
+
mBulletType = bulletType;
|
860
|
+
|
861
|
+
|
862
|
+
|
863
|
+
//発射対象の保存
|
864
|
+
|
865
|
+
mShooterType = shooterType;
|
866
|
+
|
867
|
+
|
868
|
+
|
869
|
+
//弾の情報を取得
|
870
|
+
|
871
|
+
const BulletData data = Database::msBulletdata[bulletType];
|
872
|
+
|
873
|
+
|
874
|
+
|
875
|
+
//画像の設定
|
876
|
+
|
877
|
+
mSprite.SetTexture(textureHandle);
|
878
|
+
|
879
|
+
mSprite.src.x = data.mRectX1;
|
880
|
+
|
881
|
+
mSprite.src.y = data.mRectY1;
|
882
|
+
|
883
|
+
mSprite.size.x = data.mRectX2;
|
884
|
+
|
885
|
+
mSprite.size.y = data.mRectY2;
|
886
|
+
|
887
|
+
|
888
|
+
|
889
|
+
//初期座標の設定
|
890
|
+
|
891
|
+
mPos.x = pos.x;
|
892
|
+
|
893
|
+
mPos.y = pos.y;
|
894
|
+
|
895
|
+
|
896
|
+
|
897
|
+
//画像に座標を反映
|
898
|
+
|
899
|
+
mSprite.pos.x = mPos.x;
|
900
|
+
|
901
|
+
mSprite.pos.y = mPos.y;
|
902
|
+
|
903
|
+
|
904
|
+
|
905
|
+
//使用状態とする
|
906
|
+
|
907
|
+
mIsActive = TRUE;
|
908
|
+
|
909
|
+
|
910
|
+
|
911
|
+
//威力の設定
|
912
|
+
|
913
|
+
mPower = data.mPower;
|
914
|
+
|
915
|
+
|
916
|
+
|
917
|
+
//当たり判定情報の初期化
|
918
|
+
|
919
|
+
mCollision.mRadius = data.mRadius;
|
920
|
+
|
921
|
+
mCollision.mPos.x = pos.x;
|
922
|
+
|
923
|
+
mCollision.mPos.y = pos.y;
|
924
|
+
|
925
|
+
}
|
926
|
+
|
927
|
+
|
928
|
+
|
929
|
+
/*----------------------
|
930
|
+
|
931
|
+
更新
|
932
|
+
|
933
|
+
-----------------------*/
|
934
|
+
|
935
|
+
void Bullet::Update(void)
|
936
|
+
|
937
|
+
{
|
938
|
+
|
939
|
+
//使用中でなければ処理しない
|
940
|
+
|
941
|
+
if (mIsActive==FALSE)
|
942
|
+
|
943
|
+
{
|
944
|
+
|
945
|
+
return;
|
946
|
+
|
947
|
+
}
|
948
|
+
|
949
|
+
|
950
|
+
|
951
|
+
//弾の情報を取得
|
952
|
+
|
953
|
+
const BulletData data = Database::msBulletdata[mBulletType];
|
954
|
+
|
955
|
+
|
956
|
+
|
957
|
+
|
958
|
+
|
959
|
+
//弾の種類に応じた移動処理
|
960
|
+
|
961
|
+
switch (mBulletType)
|
962
|
+
|
963
|
+
{
|
964
|
+
|
965
|
+
case BULLET_TYPE_PLAYER_NORMAL: //プレイヤー通常弾
|
966
|
+
|
967
|
+
{
|
968
|
+
|
969
|
+
//mPos.y -= data.mVel;
|
970
|
+
|
971
|
+
mPos.x +=data.mVel;
|
972
|
+
|
973
|
+
|
974
|
+
|
975
|
+
|
976
|
+
|
977
|
+
break;
|
978
|
+
|
979
|
+
}
|
980
|
+
|
981
|
+
|
982
|
+
|
983
|
+
|
984
|
+
|
985
|
+
|
986
|
+
|
987
|
+
case BULLET_TYPE_ENEMY_NORMAL: //敵通常弾
|
988
|
+
|
989
|
+
{
|
990
|
+
|
991
|
+
//mPos.y += data.mVel;
|
992
|
+
|
993
|
+
mPos.x -= data.mVel;
|
994
|
+
|
995
|
+
|
996
|
+
|
997
|
+
break;
|
998
|
+
|
999
|
+
}
|
1000
|
+
|
1001
|
+
|
1002
|
+
|
1003
|
+
|
1004
|
+
|
1005
|
+
|
1006
|
+
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
|
1010
|
+
|
1011
|
+
//画面外に出たら弾を未使用状態にする
|
1012
|
+
|
1013
|
+
if (
|
1014
|
+
|
1015
|
+
mPos.x < SCREEN_LEFT - BULLET_ALIVE_AREA ||
|
1016
|
+
|
1017
|
+
mPos.x > SCREEN_RIGHT + BULLET_ALIVE_AREA ||
|
1018
|
+
|
1019
|
+
mPos.y < SCREEN_TOP - BULLET_ALIVE_AREA ||
|
1020
|
+
|
1021
|
+
mPos.y > SCREEN_BOTTOM + BULLET_ALIVE_AREA
|
1022
|
+
|
1023
|
+
)
|
1024
|
+
|
1025
|
+
{
|
1026
|
+
|
1027
|
+
mIsActive = FALSE;
|
1028
|
+
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
|
1032
|
+
|
1033
|
+
// 画像に座標を反映
|
1034
|
+
|
1035
|
+
mSprite.pos.x = mPos.x;
|
1036
|
+
|
1037
|
+
mSprite.pos.y = mPos.y;
|
1038
|
+
|
1039
|
+
|
1040
|
+
|
1041
|
+
//当たり判定に座標を反映
|
1042
|
+
|
1043
|
+
mCollision.mPos.x = mPos.x;
|
1044
|
+
|
1045
|
+
mCollision.mPos.y = mPos.y;
|
1046
|
+
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
|
1050
|
+
|
1051
|
+
/*----------------------------
|
1052
|
+
|
1053
|
+
描画
|
1054
|
+
|
1055
|
+
----------------------------*/
|
1056
|
+
|
1057
|
+
void Bullet::Draw(void)
|
1058
|
+
|
1059
|
+
{
|
1060
|
+
|
1061
|
+
//使用中でなければ処理しない
|
1062
|
+
|
1063
|
+
if (mIsActive == FALSE)
|
1064
|
+
|
1065
|
+
{
|
1066
|
+
|
1067
|
+
return;
|
1068
|
+
|
1069
|
+
}
|
1070
|
+
|
1071
|
+
//自機の表示
|
1072
|
+
|
1073
|
+
mSprite.Draw();
|
1074
|
+
|
1075
|
+
}
|
1076
|
+
|
1077
|
+
コード
|
1078
|
+
|
1079
|
+
```
|
1080
|
+
|
1081
|
+
```
|
1082
|
+
|
1083
|
+
```
|
1084
|
+
|
1085
|
+
```
|
1086
|
+
|
1087
|
+
|
1088
|
+
|
1
|
-
### 前提・実現したいこと
|
1089
|
+
```### 前提・実現したいこと
|
2
1090
|
|
3
1091
|
シューティングを作っているのですが誘導弾のやり方がわかりません。わかりやすくお願いします。
|
4
|
-
|
5
|
-
ここに質問の内容を詳しく書いてください。
|
6
|
-
|
7
|
-
(例)PHP(CakePHP)で●●なシステムを作っています。
|
8
|
-
|
9
|
-
■■な機能を実装中に以下のエラーメッセージが発生しました。
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
### 発生している問題・エラーメッセージ
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
```
|
18
|
-
|
19
|
-
エラーメッセージ
|
20
|
-
|
21
|
-
```
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
### 該当のソースコード
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
```ここに言語名を入力
|
30
|
-
|
31
|
-
ソースコード
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
### 試したこと
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
ここに問題に対して試したことを記載してください。
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
### 補足情報(FW/ツールのバージョンなど)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
ここにより詳細な情報を記載してください。
|