-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockOnEnemy.java
More file actions
51 lines (44 loc) · 1.11 KB
/
LockOnEnemy.java
File metadata and controls
51 lines (44 loc) · 1.11 KB
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
/**
* This is an extension of the enemy Class,
* This enemy simply aims at the player the whole time
* @author elan
*
*/
public class LockOnEnemy extends Enemy
{
public LockOnEnemy(double x, double y, double a, int i, int hp)
{
super(x, y, a, i, hp);
}
public void update()
{
super.update();
updateAngle();
}
public void updateAngle()
{
if(Controller.player.getX() <= xPos)
angle = Math.toDegrees(Math.atan((yPos - Controller.player.getY())/(double)(xPos - Controller.player.getX()))) - 90;
else
angle = Math.toDegrees(Math.atan((yPos - Controller.player.getY())/(double)(xPos - Controller.player.getX()))) + 90;
if(angle > 90)
angle = 90;
else if(angle < -90)
angle = -90;
}
public void render()
{
String type = "";
if(States.enemyHealth > 23)
type = "LockOnEnemy4.png";
else if(States.enemyHealth > 18)
type = "LockOnEnemy3.png";
else if(States.enemyHealth > 13)
type = "LockOnEnemy2.png";
else
type = "LockOnEnemy1.png";
StdDraw.picture(xPos, yPos, type, States.enemySize, States.enemySize, angle);
if(HP < States.enemyHealth)
renderHPbar();
}
}