-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bullet.cs
335 lines (307 loc) · 9.35 KB
/
Bullet.cs
1
2
3
4
5
6
7
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
using System;
using System.Collections;
using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.HighLevel.GameEngine2D;
using Sce.PlayStation.HighLevel.GameEngine2D.Base;
namespace ShootingApp
{
public enum BulletType
{ Single, Line, Circle, Spiral,
SingleUp, LineUp, CircleUp, SpiralUp,
SingleDown, LineDown, CircleDown, SpiralDown,
SingleAimed, LineAimed, CircleAimed,
Boss
}
/// <summary>
/// 1つの弾丸を管理するクラス
/// </summary>
public class Bullet1
{
public float X,Y; // 発射地点の座標
public float DX,DY; // 飛ばす方向
public SpriteUV Sprite;
public Bullet1(float x,float y, float dx, float dy){
X = x; Y = y; DX = dx; DY = dy;
}
}
/// <summary>
/// 自機から発射された弾丸をまとめて管理するクラス
/// </summary>
public static class MyBullet
{
public static ArrayList BulletList; // 弾丸を登録するArrayList
private static Texture2D Texture;
private static TextureInfo TextureInfo;
public static void InitMyBullet(){
BulletList = new ArrayList();
Texture = new Texture2D("Application/resourses/arrow.gif", false);
TextureInfo = new TextureInfo(Texture);
}
/// <summary>
/// 新たに弾丸を生成
/// </summary>
/// <param name='x'>
/// 初期位置のx座標
/// </param>
/// <param name='y'>
/// 初期位置のy座標
/// </param>
/// <param name='dx'>
/// x方向の速度
/// </param>
/// <param name='dy'>
/// y方向の速度
/// </param>
public static void MakeNewBullet(float x, float y, float dx, float dy){
var newBullet = new Bullet1(x,y,dx,dy);
newBullet.Sprite = new SpriteUV(){TextureInfo = TextureInfo};
newBullet.Sprite.Quad.S = TextureInfo.TextureSizef;
newBullet.Sprite.CenterSprite();
newBullet.Sprite.Position = new Sce.PlayStation.Core.Vector2(x,y);
BulletList.Add(newBullet);
Scenes.sceneOnGame.AddChild(((Bullet1)BulletList[BulletList.Count-1]).Sprite);
}
/// <summary>
/// 弾丸の位置を更新する
/// </summary>
/// <param name='bl'>
/// Bullet1
/// </param>
public static void Update(Bullet1 bl){
var newblPosition = new Vector2(bl.Sprite.Position.X,bl.Sprite.Position.Y);
newblPosition += new Vector2(bl.DX,bl.DY);
bl.Sprite.RunAction(new MoveTo(newblPosition,0.0f));
}
/// <summary>
/// 弾丸を削除する
/// </summary>
/// <param name='bl'>
/// Bullet1
/// </param>
public static void RemoveBullet(Bullet1 bl){
bl.Sprite.RemoveAllChildren(true);
Scenes.sceneOnGame.RemoveChild(bl.Sprite,true);
BulletList.Remove(bl);
}
public static void TextureDispose(){
Texture.Dispose();
TextureInfo.Dispose();
}
}
/// <summary>
/// 敵の弾丸をまとめて管理するクラス
/// </summary>
public static class EnemyBullet
{
public static ArrayList BulletList; // 弾丸を登録するArrayList
private static Texture2D[] BulletTexture;
private static TextureInfo[] BulletTextureInfo;
public static void InitEnemyBullet(){
BulletList = new ArrayList();
BulletTexture = new Texture2D[4];
BulletTextureInfo = new TextureInfo[4];
var image2 = new Image("/Application/resourses/Bullet01_16x16.png");
var image20 = image2.Crop(new ImageRect(0,0,16,16));
var image21 = image2.Crop(new ImageRect(0,16,16,16));
var image22 = image2.Crop(new ImageRect(0,32,16,16));
var image23 = image2.Crop(new ImageRect(0,48,16,16));
BulletTexture[0] = Convert.CreateTextureFromImage(image20);
BulletTextureInfo[0] = new TextureInfo(BulletTexture[0]);
BulletTexture[1] = Convert.CreateTextureFromImage(image21);
BulletTextureInfo[1] = new TextureInfo(BulletTexture[1]);
BulletTexture[2] = Convert.CreateTextureFromImage(image22);
BulletTextureInfo[2] = new TextureInfo(BulletTexture[2]);
BulletTexture[3] = Convert.CreateTextureFromImage(image23);
BulletTextureInfo[3] = new TextureInfo(BulletTexture[3]);
image2.Dispose();
image20.Dispose();
image21.Dispose();
image22.Dispose();
image23.Dispose();
}
public static void TextureDispose(){
foreach(Texture2D texture in BulletTexture)
texture.Dispose();
foreach(TextureInfo textureInfo in BulletTextureInfo)
textureInfo.Dispose();
}
/// <summary>
/// 単品の弾丸を生成
/// </summary>
/// <param name='x'>
/// 初期位置
/// </param>
/// <param name='y'>
/// 初期位置
/// </param>
/// <param name='dx'>
/// フレームあたり変化量
/// </param>
/// <param name='dy'>
/// フレームあたり変化量
/// </param>
public static void MakeSingleBullet(float x, float y, float dx, float dy){
NewBullet(BulletType.Single,x,y,dx,dy);
}
/// <summary>
/// 縦に並んだ弾丸を生成
/// </summary>
/// <param name='x'>
/// 初期位置(中心座標)
/// </param>
/// <param name='y'>
/// 初期位置(中心座標)
/// </param>
/// <param name='n'>
/// 個数
/// </param>
/// <param name='interval'>
/// 弾丸と弾丸の間[pixel]
/// </param>
/// <param name='dx'>
/// フレームあたり変化量
/// </param>
/// <param name='dy'>
/// フレームあたり変化量
/// </param>
public static void MakeLineBullets(float x, float y, int n, int interval, float dx, float dy){
NewBullet(BulletType.Line,x,y,dx,dy);
for(int i = 1; i < n; i++){
NewBullet(BulletType.Line,x,y+i*interval,dx,dy);
NewBullet(BulletType.Line,x,y+i*interval*(-1),dx,dy);
}
}
/// <summary>
/// 放射状に広がる弾丸を生成
/// </summary>
/// <param name='x'>
/// 初期位置
/// </param>
/// <param name='y'>
/// 初期位置
/// </param>
/// <param name='n'>
/// 円を構成する弾丸の個数
/// </param>
/// <param name='dr'>
/// フレームあたり変化する半径
/// </param>
public static void MakeCircleBullets(float x, float y, int n, float dr){
for(int i = 0;i < n; i++){
NewBullet(BulletType.Circle,x,y,dr*FMath.Cos(FMath.DegToRad * (360/n*i)),dr*FMath.Sin(FMath.DegToRad * (360/n*i)));
}
}
/// <summary>
/// 自機狙い円形の弾丸を生成
/// </summary>
/// <param name='x'>
/// 初期位置
/// </param>
/// <param name='y'>
/// 初期位置
/// </param>
/// <param name='n'>
/// 個数
/// </param>
/// <param name='r'>
/// 半径
/// </param>
/// <param name='dx'>
/// フレームあたり変化量
/// </param>
/// <param name='dy'>
/// フレームあたり変化量
/// </param>
public static void MakeDirectionCircleBullets(float x, float y, int n, float r, float dx, float dy){
for(int i = 0;i < n; i++){
NewBullet(BulletType.Circle,x+r*FMath.Cos(FMath.DegToRad * (360/n*i)),y+r*FMath.Sin(FMath.DegToRad * (360/n*i)),dx,dy);
}
}
/// <summary>
/// 螺旋状に広がる弾丸を生成
/// </summary>
/// <param name='x'>
/// 初期位置
/// </param>
/// <param name='y'>
/// 初期位置
/// </param>
/// <param name='n'>
/// 1周の個数
/// </param>
/// <param name='times'>
/// 何周するか
/// </param>
public static void MakeSpiralBullets(float x, float y, int n, int times){
for(int i = 0;i < n * times; i++){
NewBullet(BulletType.Spiral,x,y,(float)(i+n/3)/n*FMath.Cos(FMath.DegToRad * (360/n*i)),(float)(i+n/3)/n*FMath.Sin(FMath.DegToRad * (360/n*i)));
}
}
/// <summary>
/// 弾丸1つ生成
/// </summary>
/// <param name='type'>
/// 弾丸タイプ
/// </param>
/// <param name='x'>
/// 初期位置
/// </param>
/// <param name='y'>
/// 初期位置
/// </param>
/// <param name='dx'>
/// フレームあたり変化量
/// </param>
/// <param name='dy'>
/// フレームあたり変化量
/// </param>
private static void NewBullet(BulletType type, float x, float y, float dx, float dy){
var newBullet = new Bullet1(x,y,dx,dy);
newBullet.Sprite = new SpriteUV(){TextureInfo = BulletTextureInfo[(int)type]};
newBullet.Sprite.Quad.S = BulletTextureInfo[(int)type].TextureSizef;
newBullet.Sprite.CenterSprite();
newBullet.Sprite.Position = new Sce.PlayStation.Core.Vector2(x,y);
BulletList.Add(newBullet);
Scenes.sceneOnGame.AddChild(((Bullet1)BulletList[BulletList.Count-1]).Sprite);
}
/// <summary>
/// 弾丸の位置を更新
/// </summary>
/// <param name='bl'>
/// 更新する弾丸
/// </param>
public static void Update(Bullet1 bl){
var newblPosition = new Vector2(bl.Sprite.Position.X,bl.Sprite.Position.Y);
newblPosition += new Vector2(bl.DX,bl.DY);
bl.Sprite.RunAction(new MoveTo(newblPosition,0.0f));
}
/// <summary>
/// 弾丸を削除する
/// </summary>
/// <param name='bl'>
/// 削除する弾丸
/// </param>
public static void RemoveBullet(Bullet1 bl){
bl.Sprite.RemoveAllChildren(true);
Scenes.sceneOnGame.RemoveChild(bl.Sprite,true);
BulletList.Remove(bl);
}
/// <summary>
/// 敵弾丸リストに登録されている弾丸を自機弾丸リストに移動
/// </summary>
/// <param name='myShipSpritePosition'>
/// 自機の位置
/// </param>
public static void moveToMyBulletList(Vector2 myShipSpritePosition){
foreach(Bullet1 bl in BulletList){
var newDirectionVector = Vector2.Normalize(bl.Sprite.Position - myShipSpritePosition) * 2;
bl.DX = newDirectionVector.X;
bl.DY = newDirectionVector.Y;
MyBullet.BulletList.Add(bl);
}
BulletList.Clear();
}
}
}