-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomingBullet.java
More file actions
51 lines (48 loc) · 1.42 KB
/
HomingBullet.java
File metadata and controls
51 lines (48 loc) · 1.42 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 Class can be used to create HomingBullet objects
* @author elan
*
*/
public class HomingBullet extends EnemyBullet
{
/**
* Cunstructor for the HomingBullet object
* @param enemy Bullet will be created with same x, y, and angle as this entity
* @param index Give the HomingBullet a unique index to identify it
*/
public HomingBullet(Entity enemy, int index)
{
super(enemy, index);
angle = enemy.getAngle() + 180;
}
/**
* Does all nessisary updates for the Bullet object
*/
public void update()
{
super.update();
updateAngle();
}
/**
* gradually changes the trajectory of the bullet to aim for the player
*/
public void updateAngle()
{
if(Controller.player.getX() <= xPos)
{
if(angle != (Math.toDegrees(Math.atan((yPos - Controller.player.getY())/(double)(xPos - Controller.player.getX()))) - 90))
angle += (Math.toDegrees(Math.atan((yPos - Controller.player.getY())/(double)(xPos - Controller.player.getX()))) - 90)/(double)50;
}
else
if(angle != (Math.toDegrees(Math.atan((yPos - Controller.player.getY())/(double)(xPos - Controller.player.getX()))) + 90))
angle += (Math.toDegrees(Math.atan((yPos - Controller.player.getY())/(double)(xPos - Controller.player.getX()))) + 90)/(double)50;
}
/**
* draws the Bullet on the screen
*/
public void render()
{
super.render();
StdDraw.picture(xPos, yPos, "homingBullet.png", States.BULLET_SIZE, States.BULLET_SIZE, angle);
}
}