-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPumpkinMonster.pde
96 lines (93 loc) · 2.61 KB
/
PumpkinMonster.pde
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
public class PumpkinMonster extends Boss{
boolean findPlayer = false;
float findDis;
PImage[] stand2;
PImage[] transform;
boolean transformed;
int changetime;
public PumpkinMonster(PImage img, int size_x, int size_y, float x, float y, int dam, float ChaseDis, float chase_speed, float findDis){
super(img, size_x,size_y, x, y,dam, ChaseDis,chase_speed);
stand = new PImage[8];
walk = new PImage[3];
stand2 = new PImage[1];
transform = new PImage[7];
transformed = false;
this.findDis = findDis;
this.loadFrames(this.walk,"./data/pumkinMonster/run/pumpkinMonster");
this.loadFrames(this.stand,"./data/pk/pumpkin");
this.loadFrames(this.stand2,"./data/pumkinMonster/run/pumpkinMonster");
this.loadFrames(this.transform, "./data/pumkinMonster/transform/pumpkinMonster");
currentImg = stand;
}
@Override
public void selectImg(){
ms = millis();
if (!findPlayer){FindPlayer(player);}
CheckAttack(player);
if (findPlayer){
if(!transformed){
changetime = millis();
currentImg = transform;
transformed = true;
w = PUMKINMONSTER_SIZE_X;
h = PUMKINMONSTER_SIZE_Y;
}
else if (transformed && (millis() - changetime)/100>5){
if(Chase(player)){
currentImg = walk;
}
}
else if (change_x==0) {
if (findPlayer)
currentImg = stand2;
else
currentImg = stand;
}
}
}
boolean Chase(Player player){
float dis = 10000;
if (collisionTest(player, this)){
return false;
}
if(player.getBottom()==this.getBottom()){
dis = abs(player.getCenter_x() - this.getCenter_x());
}
if (dis<ChaseDis){
if(player.getCenter_x()>this.getCenter_x()){
this.change_x = +chase_speed;
return true;
}
else{
this.change_x = -chase_speed;
return true;
}
}
else{
this.change_x = 0;
return false;
}
}
boolean CheckAttack(Player player){
if (collisionTest(player, this)){
if ((ms - attms)/1000>=2 ){
player.lives-=dam;
attms = ms;
return true;
}
return true;
}
return false;
}
public void updateAnimation() {
frame++;
if (frame % 9 == 0) {
selectImg();
moveToNextImg();
}
}
void FindPlayer(Player player){
if (abs(player.getCenter_x() - this.getCenter_x()) < findDis)
findPlayer = true;
}
}