File: bullet.d

package info (click to toggle)
projectl 1.001.dfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,720 kB
  • ctags: 5
  • sloc: xml: 57; makefile: 32
file content (240 lines) | stat: -rw-r--r-- 5,968 bytes parent folder | download | duplicates (3)
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
module br.bullet;
private import util.parts;
private import util.shape;
private import util.vector;
private import util.matrix;
private import util.log;
private import util.particle;
private import util.basis;
private import br.gamemanager;
private import br.blast;
private import std.math;
private import SDL_mixer;
private import br.sound;

public class Bullet:Parts{
	private bool inStage;
	public this(bool breakable){
		collisionManager.add(this ,collisionManager.kind.SHIP ,2);
		bulletManager.add(this);
		if(breakable){
			collisionManager.add(this, collisionManager.kind.LASER ,2);
			R = 160.0 / 255.0;
			G = 247.0 / 255.0;
			B = 150.0 / 255.0;
		}else{
			R = 245.0 / 255.0;
			G = 104.0 / 255.0;
			B = 110.0 / 255.0;
		}
		inStage = false;
		drawing = POLYGON | WIRE;
		alpha = 1.6;
	}
	public override void addChild(ref Parts child,string name, double dist = 0.1, int childKind = NORMAL, Matrix link = null ,Matrix pose = null){
		super.addChild(child ,name ,dist ,childKind ,link ,pose);
		bulletManager.add(child);
	}
	public override void  move(){
		super.move();
		
		if((rpos.y+size < screen.GAME_DOWN || screen.GAME_UP < rpos.y-size ||
			screen.GAME_RIGHT  < rpos.x-size || rpos.x+size < screen.GAME_LEFT 
			
			)){
			if(inStage || 300 < cnt )vanish();
			
		}else inStage = true;
		
		
		if(screen.GAME_NEAR < rpos.z - size || rpos.z + size < screen.GAME_FAR){

			vanish();
		}
		
	}
	public override void destroy(){
		super.destroy();
		new SmallBlast(rpos.x ,rpos.y ,30 ,30 ,5.0 ,90 ,R ,G ,B ,0.02);
//		makeParticle(shape, size ,WIRE ,rpos ,new Vector3() ,rpose ,R ,G ,B ,alpha * 0.5);
		makeSimpleParticle(2 ,size ,WIRE ,rpos ,R ,G ,B ,alpha * 0.5);
	}
	public override void reportCollision(int kind){
		destroy();
		
		Sound_PlaySe(se_kind.REVERSE);
//		Mix_PlayChannel(0, chunk_reverse, 0);
	}
	public override void vanish(){
 		
		super.vanish();
	}
}

public class StraightBullet:Bullet{
	static Shape baseShape;
	static  float[][] a = 
		[
			[-2.0 ,0.0 ,1.0]
  	   ];
  	static float[][] b =
		[
			[0.0 ,1.0 ,0.0]
  	];
	double aim;
	double speed;
	public this(Vector3 v ,bool breakable, double aim ,double speed = 4.0){
		super(breakable);
		if(baseShape is null){
			baseShape = new SH_Pole(a ,b ,4);
		}
//		setPoseBase(matRotateZ(aim / PI * 180.0));
		//collisionManager.add(this ,collisionManager.kind.BULLET ,2);
		
  	shape = new SH_Pole(a ,b ,4);
		size =  17;
		collisionRange = 8;
		this.speed = speed;
		
		pos = cast(Vector3)v.clone();
		rpos = cast(Vector3)pos.clone();
		this.aim = aim;
	}
	public override void  move(){
		super.move();
		if(parent is null){
			pos.x += speed * cos(aim);
			pos.y += speed * sin(aim);
		}
		poseZ = aim / PI * 180.0;
	}
}
public class SlowStraightBullet:StraightBullet{
	public this(Vector3 v ,bool breakable, double aim){
		super(v ,breakable ,aim);
		speed = 1.5;
	}
}
public class EBullet2:StraightBullet{
	public this(Vector3 v ,bool breakable,double aim){
		
		super(v ,breakable ,aim);
		Parts b = new StraightBullet(v ,breakable ,aim);
		addChild(b ,"bul" ,40 ,FOLLOW);
		Parts b2 = new StraightBullet(v ,breakable, aim);
		b.addChild(b2 ,"bul" ,40 ,FOLLOW);
	}
}
public class Bullet3D:StraightBullet{
	public this(Vector3 v ,bool breakable,double aim ,double speed){
		
		super(v ,breakable ,aim ,speed);
	}
	public override void move(){
		
		if(rpos.z < -800 - 2)pos.z +=2.0;
		else if(-800 + 2 < rpos.z)pos.z -= 2.0;
		else {
			super.move();
		}
		poseZ = aim / PI * 180.0;
	}
}
public class Bullet3D2:Bullet{
	static Shape baseShape;
	static  float[][] a = 
		[
			[-1.0 ,0.0 ,1.0]
  	   ];
  	static float[][] b =
		[
			[0.0 ,1.0 ,0.0]
  	];
	Vector3 aim;
	public this(Vector3 v ,bool breakable,Vector3 aim){
		super(breakable);
		if(baseShape is null){
			baseShape = new SH_Pole(a ,b ,4);
		}
//		setPoseBase(matRotateZ(aim / PI * 180.0));
		//collisionManager.add(this ,collisionManager.kind.BULLET ,2);
		
	  	shape = new SH_Pole(a ,b ,4);
		size =  25;
		collisionRange = 12;
		pos = cast(Vector3)v.clone();
		rpos = cast(Vector3)pos.clone();
		this.aim = cast(Vector3)aim.clone();
	}
	public override void move(){
		super.move();
		pos += aim;
		
		poseZ += 1.0;
	}
}
public class BendBullet:StraightBullet{
	private:
	double bendAim;
	int bendTime;
	double afSpeed;
	public this(Vector3 v ,bool breakable,double aim ,double bendAim ,int bendTime,double speed = 4.0 ,double afSpeed = 4.0){
		super(v ,breakable ,aim ,speed);
		this.bendAim = bendAim;
		this.bendTime = bendTime;
		this.afSpeed = afSpeed;
	}
	public override void move(){
		super.move();
		if(cnt == bendTime){
			aim += bendAim;
			speed = afSpeed;
		}
//		poseZ = aim/PI*180.0;
	}
}
public class AccBullet:StraightBullet{
	double maxSpeed ,accSpeed;
	public this(Vector3 v ,bool breakable,double aim ,double min ,double max ,double acc){
		
		super(v ,breakable ,aim ,min);
		maxSpeed = max;
		accSpeed = acc;
	}
	public override void move(){
		super.move();
		if(speed < maxSpeed)speed += accSpeed;
		else speed = maxSpeed;
	}
}

public class HomingBullet:StraightBullet{
	private:
	double dAim;
//	int bendTime;
//	double afSpeed;
	public this(Vector3 v ,bool breakable,double aim ,double dAim = PI / 90.0,double speed = 4.0 ,int num = 1){
		super(v ,breakable ,aim ,speed);
		this.dAim = dAim;
		num--;
		if(0<num){
			Parts p = new HomingBullet(v ,breakable ,aim ,dAim ,speed ,num);
			addChild(p, "f", 34 ,FOLLOW );
		}
	}
	public override void move(){
		
		super.move();
		if(parent is null){
			double taim = atan2(ship.rpos.y-rpos.y ,ship.rpos.x-rpos.x);
			if(abs(aim -taim) < dAim){}
			else if(raimmark(aim ,taim) < 0)aim -= dAim;
			else aim += dAim;
			
			aim = radlimit(aim);
			
			poseZ = aim*180.0/PI;
		}
//		poseZ = aim/PI*180.0;
	}
}