-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboss.pde
73 lines (67 loc) · 2.08 KB
/
boss.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
class Boss {
float x;
float y;
float speed;
float size;
float maxHealth;
float health;
int healthDelay = 20;
int lastDamage = millis();
int moveDelay = 200;
int lastMove = millis();
float factor = 1;
PImage sprite1 = loadImage("Boss1.png");
PImage sprite2 = loadImage("Boss2.png");
Boss(float x, float y, float speed, float size, float maxHealth, float health) {
this.x = x;
this.y = y;
this.speed = speed;
this.size = size;
this.maxHealth = maxHealth;
this.health = health;
}
// Draws the boss
void display(){
PImage sprite;
if (stage() >= 1 && stage() < 3) {sprite = sprite1;}
else {sprite = sprite2;}
fill(160,30,240);
strokeWeight(0);
stroke(0,0,0);
image(sprite,x,y,size,size);
}
// Moves randomly around the top part of the screen
void move(){
if (factor == 1) {factor = -1;}
else {factor = 1;}
if ((millis() - lastMove) > moveDelay){
x += factor*speed*random(1,3);
y += factor*speed*random(1,3);
lastMove = millis();
}
}
// Returns the stage the boss is at based on its health
int stage(){
if (health >= (maxHealth*2)/3 && health <= maxHealth){return 1;}
else if (health >= maxHealth/3 && health < (maxHealth*2)/3){return 2;}
else if (health >= 0 && health < maxHealth/3){return 3;}
else return 0;
}
// Returns whether the boss is dead or not
boolean isDead(){
if (health <= 0) return true;
return false;
}
// Displays the boss' health bar
void displayHP(){
float hbbd = maxHealth / 650;
strokeWeight(3);
fill(255,255,255);
stroke(255, 255, 255);
rect(1200, 700, 20, -maxHealth / hbbd, 20);
if (pattern5Shield.isEmpty()) {fill(160,30,240);}
else {fill(55,55,55);}
stroke(255, 255, 255);
rect(1200, 700, 20, -health / hbbd, 20);
}
}