-
Notifications
You must be signed in to change notification settings - Fork 0
/
BossPointer.java
130 lines (90 loc) · 5.65 KB
/
BossPointer.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
package mkat.apps.spacewars;
import org.andengine.engine.handler.IUpdateHandler;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.util.math.MathUtils;
public class BossPointer extends Sprite{
Sprite pointer;
Boss associatedBoss;
//mm = new MoveModifier(1, GameLevel.getInstance().mPlayer.getX(), GameLevel.getInstance().mPlayer.getY(), sprite.getX(),sprite.getY());
//pointer.registerEntityModifier(mm);
public BossPointer(ITextureRegion pTextureRegion, Boss toBoss) {
super(GameLevel.getInstance().mPlayer.getX(),GameLevel.getInstance().mPlayer.getY(), pTextureRegion, ResourceManager.getInstance().engine.getVertexBufferObjectManager());
pointer = this;
associatedBoss = toBoss;
setupPointer();
}
//setup laser:
private void setupPointer() {
pointer.setCullingEnabled(true);
pointer.setAlpha(1f);
//thisGameLevel.attachChild(pointer);
//END COMPASS
//COMPASS
//Log.v("","number of enemies in array " + enemyCount);
GameLevel.getInstance().registerUpdateHandler(new IUpdateHandler() {
@Override
public void onUpdate(float pSecondsElapsed) {
//Pointer for Compass
if (GameLevel.getInstance().PlayerReady){
//COMPASS
final float dX = GameLevel.getInstance().mPlayer.getX() - associatedBoss.getX();
final float dY = GameLevel.getInstance().mPlayer.getY() - associatedBoss.getY();
/* Calculate the angle of rotation in radians*/
final float angle = (float) Math.atan2(-dY, dX);
/* Convert the angle from radians to degrees, adding the
default image rotation */
final float rotation = MathUtils.radToDeg(angle-90);
/* Set the arrow's new rotation */
pointer.setRotation(rotation);
if ((GameLevel.getInstance().bossPointerLine != null) && GameLevel.getInstance().bossPointerLine.collidesWith(GameLevel.getInstance().mPlayer.compass1)){
//equation of compass 1
float x = GameLevel.getInstance().mPlayer.compass1.getX1();
//find the equation of direction line between enemy and player
float slope = (GameLevel.getInstance().bossPointerLine.getY1() - GameLevel.getInstance().bossPointerLine.getY2())/(GameLevel.getInstance().bossPointerLine.getX1()-GameLevel.getInstance().bossPointerLine.getX2());
float b = GameLevel.getInstance().bossPointerLine.getY1() - (slope * GameLevel.getInstance().bossPointerLine.getX1());
//substitute x into y and we get our point of intersection
float y = slope*x + b;
//x and y are where we put our pointer (subtract 5 pixels for viewing purposes)
pointer.setPosition(x+5, y);
} else if ((GameLevel.getInstance().bossPointerLine != null) && GameLevel.getInstance().bossPointerLine.collidesWith(GameLevel.getInstance().mPlayer.compass2)) {
//equation of compass 2
float y = GameLevel.getInstance().mPlayer.compass2.getY1();
//find the equation of direction line between enemy and player
float slope = (GameLevel.getInstance().bossPointerLine.getY1() - GameLevel.getInstance().bossPointerLine.getY2())/(GameLevel.getInstance().bossPointerLine.getX1()-GameLevel.getInstance().bossPointerLine.getX2());
float b = GameLevel.getInstance().bossPointerLine.getY1() - (slope * GameLevel.getInstance().bossPointerLine.getX1());
//substitute x into y and we get our point of intersection
float x = (y - b)/slope;
//x and y are where we put our pointer (subtract 5 pixels for viewing purposes)
pointer.setPosition(x, y-5);
} else if ((GameLevel.getInstance().bossPointerLine != null) && GameLevel.getInstance().bossPointerLine.collidesWith(GameLevel.getInstance().mPlayer.compass3)) {
//equation of compass 3
float x = GameLevel.getInstance().mPlayer.compass3.getX1();
//find the equation of direction line between enemy and player
float slope = (GameLevel.getInstance().bossPointerLine.getY1() - GameLevel.getInstance().bossPointerLine.getY2())/(GameLevel.getInstance().bossPointerLine.getX1()-GameLevel.getInstance().bossPointerLine.getX2());
float b = GameLevel.getInstance().bossPointerLine.getY1() - (slope * GameLevel.getInstance().bossPointerLine.getX1());
//substitute x into y and we get our point of intersection
float y = slope*x + b;
//x and y are where we put our pointer (subtract 5 pixels for viewing purposes)
pointer.setPosition(x-5, y);
} else if ((GameLevel.getInstance().bossPointerLine != null) && GameLevel.getInstance().bossPointerLine.collidesWith(GameLevel.getInstance().mPlayer.compass4)) {
//equation of compass 2
float y = GameLevel.getInstance().mPlayer.compass4.getY1();
//find the equation of direction line between enemy and player
float slope = (GameLevel.getInstance().bossPointerLine.getY1() - GameLevel.getInstance().bossPointerLine.getY2())/(GameLevel.getInstance().bossPointerLine.getX1()-GameLevel.getInstance().bossPointerLine.getX2());
float b = GameLevel.getInstance().bossPointerLine.getY1() - (slope * GameLevel.getInstance().bossPointerLine.getX1());
//substitute x into y and we get our point of intersection
float x = (y - b)/slope;
//x and y are where we put our pointer (subtract 5 pixels for viewing purposes)
pointer.setPosition(x, y+5);
}
}
}
@Override
public void reset() {
// TODO Auto-generated method stub
}
});
//END COMPASS
}
}