-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCat.java
128 lines (96 loc) · 3.68 KB
/
Cat.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
import mayflower.*;
public class Cat extends MovableAnimatedActor
{
private Animation walkRight;
private Animation idleRight;
private Animation walkLeft;
private Animation fallRight;
private Animation fallLeft;
private Animation idleLeft;
private Animation jumpRight;
private Animation jumpLeft;
private Animation climb;
private int score;
private int health;
public Cat(int startScore, int startHealth)
{
score = startScore;
health = startHealth;
String[] idleImages = new String[10];
for (int i = 0; i < idleImages.length; i++)
idleImages[i] = String.format("assets/cat/Idle (%d).png", i + 1);
String[] walkImages = new String[10];
for (int i = 0; i < walkImages.length; i++)
walkImages[i] = String.format("assets/cat/Walk (%d).png", i + 1);
String[] fallImages = new String[8];
for (int i = 0; i < fallImages.length; i++)
fallImages[i] = String.format("assets/cat/Fall (%d).png", i + 1);
String[] jumpImages = new String[8];
for (int i = 0; i < jumpImages.length; i++)
jumpImages[i] = String.format("assets/cat/Jump (%d).png", i + 1);
String[] climbImages = new String[3];
for (int i = 0; i < climbImages.length; i++)
climbImages[i] = String.format("assets/cat/Climb (%d).png", i + 1);
idleRight = new Animation(50000000, idleImages);
idleRight.scale(100, 87);
idleRight.setBounds(18, 5, 54, 80);
idleLeft = new Animation(50000000, idleImages);
idleLeft.scale(100, 87);
idleLeft.mirrorHorizontally();
idleLeft.setBounds(18, 5, 54, 80);
walkRight = new Animation(50000000, walkImages);
walkRight.scale(100, 87);
walkRight.setBounds(18, 5, 54, 80);
walkLeft = new Animation(50000000, walkImages);
walkLeft.scale(100, 87);
walkLeft.mirrorHorizontally();
walkLeft.setBounds(28, 5, 54, 80);
fallRight = new Animation(50000000, fallImages);
fallRight.scale(100, 87);
fallRight.setBounds(18, 5, 54, 80);
fallLeft = new Animation(50000000, fallImages);
fallLeft.mirrorHorizontally();
fallLeft.scale(100, 87);
fallLeft.setBounds(28, 5, 54, 80);
jumpRight = new Animation(50000000, jumpImages);
jumpRight.scale(100, 87);
jumpRight.setBounds(18, 5, 54, 80);
jumpLeft = new Animation(50000000, jumpImages);
jumpLeft.mirrorHorizontally();
jumpLeft.scale(100, 87);
jumpLeft.setBounds(18, 5, 54, 80);
climb = new Animation(80000000, climbImages);
climb.scale(100, 87);
climb.setBounds(18, 5, 54, 80);
setIdleRightAnimation(idleRight);
setIdleLeftAnimation(idleLeft);
setWalkRightAnimation(walkRight);
setWalkLeftAnimation(walkLeft);
setFallLeftAnimation(fallLeft);
setFallRightAnimation(fallRight);
setJumpRightAnimation(jumpRight);
setJumpLeftAnimation(jumpLeft);
setClimbAnimation(climb);
}
public void act()
{
super.act();
if (health <= 0 || getY() >= getWorld().getHeight()) {
World gameOver = new GameOverLose(this.score);
Mayflower.setWorld(gameOver);
}
}
public int getScore() { return score; }
public void incScore() { score++; }
public int getHealth() { return health; }
public void decrHealth(int howMany) {
health -= howMany;
}
public void incrHealth(int howMany) {
health += howMany;
}
// remake actors, used when damage is taken
public void respawn() {
setLocation(0, 300);
}
}