-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShotEntity.java
More file actions
102 lines (70 loc) · 1.95 KB
/
ShotEntity.java
File metadata and controls
102 lines (70 loc) · 1.95 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
96
97
98
99
100
101
/**
* An entity representing a shot fired by the player's ship
*
* @author Kevin Glass
*/
public class ShotEntity extends Entity {
/** The vertical speed at which the players shot moves */
private double moveSpeed = -300;
/** The game in which this entity exists */
private Game game;
/** True if this shot has been "used", i.e. its hit something */
private boolean used = false;
//sensor.setConfig();
/**
* Create a new shot from the player
*
* @param game The game in which the shot has been created
* @param sprite The sprite representing this shot
* @param x The initial x location of the shot
* @param y The initial y location of the shot
*/
public ShotEntity(Game game,String sprite,int x,int y) {
super(sprite,x,y);
this.game = game;
dy = moveSpeed;
try {
MXC6226XU sensor = new MXC6226XU();
//dx = (sensor.read() - 198) * 5 ;
//sensor.MoveX_Acc();
//dx = (sensor.MoveX_Acc() - 198) * 5 ;
dx = sensor.get_Acc();
}
catch(Exception e){}
}
/**
* Request that this shot moved based on time elapsed
*
* @param delta The time that has elapsed since last move
*/
public void move(long delta) {
// proceed with normal move
super.move(delta);
// if we shot off the screen, remove ourselfs
if (y < -100) {
game.removeEntity(this);
}
}
/**
* Notification that this shot has collided with another
* entity
*
* @parma other The other entity with which we've collided
*/
public void collidedWith(Entity other) {
// prevents double kills, if we've already hit something,
// don't collide
if (used) {
return;
}
// if we've hit an alien, kill it!
if (other instanceof AlienEntity) {
// remove the affected entities
game.removeEntity(this);
game.removeEntity(other);
// notify the game that the alien has been killed
game.notifyAlienKilled();
used = true;
}
}
}