-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayerEntity.java
66 lines (60 loc) · 1.5 KB
/
playerEntity.java
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
package org.newdawn.spaceinvaders;
/**
* The entity that represents the players ship
*
* @author Kevin Glass
*/
public class PlayerEntity extends Entity
{
/** The game in which the ship exists */
private Game 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
*/
public PlayerEntity(Game game,String ref,int x,int 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)
*/
public void move(long 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
*/
public void collidedWith(Entity other)
{
// if its an alien, notify the game that the player
// is dead
if (other instanceof AlienEntity)
{
game.notifyDeath();
}
}
}