forked from Eliriah/Intergalactic_Assailants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
167 lines (150 loc) · 3.13 KB
/
Player.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import java.awt.Rectangle;
public class Player {
// The Players instance Variables
private int x_coordinate;
private int y_coordinate;
private int width;
private int height;
private boolean live;
/**
* Player constructor that takes in the x and y coordinates as well as the width
* and height of the player
*
* @param x
* @param y
* @param w
* @param h
*/
public Player(int x, int y, int w, int h) {
this.x_coordinate = x;
this.y_coordinate = y;
this.width = w;
this.height = h;
this.live = true;
}
// Getters
/**
* Returns the player's x-coordinate
*
* @return x_coordinate
*/
public int getX_Coordinate() {
return x_coordinate;
}
/**
* Returns the player's y-coordinate
*
* @return
*/
public int getY_Coordinate() {
return y_coordinate;
}
/**
* Returns the player's width
*
* @return
*/
public int getWidth() {
return width;
}
/**
* Returns the player's height
*
* @return
*/
public int getHeight() {
return height;
}
/**
* Returns the life of the player
*
* @return
*/
public boolean getLive() {
return live;
}
// Setters
/**
* Sets the player's x-coordinate
*
* @param a
*/
public void setXCoordinate(int a) {
x_coordinate = a;
}
/**
* Sets the player's y coordinate
*
* @param a
*/
public void setYCoordinate(int a) {
y_coordinate = a;
}
/**
* Sets the player's state
*
* @param state
*/
public void setLive(boolean state) {
if (live != state)
live = state;
}
/**
* Sets the player's width
*
* @param aWidth
*/
public void setWidth(int aWidth) {
width = aWidth;
}
/**
* Sets the player's height
*
* @param aHeight
*/
public void setHeight(int aHeight) {
height = aHeight;
}
// Movement
/**
* Moves the player to the right
*
* @param distance
*/
public void moveRight(int distance) {
x_coordinate += distance;
}
/**
* Moves the player to the left
*
* @param distance
*/
public void moveLeft(int distance) {
x_coordinate -= distance;
}
/**
* Moves the object down
*
* @param distance
*/
public void moveDown(int distance) {
y_coordinate += distance;
}
/**
* Moves the object up
*
* @param distance
*/
public void moveUp(int distance) {
y_coordinate -= distance;
}
// Hitbox
/**
* Returns the position and dimensions of the unit's hitbox
*
* @return
*/
public Rectangle getUnitHitBox() {
return new Rectangle(x_coordinate, y_coordinate, width, height);
}
}