-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lvl1BossLaser.java
333 lines (249 loc) · 11.7 KB
/
Lvl1BossLaser.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
package mkat.apps.spacewars;
import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.andengine.entity.modifier.ScaleModifier;
import org.andengine.entity.primitive.Line;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.util.math.MathUtils;
import org.andengine.util.modifier.IModifier;
import android.util.Log;
public class Lvl1BossLaser extends Sprite{
Sprite sprite = null;
Lvl1Boss callingBossHere = null;
int count = 0;
float fromX = 0;
float fromY = 0;
float rotAngle = 0;
float a, o = 0; //Point of intersection between both lines
float laserdtoTravel = 0;
float laserVelocity, laserMoveDuration = 0;
boolean registerUnregister = false;
Line line1, line2, line3, line4;
MoveModifier mod;
ScaleModifier scale;
IEntityModifierListener laserModifierListener;
public Lvl1BossLaser(ITextureRegion pTextureRegion, float x, float y, float rAngle, Lvl1Boss callingBoss) {
super(x,y,pTextureRegion, ResourceManager.getInstance().engine.getVertexBufferObjectManager());
fromX = x;
fromY = y;
rotAngle = rAngle;
sprite = this;
sprite.setVisible(true);
sprite.setCullingEnabled(true);
sprite.setIgnoreUpdate(false);
sprite.setColor(1, 1, 1);
sprite.setRotation(rotAngle);
Log.v("","creates boss lasers");
setupBossLaser(sprite);
callingBossHere = callingBoss;
//GameLevel.getInstance().attachChild(allLasers[g]);
}
//setup laser:
private void setupBossLaser(Sprite laser) {
//Log.v("","sets up enemy laser");
//Log.v("", "value of laserFired " + GameLevel.getInstance().laserFired);
//sprite.dispose();
//.setAnchorCenter(.getHeight(), .getWidth());
//set the laser to invisible exactly as soon as it finishes reaching its destination
//.setPosition(GameLevel.getInstance().touchX,GameLevel.getInstance().touchY);
final Sprite laser2;
laser2 = laser;
laserModifierListener = new IEntityModifierListener() {
//When the modifier starts, this method is called
@Override
public void onModifierStarted(IModifier<IEntity> pModifier, final IEntity pItem){
}
//When the modifier finishes, this method is called
@Override
public void onModifierFinished(final IModifier<IEntity> pModifer, final IEntity pItem){
laser2.setVisible(false);
callingBossHere.bulletLifeEnd = true;
}
//AFTER THIS PLAYER"S LIFE = 0, so game over, dump current scene, load game over text and quit to menu.
};
Log.v("","which sprite");
if (((laser2.getRotation()==-45))){
//equation of the circle:
a = (float)Math.cos(MathUtils.degToRad(-45f))*(ResourceManager.getInstance().cameraWidth*0.375f);
o = (float)Math.sin(MathUtils.degToRad(-45f))*(ResourceManager.getInstance().cameraWidth*0.375f);
//laser2.setRotation(-90);
//add a to y, o to x
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, (fromX-o), (fromY+a));
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = ResourceManager.getInstance().cameraHeight/1.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
count++;
if (laser2.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
laser2.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, fromX-o, fromY+a);
scale = new ScaleModifier(laserMoveDuration, 1, 10);
scale.addModifierListener(laserModifierListener);
mod.addModifierListener(laserModifierListener);
laser2.registerEntityModifier(mod);
laser2.registerEntityModifier(scale);
}
} else if (((laser2.getRotation()==-90))){
//equation of the circle:
//add a to y, o to x
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, (fromX-(ResourceManager.getInstance().cameraWidth*0.375f)), (fromY));
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = ResourceManager.getInstance().cameraHeight/1.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
count++;
if (laser2.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
laser2.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, fromX-(ResourceManager.getInstance().cameraWidth*0.375f), fromY);
mod.addModifierListener(laserModifierListener);
scale = new ScaleModifier(laserMoveDuration, 1, 10);
scale.addModifierListener(laserModifierListener);
laser2.registerEntityModifier(mod);
laser2.registerEntityModifier(scale);
}
} else if (((laser2.getRotation()==-135))){
//equation of the circle:
a = (float)Math.cos(MathUtils.degToRad(-45f))*(ResourceManager.getInstance().cameraWidth*0.375f);
o = (float)Math.sin(MathUtils.degToRad(-45f))*(ResourceManager.getInstance().cameraWidth*0.375f);
//laser2.setRotation(0);
//add a to y, o to x
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, (fromX-o), (fromY-a));
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = (ResourceManager.getInstance().cameraHeight)/1.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
count++;
if (laser2.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
laser2.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, fromX-o, fromY-a);
mod.addModifierListener(laserModifierListener);
scale = new ScaleModifier(laserMoveDuration, 1, 10);
scale.addModifierListener(laserModifierListener);
laser2.registerEntityModifier(mod);
laser2.registerEntityModifier(scale);
}
} else if (((laser2.getRotation()==-180))){
//equation of the circle:
//add a to y, o to x
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, (fromX), (fromY-(ResourceManager.getInstance().cameraWidth*0.375f)));
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = (ResourceManager.getInstance().cameraHeight)/1.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
count++;
if (laser2.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
laser2.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, fromX, fromY-(ResourceManager.getInstance().cameraWidth*0.375f));
mod.addModifierListener(laserModifierListener);
scale = new ScaleModifier(laserMoveDuration, 1, 10);
scale.addModifierListener(laserModifierListener);
laser2.registerEntityModifier(mod);
laser2.registerEntityModifier(scale);
}
} else if (((laser2.getRotation()==-225))){
//equation of the circle:
a = (float)Math.cos(MathUtils.degToRad(-45f))*(ResourceManager.getInstance().cameraWidth*0.375f);
o = (float)Math.sin(MathUtils.degToRad(-45f))*(ResourceManager.getInstance().cameraWidth*0.375f);
//laser2.setRotation(-45);
//add a to y, o to x
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, (fromX+o), (fromY-a));
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = (ResourceManager.getInstance().cameraHeight)/1.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
count++;
if (laser2.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
laser2.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, fromX+o, fromY-a);
mod.addModifierListener(laserModifierListener);
scale = new ScaleModifier(laserMoveDuration, 1, 10);
scale.addModifierListener(laserModifierListener);
laser2.registerEntityModifier(mod);
laser2.registerEntityModifier(scale);
}
} else if (((laser2.getRotation()==-270))){
//equation of the circle:
//add a to y, o to x
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, (fromX+(ResourceManager.getInstance().cameraWidth*0.375f)), (fromY));
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = (ResourceManager.getInstance().cameraHeight)/1.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
count++;
if (laser2.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
laser2.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, fromX+(ResourceManager.getInstance().cameraWidth*0.375f), fromY);
mod.addModifierListener(laserModifierListener);
scale = new ScaleModifier(laserMoveDuration, 1, 10);
scale.addModifierListener(laserModifierListener);
laser2.registerEntityModifier(mod);
laser2.registerEntityModifier(scale);
}
} else if (((laser2.getRotation()==-315))){
//equation of the circle:
a = (float)Math.cos(MathUtils.degToRad(-45))*(ResourceManager.getInstance().cameraWidth*0.375f);
o = (float)Math.sin(MathUtils.degToRad(-45))*(ResourceManager.getInstance().cameraWidth*0.375f);
//laser2.setRotation(0);
//add a to y, o to x
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, (fromX+o), (fromY+a));
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = (ResourceManager.getInstance().cameraHeight)/1.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
count++;
if (laser2.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
laser2.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, fromX+o, fromY+a);
mod.addModifierListener(laserModifierListener);
scale = new ScaleModifier(laserMoveDuration, 1, 10);
scale.addModifierListener(laserModifierListener);
laser2.registerEntityModifier(mod);
laser2.registerEntityModifier(scale);
}
} else if (((laser2.getRotation()==-360))){
//equation of the circle:
//add a to y, o to x
//let's get the distance our laser has to travel
laserdtoTravel = MathUtils.distance(fromX, fromY, (fromX), (fromY+(ResourceManager.getInstance().cameraWidth*0.375f)));
//Log.v("",Float.toString(laserdtoTravel));
//let's get the velocity
laserVelocity = (ResourceManager.getInstance().cameraHeight)/1.0f;
laserMoveDuration = (laserdtoTravel/laserVelocity);
count++;
if (laser2.getEntityModifierCount()>=0){
//mod.removeModifierListener(laserModifierListener);
laser2.clearEntityModifiers();
//Log.v("", "gets here!");
mod = new MoveModifier(laserMoveDuration, fromX, fromY, fromX, fromY+(ResourceManager.getInstance().cameraWidth*0.375f));
mod.addModifierListener(laserModifierListener);
scale = new ScaleModifier(laserMoveDuration, 1, 10);
scale.addModifierListener(laserModifierListener);
laser2.registerEntityModifier(mod);
laser2.registerEntityModifier(scale);
}
}
}
}