-
Notifications
You must be signed in to change notification settings - Fork 0
/
Princess.java
77 lines (71 loc) · 2.92 KB
/
Princess.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
/*Author: Josiah Etto
*Description: This class is responsible for and provides the information necessary for
*all of the possible actions performed by the Princess sprite. These are movement,
*loading and scaling of the sprite image, and halting of movement if necessary.
*Last Edited: January 10, 2020
*/
final class Princess extends Sprite {
private int yVelocity;//added to Princess's y value to allow vertical movement
private boolean go;//used to determine which direction Princess should move in
private int dress;
protected int collide;
private String [] dresses = {"Image/zelda.png", "Image/zeldaB.png"};
/* constructor
* pre: none
* post: sets default values and calls a method to load and sets dimensions for Princess
*/
public Princess(int x, int y, int dress) {
super(x, y);
this.dress = dress;
yVelocity = 1;//sets Princess' movement speed to 1
go = false;//sets Princess' direction of movement down
collide = 0;
initPrincess();//calls a method to load the image and sets the dimensions for Princess
}
/* loads and scales the image and sets the dimensions for Princess
* pre: none
* post: calls methods that are in charge of the image and dimensions
*/
private void initPrincess() {
loadPrincess(dresses[dress]); //loads and scales Sprite image
setPrincessDimensions();//sets width and height values
}
public String getDress() {
if (dress == 0)
return "none";
else
return "blue";
}
/* changes the x and y values of Princess depending on its location on the screen. max_height
* is used to prevent Princess from going above a height that seems strange when considering
* where the ground is in the level
* pre: none
* post: moves the Princess object
*/
public void move(int max_height) {
if (pressed == false) {//if the pause button has not been pressed
if (go == false) {//if Princess is moving to the bottom of the screen
y+= yVelocity;//move down
if (y == 690 - height) {//if Princess has reached bottom of the screen
go = true;//change direction
}
}else {//if Princess is moving to the top of the screen
y-= yVelocity;//move up
if (y == max_height) {//when Princess reaches the specified height
go = false;//change direction
}
}
}else{//if pause button has been pressed
pause();//stop movement
}
}
/* used in the BoardFive class in the event that the Witch stops time,
* Princess's movement will be halted for a certain amount of time as if
* the game has been paused
* pre: none
* post: zero is added to Princess' x and y values
*/
public void stop() {
y+=0;//stops vertical movement
}
}