-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyBullet.java
More file actions
95 lines (86 loc) · 2.08 KB
/
EnemyBullet.java
File metadata and controls
95 lines (86 loc) · 2.08 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
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
/**
* This Class can be used to create EnemyBullet objects
* @author elan
*
*/
public class EnemyBullet extends Bullet
{
/**
* Cunstructor for the EnemyBullet object
* @param enemy Bullet will be created with same x, y, and angle as this entity
* @param index Give the EnemyBullet a unique index to identify it
*/
public EnemyBullet(Entity enemy, int index)
{
super(enemy, index);
angle = enemy.getAngle() + 180;
}
/**
* Cunstructor for the EnemyBullet object
* @param enemy Bullet will be created with same x, y, and angle as this entity
* @param index Give the EnemyBullet a unique index to identify it
* @param angleDeviation this angle will be added to the entity's angle and the bullet will be created with the resulting angle
*/
public EnemyBullet(Entity enemy, int index, double a)
{
super(enemy, index);
angle = enemy.getAngle() + 180 + a;
}
/**
* Does all nessisary updates for the Bullet object
*/
public void update()
{
updatePos();
checkBounds();
}
/**
* updates the Bullets x and y co-ordinates
*/
protected void updatePos()
{
moveLeft(States.enemySpeed*Math.cos(Math.toRadians(90 - angle)));
moveUp(States.enemySpeed*Math.sin(Math.toRadians(90 - angle)));
}
/**
* Returns how much damage this bullet does
* @return damage of the bullet
*/
public int getDamage()
{
return States.enemyDamage;
}
/**
* checks if the bullet is still on the screen, if it is not it is destroyed
*/
private void checkBounds()
{
if(!(canMoveLeft() && canMoveRight() && canMoveUp() && canMoveDown()))
{
try
{
Controller.enemyBullets.remove(index);
}
catch(IndexOutOfBoundsException e)
{
e.printStackTrace();
}
}
}
/**
* draws the Bullet on the screen
*/
public void render()
{
String type = "";
if(Level.getLevel() > 14)
type = "enemyBullet4.png";
else if(Level.getLevel() > 9)
type = "enemyBullet3.png";
else if(Level.getLevel() > 4)
type = "enemyBullet2.png";
else
type = "enemyBullet1.png";
StdDraw.picture(xPos, yPos, type, States.BULLET_SIZE, States.BULLET_SIZE, angle);
}
}