-
Notifications
You must be signed in to change notification settings - Fork 1
/
ShipEntity.snap
53 lines (49 loc) · 1.4 KB
/
ShipEntity.snap
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
/**
* The entity that represents the players ship
*/
class ShipEntity extends Entity {
/** The game in which the ship exists */
var game;
/**
* Create a new entity to represent the players ship
*
* @param game The game in which the ship is being created
* @param ref The reference to the sprite to show for the ship
* @param x The initial x location of the player's ship
* @param y The initial y location of the player's ship
*/
new(game, ref, x, y) : super(ref,x,y){
this.game = game;
}
/**
* Request that the ship move itself based on an elapsed ammount of
* time
*
* @param delta The time that has elapsed since last move (ms)
*/
move(delta) {
// if we're moving left and have reached the left hand side
// of the screen, don't move
if (dx < 0 && x < 10) {
return;
}
// if we're moving right and have reached the right hand side
// of the screen, don't move
if (dx > 0 && x > 750) {
return;
}
super.move(delta);
}
/**
* Notification that the player's ship has collided with something
*
* @param other The entity with which the ship has collided
*/
collidedWith(other) {
// if its an alien, notify the game that the player
// is dead
if (other.class == AlienEntity) {
game.notifyDeath();
}
}
}