質問編集履歴
3
Tankクラスの全文記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
独学で学んでいる者です。
|
2
2
|
|
3
|
-
質問修正しました。
|
4
|
-
|
5
|
-
遅くなりました、すいません。
|
6
|
-
|
7
3
|
|
8
4
|
|
9
5
|
・試みたこと
|
@@ -34,7 +30,7 @@
|
|
34
30
|
|
35
31
|
|
36
32
|
|
37
|
-
プレイヤークラス
|
33
|
+
プレイヤークラス
|
38
34
|
|
39
35
|
```java
|
40
36
|
|
@@ -68,13 +64,13 @@
|
|
68
64
|
|
69
65
|
public class Players {
|
70
66
|
|
71
|
-
|
67
|
+
private:
|
72
|
-
|
68
|
+
|
73
|
-
|
69
|
+
SurfaceHolder holder;
|
74
|
-
|
70
|
+
|
75
|
-
|
71
|
+
Graphics gr1;
|
76
|
-
|
72
|
+
|
77
|
-
|
73
|
+
Paint paint;
|
78
74
|
|
79
75
|
|
80
76
|
|
@@ -450,8 +446,6 @@
|
|
450
446
|
|
451
447
|
|
452
448
|
|
453
|
-
//関係部分のみ抜粋
|
454
|
-
|
455
449
|
|
456
450
|
|
457
451
|
import android.app.Activity;
|
@@ -480,23 +474,27 @@
|
|
480
474
|
|
481
475
|
|
482
476
|
|
477
|
+
|
478
|
+
|
483
479
|
public class Tank {
|
484
480
|
|
485
481
|
|
486
482
|
|
483
|
+
private:
|
484
|
+
|
487
|
-
|
485
|
+
SurfaceHolder holder;
|
488
|
-
|
486
|
+
|
489
|
-
|
487
|
+
Graphics gra2;
|
490
|
-
|
488
|
+
|
491
|
-
|
489
|
+
Paint paint;
|
492
|
-
|
490
|
+
|
493
|
-
|
491
|
+
Players p1;
|
492
|
+
|
494
|
-
|
493
|
+
BackGround BG;
|
495
|
-
|
496
|
-
|
494
|
+
|
497
|
-
|
495
|
+
int TankX = 1600;
|
498
|
-
|
496
|
+
|
499
|
-
|
497
|
+
int TankFlag = 0;
|
500
498
|
|
501
499
|
|
502
500
|
|
@@ -512,8 +510,6 @@
|
|
512
510
|
|
513
511
|
|
514
512
|
|
515
|
-
//コンストラクタ
|
516
|
-
|
517
513
|
private Tfire(int x, int y) {
|
518
514
|
|
519
515
|
this.x = x;
|
@@ -524,7 +520,29 @@
|
|
524
520
|
|
525
521
|
}
|
526
522
|
|
527
|
-
|
523
|
+
}
|
524
|
+
|
525
|
+
private class Smg {
|
526
|
+
|
527
|
+
int x;
|
528
|
+
|
529
|
+
int y;
|
530
|
+
|
531
|
+
int life;
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
private Smg(int x, int y) {
|
536
|
+
|
537
|
+
this.x = x;
|
538
|
+
|
539
|
+
this.y = y;
|
540
|
+
|
541
|
+
this.life = 5;
|
542
|
+
|
543
|
+
}
|
544
|
+
|
545
|
+
}
|
528
546
|
|
529
547
|
|
530
548
|
|
@@ -558,9 +576,7 @@
|
|
558
576
|
|
559
577
|
private List<Smg> Smoke = new ArrayList<Smg>();//煙
|
560
578
|
|
561
|
-
private List<Expl> expls =new ArrayList<Expl>();
|
579
|
+
private List<Expl> expls =new ArrayList<Expl>();//爆炎
|
562
|
-
|
563
|
-
|
564
580
|
|
565
581
|
|
566
582
|
|
@@ -624,8 +640,6 @@
|
|
624
640
|
|
625
641
|
|
626
642
|
|
627
|
-
|
628
|
-
|
629
643
|
public void set1(Graphics gr2) {
|
630
644
|
|
631
645
|
|
@@ -636,6 +650,16 @@
|
|
636
650
|
|
637
651
|
|
638
652
|
|
653
|
+
//戦車
|
654
|
+
|
655
|
+
gr2.drawBitmap(Bt[16], TankX, BG.setEarthH() - 151);
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
|
660
|
+
|
661
|
+
|
662
|
+
|
639
663
|
//戦車の弾
|
640
664
|
|
641
665
|
for (int i = fire.size() - 1; i >= 0; i--) {
|
@@ -650,11 +674,17 @@
|
|
650
674
|
|
651
675
|
}
|
652
676
|
|
653
|
-
|
677
|
+
//煙
|
678
|
+
|
654
|
-
|
679
|
+
for (int i = Smoke.size() - 1; i >= 0; i--) {
|
680
|
+
|
655
|
-
|
681
|
+
Smg pos = Smoke.get(i);
|
682
|
+
|
656
|
-
|
683
|
+
gr2.drawBitmap(Bt[18], pos.x, pos.y);
|
684
|
+
|
685
|
+
}
|
686
|
+
|
657
|
-
//爆
|
687
|
+
//爆炎
|
658
688
|
|
659
689
|
for (int i = expls.size() - 1; i >= 0; i--) {
|
660
690
|
|
@@ -662,9 +692,7 @@
|
|
662
692
|
|
663
693
|
gr2.drawBitmap(Bt[20], expl.x, expl.y);
|
664
694
|
|
665
|
-
|
695
|
+
}
|
666
|
-
|
667
|
-
|
668
696
|
|
669
697
|
}
|
670
698
|
|
@@ -700,7 +728,7 @@
|
|
700
728
|
|
701
729
|
|
702
730
|
|
703
|
-
//爆炎の追加
|
731
|
+
//爆炎の追加
|
704
732
|
|
705
733
|
if(TankFlag ==1){
|
706
734
|
|
@@ -708,9 +736,7 @@
|
|
708
736
|
|
709
737
|
Tfire pos = fire.get(i);
|
710
738
|
|
711
|
-
|
712
|
-
|
713
|
-
//ここで弾とプレイヤーを衝突させたかった
|
739
|
+
//ここで戦車弾とプレイヤーを衝突させたかった
|
714
740
|
|
715
741
|
if (pos.x < 100) {
|
716
742
|
|
@@ -736,7 +762,91 @@
|
|
736
762
|
|
737
763
|
}}
|
738
764
|
|
739
|
-
|
765
|
+
//煙の遷移
|
766
|
+
|
767
|
+
for (int i = Smoke.size() - 1; i >= 0; i--) {
|
768
|
+
|
769
|
+
Smg pos = Smoke.get(i);
|
770
|
+
|
771
|
+
pos.life--;
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
if (pos.life < 0) {
|
776
|
+
|
777
|
+
Smoke.remove(i);
|
778
|
+
|
779
|
+
}
|
780
|
+
|
781
|
+
break;
|
782
|
+
|
783
|
+
}
|
784
|
+
|
785
|
+
|
786
|
+
|
787
|
+
//戦車の攻撃
|
788
|
+
|
789
|
+
if (TankFlag == 0) {
|
790
|
+
|
791
|
+
if (TankX > p1.setPlayerX()) {
|
792
|
+
|
793
|
+
fire.add(new Tfire(TankX - 70, BG.setEarthH()-146));
|
794
|
+
|
795
|
+
Smoke.add(new Smg(TankX - 60, BG.setEarthH() - 150));
|
796
|
+
|
797
|
+
TankFlag = 1;
|
798
|
+
|
799
|
+
|
800
|
+
|
801
|
+
}
|
802
|
+
|
803
|
+
}
|
804
|
+
|
805
|
+
//爆炎の遷移
|
806
|
+
|
807
|
+
for (int i = expls.size() - 1; i >= 0; i--) {
|
808
|
+
|
809
|
+
Expl expl = expls.get(i);
|
810
|
+
|
811
|
+
expl.life--;
|
812
|
+
|
813
|
+
if (expl.life < 0) {
|
814
|
+
|
815
|
+
expls.remove(i);
|
816
|
+
|
817
|
+
}
|
818
|
+
|
819
|
+
break;
|
820
|
+
|
821
|
+
}
|
822
|
+
|
823
|
+
|
824
|
+
|
825
|
+
}
|
826
|
+
|
827
|
+
|
828
|
+
|
829
|
+
public void move(){
|
830
|
+
|
831
|
+
TankX -= 27;
|
832
|
+
|
833
|
+
for (int i = Smoke.size() - 1; i >= 0; i--) {
|
834
|
+
|
835
|
+
Smg pos = Smoke.get(i);
|
836
|
+
|
837
|
+
pos.x-=27;
|
838
|
+
|
839
|
+
}
|
840
|
+
|
841
|
+
for (int i = expls.size() - 1; i >= 0; i--) {
|
842
|
+
|
843
|
+
Expl expl = expls.get(i);
|
844
|
+
|
845
|
+
expl.x -= 27;
|
846
|
+
|
847
|
+
}
|
848
|
+
|
849
|
+
}
|
740
850
|
|
741
851
|
|
742
852
|
|
@@ -764,9 +874,13 @@
|
|
764
874
|
|
765
875
|
|
766
876
|
|
877
|
+
|
878
|
+
|
767
879
|
```
|
768
880
|
|
881
|
+
|
882
|
+
|
769
|
-
これらの細かいクラスをダブルバッファリングで大本のクラスに書いています
|
883
|
+
これらの細かいクラスをダブルバッファリングで大本のクラスに書いています
|
770
884
|
|
771
885
|
|
772
886
|
|
@@ -774,4 +888,4 @@
|
|
774
888
|
|
775
889
|
戦車弾とプレイヤーを衝突させたいです。
|
776
890
|
|
777
|
-
どうしたらいいですか
|
891
|
+
どうしたらいいですか?
|
2
・試みたことを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,13 +6,31 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
・試みたこと
|
10
|
+
|
11
|
+
下記のTankクラスの問題個所でプレイヤークラスから渡された(setPlayerX(),setPlayerY())はただ原点座標を返しているにすぎないと判断した私は、その座標をプレイヤーの動きと重ねればどうだろうと思い、プレイヤーのYの動きである
|
12
|
+
|
13
|
+
PlayerY +=vy;
|
14
|
+
|
15
|
+
をsetPlayerYメソッドに書きました。
|
16
|
+
|
17
|
+
すると、プレイヤーが落ちてくるよりも遅く(確認のために描画してある)爆炎がゆっくりと下がってきました。
|
18
|
+
|
19
|
+
今後、重ねる方法をとらないにしても、なぜ同じ式を入れているプレイヤーと爆炎で落ちるスピードが違うのか?という質問が2番になります。
|
20
|
+
|
21
|
+
ダブルバッファリングによるフレーム数とかの問題ですか?
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
9
|
-
前回の質問
|
27
|
+
・前回の質問
|
10
|
-
|
28
|
+
|
11
|
-
|
29
|
+
1playerが動いているのだからplayerYに格納されている値も変化し続けているのではないのですか?
|
12
|
-
|
30
|
+
|
13
|
-
|
31
|
+
2同じ値を使っているのに別の座標で落ちる速度が違うのはなぜですか?
|
14
|
-
|
32
|
+
|
15
|
-
|
33
|
+
3どうすれば逐一動いているplayerYの座標を取得できますか?
|
16
34
|
|
17
35
|
|
18
36
|
|
1
コードが少なすぎて判断材料が足りなかった点と新しい質問
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,43 +1,759 @@
|
|
1
1
|
独学で学んでいる者です。
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
プレイヤーがいるとして、
|
6
|
-
|
7
|
-
・PlayerY =プレイヤーのy座標
|
8
|
-
|
9
|
-
・vy =重力
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
private int playerY;
|
14
|
-
|
15
|
-
public int vy = 27;
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
PlayerY +=vy;
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
3
|
+
質問修正しました。
|
24
|
-
|
25
|
-
|
4
|
+
|
26
|
-
|
27
|
-
|
5
|
+
遅くなりました、すいません。
|
28
|
-
|
29
|
-
|
6
|
+
|
30
|
-
|
31
|
-
|
7
|
+
|
32
|
-
|
33
|
-
|
34
|
-
|
8
|
+
|
35
|
-
質問
|
9
|
+
前回の質問
|
36
10
|
|
37
11
|
?playerが動いているのだからplayerYに格納されている値も変化し続けているのではないのですか?
|
38
12
|
|
39
13
|
?同じ値を使っているのに別の座標で落ちる速度が違うのはなぜですか?
|
40
14
|
|
41
|
-
|
42
|
-
|
43
15
|
?どうすれば逐一動いているplayerYの座標を取得できますか?
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
プレイヤークラス(そのまま)
|
20
|
+
|
21
|
+
```java
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
import android.app.Activity;
|
26
|
+
|
27
|
+
import android.content.Context;
|
28
|
+
|
29
|
+
import android.graphics.Bitmap;
|
30
|
+
|
31
|
+
import android.graphics.BitmapFactory;
|
32
|
+
|
33
|
+
import android.graphics.Paint;
|
34
|
+
|
35
|
+
import android.graphics.PixelFormat;
|
36
|
+
|
37
|
+
import android.graphics.Point;
|
38
|
+
|
39
|
+
import android.view.Display;
|
40
|
+
|
41
|
+
import android.view.MotionEvent;
|
42
|
+
|
43
|
+
import android.view.SurfaceHolder;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
public class Players {
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
private SurfaceHolder holder;
|
56
|
+
|
57
|
+
private Graphics gr1;
|
58
|
+
|
59
|
+
private Paint paint;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
//ジャンプ
|
64
|
+
|
65
|
+
private int oldY;
|
66
|
+
|
67
|
+
private int newY;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
//プレイヤー
|
72
|
+
|
73
|
+
public int PlayerX ;
|
74
|
+
|
75
|
+
public int PlayerY;
|
76
|
+
|
77
|
+
private int PlayerToX = PlayerX;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
//横方向のカウント数
|
82
|
+
|
83
|
+
private int xcount = 0;
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
//添字
|
88
|
+
|
89
|
+
private int ix = 0;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
//重力
|
94
|
+
|
95
|
+
public int vy = 27;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
public Bitmap[] Bp = new Bitmap[30];
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
public Players(int w, int h,SurfaceHolder holder,Activity P){
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
this.holder =holder;
|
112
|
+
|
113
|
+
this.holder.setFormat(PixelFormat.RGBA_8888);
|
114
|
+
|
115
|
+
this.holder.setFixedSize(w,h);
|
116
|
+
|
117
|
+
paint = new Paint();
|
118
|
+
|
119
|
+
paint.setAntiAlias(true);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
//画面サイズの指定
|
124
|
+
|
125
|
+
Display display = P.getWindowManager().getDefaultDisplay();
|
126
|
+
|
127
|
+
Point p = new Point();
|
128
|
+
|
129
|
+
display.getSize(p);
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
gr1= new Graphics(p.x,p.y,holder);
|
134
|
+
|
135
|
+
gr1.setOrigin(p.x,p.y);
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
//ビットマップの読み込み
|
142
|
+
|
143
|
+
for (int i = 0; i < 30; i++) {
|
144
|
+
|
145
|
+
Bp [i] = readBitmap(P, "red" + i);
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
public void set1(Graphics gr11) {
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
gr1 = gr11
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
//プレイヤーの描画
|
168
|
+
|
169
|
+
gr11.drawBitmap(Bp[ix],PlayerX, PlayerY);
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
//歩行
|
178
|
+
|
179
|
+
public void move1(){
|
180
|
+
|
181
|
+
//歩行
|
182
|
+
|
183
|
+
if (Math.abs(PlayerX - PlayerToX) < 1) {
|
184
|
+
|
185
|
+
PlayerX = PlayerToX;
|
186
|
+
|
187
|
+
} else if (PlayerX < PlayerToX) {
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
PlayerX += 27;
|
194
|
+
|
195
|
+
} else if (PlayerX > PlayerToX) {
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
PlayerX -= 27;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
//重力加速度
|
210
|
+
|
211
|
+
public int goDown(){
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
return PlayerY +=vy ;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
//重力の付加
|
222
|
+
|
223
|
+
public void gravity(){
|
224
|
+
|
225
|
+
PlayerY =goDown();
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
//描画座標
|
234
|
+
|
235
|
+
public int setPlayerX() {
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
return PlayerX;
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
public int setPlayerY(){
|
246
|
+
|
247
|
+
//ここにgoDown();を書いたりしました。
|
248
|
+
|
249
|
+
return PlayerY;
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
//Xの移動終点
|
256
|
+
|
257
|
+
public int setPlayertoX(){
|
258
|
+
|
259
|
+
return PlayerToX;
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
//右方向
|
270
|
+
|
271
|
+
public void move1right(){
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
while (PlayerToX - PlayerX > 1) {
|
276
|
+
|
277
|
+
xcount++;
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
//カウントから添え字を求める
|
284
|
+
|
285
|
+
ix = Math.abs(xcount) % 6 + 1;
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
break;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
//左方向
|
302
|
+
|
303
|
+
public void move1left(){
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
while (PlayerX - PlayerToX > 0) {
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
xcount++;
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
//カウントから添え字を求める
|
316
|
+
|
317
|
+
ix = Math.abs(xcount) % 6 + 7;
|
318
|
+
|
319
|
+
break;
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
//歩行制御
|
328
|
+
|
329
|
+
public void save(){
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
if (PlayerX > 960-176 ) {
|
334
|
+
|
335
|
+
PlayerX =Math.abs(960-176);
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
//タッチイベント
|
342
|
+
|
343
|
+
public boolean onTouchEvent(MotionEvent event) {
|
344
|
+
|
345
|
+
int touchX = (int) (event.getX());
|
346
|
+
|
347
|
+
int touchAction = event.getAction();
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
if (touchAction == MotionEvent.ACTION_DOWN) {
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
PlayerToX = touchX;
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
newY = (int) event.getY();
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
if (touchAction == MotionEvent.ACTION_UP) {
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
PlayerToX = PlayerX;
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
oldY = (int) (event.getY());
|
380
|
+
|
381
|
+
if (newY > oldY + 60) {
|
382
|
+
|
383
|
+
PlayerY -= 250;
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
} else {}
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
return true;
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
//ビットマップの読み込み
|
404
|
+
|
405
|
+
static Bitmap readBitmap(Context context, String name) {
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
int resID = context.getResources().getIdentifier(name, "drawable", context.getPackageName());
|
410
|
+
|
411
|
+
return BitmapFactory.decodeResource(context.getResources(), resID);
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
}
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
```
|
428
|
+
|
429
|
+
敵(Tank)
|
430
|
+
|
431
|
+
```java
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
//関係部分のみ抜粋
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
import android.app.Activity;
|
440
|
+
|
441
|
+
import android.content.Context;
|
442
|
+
|
443
|
+
import android.graphics.Bitmap;
|
444
|
+
|
445
|
+
import android.graphics.BitmapFactory;
|
446
|
+
|
447
|
+
import android.graphics.Paint;
|
448
|
+
|
449
|
+
import android.graphics.PixelFormat;
|
450
|
+
|
451
|
+
import android.graphics.Point;
|
452
|
+
|
453
|
+
import android.view.Display;
|
454
|
+
|
455
|
+
import android.view.SurfaceHolder;
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
import java.util.ArrayList;
|
460
|
+
|
461
|
+
import java.util.List;
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
public class Tank {
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
private SurfaceHolder holder;
|
470
|
+
|
471
|
+
private Graphics gra2;
|
472
|
+
|
473
|
+
private Paint paint;
|
474
|
+
|
475
|
+
private Players p1;
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
private int TankX = 1600;
|
480
|
+
|
481
|
+
private int TankFlag = 0;
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
private class Tfire {
|
488
|
+
|
489
|
+
int x;
|
490
|
+
|
491
|
+
int y;
|
492
|
+
|
493
|
+
int life;
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
//コンストラクタ
|
498
|
+
|
499
|
+
private Tfire(int x, int y) {
|
500
|
+
|
501
|
+
this.x = x;
|
502
|
+
|
503
|
+
this.y = y;
|
504
|
+
|
505
|
+
this.life = 1;
|
506
|
+
|
507
|
+
}
|
508
|
+
|
509
|
+
}
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
private class Expl {
|
514
|
+
|
515
|
+
int x;
|
516
|
+
|
517
|
+
int y;
|
518
|
+
|
519
|
+
int life;
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
public Expl(int x, int y) {
|
524
|
+
|
525
|
+
this.x = x;
|
526
|
+
|
527
|
+
this.y = y;
|
528
|
+
|
529
|
+
this.life = 5;
|
530
|
+
|
531
|
+
}
|
532
|
+
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
private List<Tfire> fire = new ArrayList<Tfire>(); //戦車弾
|
540
|
+
|
541
|
+
private List<Smg> Smoke = new ArrayList<Smg>();//煙
|
542
|
+
|
543
|
+
private List<Expl> expls =new ArrayList<Expl>();
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
public Bitmap[] Bt = new Bitmap[30];
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
public Tank(int w, int h, SurfaceHolder holder, Activity T){
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
this.holder =holder;
|
564
|
+
|
565
|
+
this.holder.setFormat(PixelFormat.RGBA_8888);
|
566
|
+
|
567
|
+
this.holder.setFixedSize(w,h);
|
568
|
+
|
569
|
+
paint = new Paint();
|
570
|
+
|
571
|
+
paint.setAntiAlias(true);
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
//画面サイズの指定
|
576
|
+
|
577
|
+
Display display = T.getWindowManager().getDefaultDisplay();
|
578
|
+
|
579
|
+
Point p = new Point();
|
580
|
+
|
581
|
+
display.getSize(p);
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
//ビットマップの読み込み
|
588
|
+
|
589
|
+
for (int i = 0; i < 30; i++) {
|
590
|
+
|
591
|
+
Bt [i] = readBitmap(T, "red" + i);
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
}
|
596
|
+
|
597
|
+
gra2= new Graphics(w,h,holder);
|
598
|
+
|
599
|
+
BG = new BackGround(w, h, holder, T);
|
600
|
+
|
601
|
+
p1 = new Players(w, h, holder, T);
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
}
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
public void set1(Graphics gr2) {
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
gra2 =gr2;
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
//戦車の弾
|
622
|
+
|
623
|
+
for (int i = fire.size() - 1; i >= 0; i--) {
|
624
|
+
|
625
|
+
Tfire atk = fire.get(i);
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
gr2.drawBitmap(Bt[17], atk.x, atk.y);
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
}
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
//爆発
|
640
|
+
|
641
|
+
for (int i = expls.size() - 1; i >= 0; i--) {
|
642
|
+
|
643
|
+
Expl expl = expls.get(i);
|
644
|
+
|
645
|
+
gr2.drawBitmap(Bt[20], expl.x, expl.y);
|
646
|
+
|
647
|
+
}
|
648
|
+
|
649
|
+
|
650
|
+
|
651
|
+
}
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
//攻撃
|
656
|
+
|
657
|
+
public void attack(){
|
658
|
+
|
659
|
+
|
660
|
+
|
661
|
+
//弾の移動
|
662
|
+
|
663
|
+
for (int i = fire.size() - 1; i >= 0; i--) {
|
664
|
+
|
665
|
+
Tfire pos = fire.get(i);
|
666
|
+
|
667
|
+
pos.x -= 96;
|
668
|
+
|
669
|
+
|
670
|
+
|
671
|
+
if (pos.x < 0) {
|
672
|
+
|
673
|
+
fire.remove(i);
|
674
|
+
|
675
|
+
TankFlag = 0;
|
676
|
+
|
677
|
+
}
|
678
|
+
|
679
|
+
break;
|
680
|
+
|
681
|
+
}
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
//爆炎の追加*問題の場所
|
686
|
+
|
687
|
+
if(TankFlag ==1){
|
688
|
+
|
689
|
+
for (int i = fire.size() - 1; i >= 0; i--) {
|
690
|
+
|
691
|
+
Tfire pos = fire.get(i);
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
//ここで弾とプレイヤーを衝突させたかった
|
696
|
+
|
697
|
+
if (pos.x < 100) {
|
698
|
+
|
699
|
+
/*しかし、衝突しなかったのでプレイヤーの座標がどこにあるのか
|
700
|
+
|
701
|
+
調べるため、現時点は100の座標と衝突させて、プレイヤーの座標で
|
702
|
+
|
703
|
+
爆炎が起こるようになっている。
|
704
|
+
|
705
|
+
*/
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
expls.add(new Expl(p1.setPlayerX(), p1.setPlayerY()));
|
710
|
+
|
711
|
+
fire.remove(i);
|
712
|
+
|
713
|
+
|
714
|
+
|
715
|
+
TankFlag = 0;
|
716
|
+
|
717
|
+
}
|
718
|
+
|
719
|
+
}}
|
720
|
+
|
721
|
+
|
722
|
+
|
723
|
+
|
724
|
+
|
725
|
+
|
726
|
+
|
727
|
+
|
728
|
+
|
729
|
+
//ビットマップの読み込み
|
730
|
+
|
731
|
+
static Bitmap readBitmap(Context context, String name) {
|
732
|
+
|
733
|
+
|
734
|
+
|
735
|
+
int resID = context.getResources().getIdentifier(name, "drawable", context.getPackageName());
|
736
|
+
|
737
|
+
return BitmapFactory.decodeResource(context.getResources(), resID);
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
|
742
|
+
|
743
|
+
}
|
744
|
+
|
745
|
+
}
|
746
|
+
|
747
|
+
|
748
|
+
|
749
|
+
```
|
750
|
+
|
751
|
+
これらの細かいクラスをダブルバッファリングで大本のクラスに書いています。
|
752
|
+
|
753
|
+
|
754
|
+
|
755
|
+
>この質問で一番聞きたい事
|
756
|
+
|
757
|
+
戦車弾とプレイヤーを衝突させたいです。
|
758
|
+
|
759
|
+
どうしたらいいですか?
|