-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
72 lines (54 loc) · 2.14 KB
/
Player.java
File metadata and controls
72 lines (54 loc) · 2.14 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
//The entity that the human player controls in the game window
//The player moves in reaction to player input
public class Player extends Entity {
//Location of image file to be drawn for a Player
//public static final String PLAYER_IMAGE_FILE = "game_assets/player.gif";
public static final String PLAYER_IMAGE_FILE = "boateng_game_assets/ship2.gif";
//Dimensions of the Player
public static final int PLAYER_WIDTH = 75;
public static final int PLAYER_HEIGHT = 75;
//Default speed that the Player moves (in pixels) each time the user moves it
public static final int DEFAULT_MOVEMENT_SPEED = 7;
//Starting hit points
public static final int STARTING_HP = 3;
//Current movement speed
private int movementSpeed;
//Remaining Hit Points (HP) -- indicates the number of "hits" (ie collisions
//with Avoids) that the player can take before the game is over
private int hp;
public Player(){
this(0, 0);
}
public Player(int x, int y){
super(x, y, PLAYER_WIDTH, PLAYER_HEIGHT, PLAYER_IMAGE_FILE);
this.hp = STARTING_HP;
this.movementSpeed = DEFAULT_MOVEMENT_SPEED;
}
//Retrieve and set the Player's current movement speed
//movement speed is the numebr of pixels the Player Entity
//moves when an arrow key is pressed
public int getMovementSpeed(){
//implement me!
return movementSpeed;
//throw new IllegalStateException("Hey 102 Student! You need to implement getMovementSpeed in Player.java!");
}
public void setMovementSpeed(int newSpeed){
this.movementSpeed = newSpeed;
}
//Retrieve the Player's current HP
public int getHP(){
return hp;
}
//Set the player's HP to a specific value.
//Returns an boolean indicating if Player still has HP remaining
public boolean setHP(int newHP){
this.hp = newHP;
return (this.hp > 0);
}
//Set the player's HP to a specific value.
//Returns an boolean indicating if Player still has HP remaining
public boolean modifyHP(int delta){
this.hp += delta;
return (this.hp > 0);
}
}