File: enemy.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 (246 lines) | stat: -rw-r--r-- 6,811 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
241
242
243
244
245
246
module br.enemy;
private import std.string;
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.ring;
private import br.blast;
private import br.sound;
private import br.gamemanager;
private import std.math;
private import br.mainloop;
private import opengl;
private import SDL_mixer;

public class Enemy:Parts,Caller{
	private:
	double hp;
	double maxHp;
	bool vincible;
	bool border;
	bool inStage;
	double damage;
	static const int DIVISION = 8;
	static double[] si;
	static double[] co;
	public this(double hp,double R = -1,double G = -1 ,double B = -1 ,double alpha = -1){
		if(R < 0.0 || G < 0.0 || B < 0.0 || alpha < 0.0){
			if(hp < 0){
				this.R = 1.0; this.G = 1.0; this.B = 0.95; this.alpha = 1.0;
			}else{
				
				this.R=0.7; this.G=0.75; this.B=1.0; this.alpha=1.5;
			}
		}else{
			this.R = R;
			this.G = G;
			this.B = B;
			this.alpha = alpha;
		}
		if(hp < 0){
			this.hp = 100;
			vincible = false;
		}else{
			this.hp = hp;
			
			vincible = true;
		}
		
		maxHp = this.hp;
		border = true;
		inStage = false;
		damage = 0;
		enemyManager.add(this);
		collisionManager.add(this, collisionManager.kind.SHIP ,2);
		collisionManager.add(this, collisionManager.kind.SWORD ,2);
		drawing = POLYGON | WIRE;
		
		}
	public override void  move(){
		super.move();
//		moveImpl();
		if(border &&(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();
		}
		if((1e-6) < damage){
			
			double radZ ,radX;
			radZ = rand.nextFloat(PI * 2.0);
			radX = rand.nextFloat(PI);
			vibrate(radZ ,radX ,damage);
			
			damage -= 0.1;
		}else damage = 0.0;
	}
	public void disableBorder(){
		border = false;
	}
	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);
		enemyManager.add(child);
//		if(vincible)super.setColor(R ,G ,B ,alpha);
	}
	public override void setColor(double R ,double G ,double B ,double alpha){
		if(vincible)super.setColor(R ,G ,B ,alpha);
	}
	public void setTarget(){
		setColor(1.0,0.7,0.8,1.5);
		
		/*
		foreach(Parts child;cast(Parts[])childHash.values){
			child.setColor(R ,G ,B ,alpha);
		}
		*/
	}
	public override void draw(){
		super.draw();
		if(si.length == 0){
			si.length = DIVISION;
			for(int i=0;i<DIVISION;i++){
				si[i] = sin(PI *2.0 * cast(double)i / DIVISION);
			}
		}
		if(co.length == 0){
			co.length = DIVISION;
			for(int i=0;i<DIVISION;i++){
				co[i] = cos(PI *2.0 * cast(double)i / DIVISION);
			}
		}
		if(vincible){
			//double R,G,B,alpha;
			//R=1.0; G=0.85;B=0.9;alpha=1.0;
			double ihp =ceil(hp);
			double radius;
			double rsize;
			double dist = size * 1.8;
			double R ,G ,B;
			double alpha = this.alpha * 0.7;
			R = fmin(1.0 ,(this.R + 0.05) * (this.R + 0.05));
			G = fmin(1.0 ,(this.G + 0.05) * (this.G + 0.05));
			B = fmin(1.0 ,(this.B + 0.05) * (this.B + 0.05));
			for(double i=0;i<hp;i+= 1.0){
				glPushMatrix();
				double rad = (-cast(double)(cnt%150)/150.0 + cast(double)i/ihp) * PI * 2.0;
				if(i < floor(hp))rsize = 15.0;
				else rsize = fmax(5.0 ,(hp - i) * 15.0);
				//rsize = 10.0;
				if(cnt % 30 < 15)radius = rsize *(1.0 - cast(double)(cnt % 15) /15.0 * 0.2);
				else radius = rsize * (1.0 - cast(double)((cnt - 15) % 15) /15.0 * 0.2);
				radius *= 0.7;
				//radius = 15.0;
				glTranslatef(cos(rad) * dist, sin(rad) * dist ,0.0);
				for(int j=0;j<DIVISION-1;j++){
					
					glBegin(GL_POLYGON);
					glColor3f(R * alpha * 0.3,G * alpha * 0.3 ,B * alpha * 0.3);
	//				glColor4f(R,G,B,0.0);
					glVertex3f(radius*co[j],radius*si[j] ,0.0);
					glVertex3f(radius*co[j+1],radius*si[j+1] ,0.0);
					glColor3f(R * alpha,G * alpha ,B * alpha);
	//				glColor4f(R,G,B,alpha);
					glVertex3f(0.0,0.0 ,0.0);
					
					glEnd();
				}
				glBegin(GL_POLYGON);
				glColor3f(R * alpha * 0.3,G * alpha * 0.3 ,B * alpha * 0.3);
	//			glColor4f(R,G,B,0);
				glVertex3f(radius*co[0],radius*si[0] ,0.0);
				glVertex3f(radius*co[DIVISION-1],radius*si[DIVISION-1] ,0.0);
				glColor3f(R * alpha,G * alpha ,B * alpha);
	//			glColor4f(R,G,B,alpha);
				glVertex3f(0.0,0.0 ,0.0);
				glEnd();
				glPopMatrix();
			}
		}
		
	}
	public void reportRing(Ring ring){
	}
	public override void destroy(){
		super.destroy();
		if(maxHp < 2.0)makeSimpleParticle(4 ,size ,WIRE ,rpos ,R ,G ,B ,alpha * 0.5);
		else makeParticle(shape, size ,WIRE ,rpos ,new Vector3() ,rpose ,R ,G ,B ,alpha);
		new SmallBlast(rpos.x ,rpos.y ,20 ,20 ,10.0 ,90 ,R ,G ,B ,0.1);
	}
	public override void vanish(){
		super.vanish();
	}
	public override void reportCollision(int kind){
		switch(kind){
			case collisionManager.kind.SWORD:
			
			double d;
			d = 1.0;//0.5 + 0.6 * fmin(1.0 ,fmax(0.0 ,(ship.laserSpeed - ship.laserMinSpeed) / (ship.laserMaxSpeed - ship.laserMinSpeed)));
			if(vincible){
				hp = hp - d;//fmax(ceil(hp-1.0) ,hp - d);
				if(hp <= 0)destroy();
				Sound_PlaySe(se_kind.SLASH);
//				Mix_PlayChannel(-1, chunk_slash, 0);
				
			}else{
				Sound_PlaySe(se_kind.DEFEND);
//				Mix_PlayChannel(-1, chunk_defend, 0);
				d *= 0.3;
			}
			
			damage = fmin(3.0 ,damage+d);
			
			break;
			default:break;
		}
	}
	public override bool exists(){
		return super.exists;
	}
}
public class Boss:Enemy{
	public:
	string state;
	int nowStateCnt;
	public this(double hp,double R = -1.0,double G = -1.0 ,double B = -1.0 ,double alpha = -1.0){
		
		if(R < 0.0 || G < 0.0 || B < 0.0 || alpha < 0.0){
			R=0.9; G=0.45; B=1.0; alpha=1.5;
		}
		super(hp ,R ,G ,B ,alpha);
		nowStateCnt = 0;
		disableBorder();
		state = "start";
	}
	public void changeState(string state){
		this.state = state;
		nowStateCnt = -1;
	}
	public override void destroy(){
		super.destroy();
//		makeParticle(shape, size ,WIRE ,rpos ,new Vector3() ,rpose ,R ,G ,B ,alpha * 2.0);
		new Blast(rpos.x ,rpos.y ,20.0 ,15.0 ,90 ,R ,G ,B ,0.2);
		Sound_PlaySe(se_kind.BOMB);
//		Mix_PlayChannel(-1, chunk_bomb, 0);
	}
	public override void move(){
		super.move();
		nowStateCnt ++;
	}
	
}

public class AttackRing:Ring{
	public this(Enemy caller ,string name ,int span ,double R=1.0 ,double G=0.4,double B=1.0,double alpha =1.0){
		super(caller ,caller.rpos ,name ,span ,R ,G ,B ,alpha);
		
	}
	
}