-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoss.java
180 lines (168 loc) · 5.05 KB
/
Boss.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
168
169
170
171
172
173
174
175
176
177
178
179
180
import greenfoot.*;
import java.util.Random;
/**
* Write a description of class Boss here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Boss extends Actor
{
SimpleTimer timer = new SimpleTimer(); //Animation Timer
SimpleTimer timer2 = new SimpleTimer(); //Air Drop
SimpleTimer timer3 = new SimpleTimer(); //Ult cooldown
SimpleTimer timer4 = new SimpleTimer(); //Ult timer
SimpleTimer timer5 = new SimpleTimer(); //Attack Timer
SimpleTimer timer7 = new SimpleTimer(); //Summon Animation
GreenfootSound groundSlam = new GreenfootSound("BossHit.wav");
GreenfootSound laser = new GreenfootSound("BossLaser.wav");
GreenfootSound punch = new GreenfootSound("BossPunch.wav");
GreenfootSound ult = new GreenfootSound("BossUlt.wav");
GreenfootSound hurt = new GreenfootSound("BossHurt.wav");
boolean isDead = false;
boolean enrage = false; //Ground Checker
public void act()
{
checkGround();
if(timer2.millisElapsed() > 5500 && timer3.millisElapsed() > 2000){
bulletHit();
}
//Regular Attacks
Random r = new Random();
if(timer2.millisElapsed() > 5500 && timer3.millisElapsed() > 2000){
walkingAnimation();
if(r.nextInt(100) < 2){
punch();
punch();
punch();
punch();
punch();
punch();
move(-4);
timer.mark();
}
if(r.nextInt(100) < 2){
attack();
attack();
attack();
attack();
attack();
attack();
timer.mark();
}
if(r.nextInt(100) < 2){
move(-2);
}
}
//Laser Attack
if(timer5.millisElapsed() > 5500){
if(timer4.millisElapsed() > 10000){
ult.setVolume(80);
ult.play();
BossUlt ult = new BossUlt();
getWorld().addObject(ult, getX() - 400, getY() + 3);
setImage("BossStance4.png");
timer3.mark();
timer4.mark();
}
}
}
public Boss(){
setImage("BossSummon1.png");
}
/**
* Checks if boss is on the ground
*/
public void checkGround(){
if(isTouching(BossGround.class)){
setLocation(getX(), getY());
if(enrage == false){
summonAnimation();
summonExplosion();
if(timer7.millisElapsed() > 2000){
enrage = true;
}
}
} else {
setLocation(getX(), getY() + 3);
}
}
/**
* Health and bullet interactions
*/
public void bulletHit(){
Boss1 world = (Boss1) getWorld();
boolean getHit = false;
if(isTouching(Bullet.class)){
hurt.setVolume(90);
hurt.play();
setImage("BossHit.png");
timer.mark();
World myWorld = getWorld();
Boss1 boss = (Boss1)myWorld;
HealthBar healthBar = boss.getHealthBar();
if(getHit == false){
healthBar.loseHealth();
getHit = true;
if(healthBar.health <= 0){
isDead = true;
}
removeTouching(Bullet.class);
}
} else {
getHit = false;
}
}
/**
* Animation for when boss is summoned
*/
public void summonAnimation(){
if(timer.millisElapsed() > 200){
setImage("BossSummon1.png");
}
if(timer.millisElapsed() > 400){
setImage("BossSummon2.png");
}
if(timer.millisElapsed() > 600){
setImage("BossSummon3.png");
timer.mark();
}
}
/**
* Explosion when the boss lands
*/
public void summonExplosion(){
groundSlam.setVolume(80);
groundSlam.play();
GroundExplosion groundExplosion = new GroundExplosion();
getWorld().addObject(groundExplosion, getX() - 30, getY() + 800);
}
public void punch(){
punch.setVolume(80);
punch.play();
BossFire bossFire = new BossFire();
setImage("BossPunch.png");
getWorld().addObject(bossFire, getX() - 130, getY() - 20);
}
public void attack(){
laser.setVolume(80);
laser.play();
BossFireAttack fire = new BossFireAttack();
setImage("BossAttack.png");
getWorld().addObject(fire, getX() - 40, getY() +3 );
}
public void walkingAnimation(){
if(timer.millisElapsed() > 150){
setImage("BossStanceDefault.png");
}
if(timer.millisElapsed() > 300){
setImage("BossStanceDefault2.png");
}
if(timer.millisElapsed() > 450){
setImage("BossStanceDefault3.png");
}
if(timer.millisElapsed() > 500){
timer.mark();
}
}
}