-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLvl5BossLaser.java
362 lines (274 loc) · 14.5 KB
/
Lvl5BossLaser.java
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package mkat.apps.spacewars;
import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.CardinalSplineMoveModifier;
import org.andengine.entity.modifier.CardinalSplineMoveModifier.CardinalSplineMoveModifierConfig;
import org.andengine.entity.modifier.DelayModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.modifier.ParallelEntityModifier;
import org.andengine.entity.modifier.RotationModifier;
import org.andengine.entity.modifier.SequenceEntityModifier;
import org.andengine.entity.particle.BatchedSpriteParticleSystem;
import org.andengine.entity.particle.emitter.PointParticleEmitter;
import org.andengine.entity.particle.initializer.AccelerationParticleInitializer;
import org.andengine.entity.particle.initializer.ExpireParticleInitializer;
import org.andengine.entity.particle.modifier.ScaleParticleModifier;
import org.andengine.entity.primitive.Line;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.sprite.UncoloredSprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.util.math.MathUtils;
import org.andengine.util.modifier.IModifier;
import android.opengl.GLES20;
public class Lvl5BossLaser extends Sprite{
Sprite sprite = null;
Lvl5Boss callingBossHere = null;
int count = 0;
float fromX = 0;
float fromY = 0;
float rotAngle = 0;
float m, m2 = 0;//slope of boundary line and intersecting line
float b, b2 = 0;//y-int of boundary line and intersecting line
float dy, dx = 0;//for intersecting line
float x, y = 0; //Point of intersection between both lines
float laserdtoTravel = 0;
float laserVelocity, laserMoveDuration = 0;
boolean registerUnregister = false;
Line line1, line2, line3, line4;
MoveModifier mod;
CardinalSplineMoveModifier path;
CardinalSplineMoveModifierConfig pathPoints;
IEntityModifierListener laserModifierListener;
public Lvl5BossLaser(ITextureRegion pTextureRegion, float x, float y, float rAngle, Lvl5Boss callingBoss) {
super(x,y,pTextureRegion, ResourceManager.getInstance().engine.getVertexBufferObjectManager());
fromX = x;
fromY = y;
sprite = this;
rotAngle = rAngle;
//Log.v("","creates enemy laser");
setupBossLaser();
callingBossHere = callingBoss;
}
//setup laser:
private void setupBossLaser() {
//Log.v("","sets up enemy laser");
//Log.v("", "value of laserFired " + GameLevel.getInstance().laserFired);
sprite.setCullingEnabled(true);
sprite.setVisible(true);
sprite.setIgnoreUpdate(false);
sprite.setColor(1, 1, 1);
sprite.setScale(3);
//final float pTension = MathUtils.random(0f, 1f);
//sprite.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE);
//sprite.setColor(pTension, 1, 1, 1);
//sprite.setAnchorCenter(sprite.getHeight(), sprite.getWidth());
//set the laser to invisible exactly as soon as it finishes reaching its destination
laserModifierListener = new IEntityModifierListener() {
@Override
public void onModifierStarted(IModifier<IEntity> pModifier, final IEntity pItem){
}
@Override
public void onModifierFinished(final IModifier<IEntity> pModifer, final IEntity pItem){
sprite.setVisible(false);
callingBossHere.bulletLifeEnd = true;
}
};
//sprite.setPosition(GameLevel.getInstance().touchX,GameLevel.getInstance().touchY);
sprite.setRotation(rotAngle);
//fromX = GameLevel.getInstance().enemyX2;
//fromY = GameLevel.getInstance().enemyY2;
//mod = new MoveModifier(.5f, fromX, fromY, 1000, 1000);
if (((sprite.getRotation()<= -180.0) && (sprite.getRotation() > -270.0))){
//equation of boundary line
m = 0.6f;
b = fromY - ((fromX+ResourceManager.getInstance().cameraHeight)*(m));
//find equation of line for intersecting line
dx = fromX - GameLevel.getInstance().mPlayer.getX();
dy = fromY - GameLevel.getInstance().mPlayer.getY();
m2 = dy/dx;
b2 = GameLevel.getInstance().mPlayer.getY() - ((GameLevel.getInstance().mPlayer.getX())*m2);
//Now solve for the point of intersection between our boundary line and our intersecting line.
x = (b2 - b)/(m - m2);
//Now with our x, solve for y in either equation:
y = (m*x) + b;
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, x, y);
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = ResourceManager.getInstance().cameraWidth/2.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
//setup path modifier
//setup control points point1:boss x,y; point2,3,4 are player x,y
final float pointsListX[] = {
fromX, fromX+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),fromX+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),x+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f))
};
final float pointsListY[] = {
fromY, fromY-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),fromY-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),y-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f))
};
final int controlPointCount = pointsListX.length;
pathPoints = new CardinalSplineMoveModifierConfig(controlPointCount, -1f);
for (int i = 0; i < controlPointCount; i++){
final float positionX = pointsListX[i];
final float positionY = pointsListY[i];
pathPoints.setControlPoint(i, (int)Math.round(positionX), (int)Math.round(positionY));
}
//end setuppath modifier
count++;
if (sprite.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
sprite.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, x, y);
//path = new CardinalSplineMoveModifier(laserMoveDuration, pathPoints);
mod.addModifierListener(laserModifierListener);
//path.addModifierListener(laserModifierListener);
//sprite.registerEntityModifier(mod);
sprite.registerEntityModifier(mod);
}
} else if ((sprite.getRotation()<= -270.0) && (sprite.getRotation() >= -360.0)){
//equation of boundary line
m = -0.6f;
b = fromY - ((fromX+ResourceManager.getInstance().cameraHeight)*(m));
//find equation of line for intersecting line
//find equation of line for intersecting line
dx = fromX - GameLevel.getInstance().mPlayer.getX();
dy = fromY - GameLevel.getInstance().mPlayer.getY();
m2 = dy/dx;
b2 = GameLevel.getInstance().mPlayer.getY() - ((GameLevel.getInstance().mPlayer.getX())*m2);
//Now solve for the point of intersection between our boundary line and our intersecting line.
x = (b2 - b)/(m - m2);
//Now with our x, solve for y in either equation:
y = (m*x) + b;
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, x, y);
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = ResourceManager.getInstance().cameraWidth/2.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
//setup path modifier
//setup control points point1:boss x,y; point2,3,4 are player x,y
final float pointsListX[] = {
fromX, fromX+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),fromX+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),x+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f))
};
final float pointsListY[] = {
fromY, fromY+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),fromY+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),y+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f))
};
final int controlPointCount = pointsListX.length;
pathPoints = new CardinalSplineMoveModifierConfig(controlPointCount, -1);
for (int i = 0; i < controlPointCount; i++){
final float positionX = pointsListX[i];
final float positionY = pointsListY[i];
pathPoints.setControlPoint(i, (int)Math.round(positionX), (int)Math.round(positionY));
}
//end setuppath modifier
count++;
if (sprite.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
sprite.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, x, y);
//path = new CardinalSplineMoveModifier(laserMoveDuration, pathPoints);
mod.addModifierListener(laserModifierListener);
//path.addModifierListener(laserModifierListener);
//sprite.registerEntityModifier(mod);
sprite.registerEntityModifier(mod);
}
} else if ((sprite.getRotation()<= 0.0) && (sprite.getRotation() > -90.0)){
//equation of boundary line
m = 0.6f;
b = fromY - ((fromX-ResourceManager.getInstance().cameraHeight)*(m));
//find equation of line for intersecting line
//find equation of line for intersecting line
dx = fromX - GameLevel.getInstance().mPlayer.getX();
dy = fromY - GameLevel.getInstance().mPlayer.getY();
m2 = dy/dx;
b2 = GameLevel.getInstance().mPlayer.getY() - ((GameLevel.getInstance().mPlayer.getX())*m2);
//Now solve for the point of intersection between our boundary line and our intersecting line.
x = (b2 - b)/(m - m2);
//Now with our x, solve for y in either equation:
y = (m*x) + b;
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, x, y);
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = ResourceManager.getInstance().cameraWidth/2.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
//setup path modifier
//setup control points point1:boss x,y; point2,3,4 are player x,y
final float pointsListX[] = {
fromX, fromX-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),fromX-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),x-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f))
};
final float pointsListY[] = {
fromY, fromY+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),fromY+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),y+(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f))
};
final int controlPointCount = pointsListX.length;
pathPoints = new CardinalSplineMoveModifierConfig(controlPointCount, -1);
for (int i = 0; i < controlPointCount; i++){
final float positionX = pointsListX[i];
final float positionY = pointsListY[i];
pathPoints.setControlPoint(i, (int)Math.round(positionX), (int)Math.round(positionY));
}
//end setuppath modifier
count++;
if (sprite.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
sprite.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, x, y);
//path = new CardinalSplineMoveModifier(laserMoveDuration, pathPoints);
mod.addModifierListener(laserModifierListener);
//path.addModifierListener(laserModifierListener);
//sprite.registerEntityModifier(mod);
sprite.registerEntityModifier(mod);
}
} else {
//GameLevel.getInstance().laserFired = false;
//equation of boundary line
m = -0.6f;
b = (fromY) - (fromX-ResourceManager.getInstance().cameraHeight)*(m);
//find equation of line for intersecting line
dx = fromX - GameLevel.getInstance().mPlayer.getX();
dy = fromY - GameLevel.getInstance().mPlayer.getY();
m2 = dy/dx;
b2 = GameLevel.getInstance().mPlayer.getY() - ((GameLevel.getInstance().mPlayer.getX())*m2);
//Now solve for the point of intersection between our boundary line and our intersecting line.
x = (b2 - b)/(m - m2);
//Now with our x, solve for y in either equation:
y = (m*x) + b;
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, x, y);
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = ResourceManager.getInstance().cameraWidth/2.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
//setup path modifier
//setup control points point1:boss x,y; point2,3,4 are player x,y
final float pointsListX[] = {
fromX, fromX-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),fromX-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),x-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f))
};
final float pointsListY[] = {
fromY, fromY-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),fromY-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f)),y-(float)(Math.random()*(ResourceManager.getInstance().cameraWidth*0.25f))
};
final int controlPointCount = pointsListX.length;
pathPoints = new CardinalSplineMoveModifierConfig(controlPointCount, -1);
for (int i = 0; i < controlPointCount; i++){
final float positionX = pointsListX[i];
final float positionY = pointsListY[i];
pathPoints.setControlPoint(i, (int)Math.round(positionX), (int)Math.round(positionY));
}
//end setuppath modifier
count++;
if (sprite.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
sprite.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, x, y);
//path = new CardinalSplineMoveModifier(laserMoveDuration, pathPoints);
mod.addModifierListener(laserModifierListener);
//path.addModifierListener(laserModifierListener);
//sprite.registerEntityModifier(mod);
sprite.registerEntityModifier(mod);
}
}
}
}