-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlusPointer.java
158 lines (114 loc) · 5.84 KB
/
PlusPointer.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
package mkat.apps.spacewars;
import org.andengine.engine.handler.IUpdateHandler;
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 android.util.Log;
public class PlusPointer extends Sprite{
Sprite pointer, powerup1;
Line line;
String type1;
//mm = new MoveModifier(1, GameLevel.getInstance().mPlayer.getX(), GameLevel.getInstance().mPlayer.getY(), sprite.getX(),sprite.getY());
//pointer.registerEntityModifier(mm);
public PlusPointer(ITextureRegion pTextureRegion, Sprite powerup, String type) {
super(GameLevel.getInstance().mPlayer.getX(),GameLevel.getInstance().mPlayer.getY(), pTextureRegion, ResourceManager.getInstance().engine.getVertexBufferObjectManager());
pointer = this;
powerup1 = powerup;
type1 = type;
if (type1 == "Health"){
line = GameLevel.getInstance().plusPointerHealthLine;
Log.v("","LINE IS HEALTH");
} else if (type1 == "FireRate"){
line = GameLevel.getInstance().plusPointerRateLine;
Log.v("","LINE IS RATE");
} else if (type1 == "FirePower"){
line = GameLevel.getInstance().plusPointerPowerLine;
Log.v("","LINE IS POWER");
} else {
line = null;
}
setupPointer();
}
//setup laser:
private void setupPointer() {
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){
if (type1 == "Health" && (GameLevel.getInstance().plusPointerHealthLine != null)){
GameLevel.getInstance().plusPointerHealthLine.setPosition(powerup1.getX(), powerup1.getY(), GameLevel.getInstance().mPlayer.getX(), GameLevel.getInstance().mPlayer.getY());
}
if (type1 == "FireRate" && (GameLevel.getInstance().plusPointerRateLine != null)){
GameLevel.getInstance().plusPointerRateLine.setPosition(powerup1.getX(), powerup1.getY(), GameLevel.getInstance().mPlayer.getX(), GameLevel.getInstance().mPlayer.getY());
}
if (type1 == "FirePower" && (GameLevel.getInstance().plusPointerPowerLine != null)){
GameLevel.getInstance().plusPointerPowerLine.setPosition(powerup1.getX(), powerup1.getY(), GameLevel.getInstance().mPlayer.getX(), GameLevel.getInstance().mPlayer.getY());
}
//COMPASS
final float dX = GameLevel.getInstance().mPlayer.getX() - powerup1.getX();
final float dY = GameLevel.getInstance().mPlayer.getY() - powerup1.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 ( (line != null) && line.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 = (line.getY1() - line.getY2())/(line.getX1()-line.getX2());
float b = line.getY1() - (slope * line.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 ( (line != null) && line.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 = (line.getY1() - line.getY2())/(line.getX1()-line.getX2());
float b = line.getY1() - (slope * line.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 ( (line != null) && line.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 = (line.getY1() - line.getY2())/(line.getX1()-line.getX2());
float b = line.getY1() - (slope * line.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 ( (line != null) && line.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 = (line.getY1() - line.getY2())/(line.getX1()-line.getX2());
float b = line.getY1() - (slope * line.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
}
}