-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mushrooms.pde
127 lines (111 loc) · 2.68 KB
/
Mushrooms.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
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
MushroomsList mushList = new MushroomsList();
SoundFile hit;
class Mushroom
{
float x, y;
int damageState; // 4 levels of damage
float sizeMushy;
PImage img;
Mushroom(float x, float y)
{
this.x = x;
this.y = y;
damageState = 1;
sizeMushy = size/damageState;
img = loadImage("images/mushroom.png");
img.resize(size, 0);
}
void display()
{
if (damageState < 4)
{
sizeMushy = size/damageState;
//rectMode(CORNER);
//rect(x, y, size, sizeMushy);
if (Level.getLevel() == 1) tint(#02E51A);
if (Level.getLevel() == 2) tint(#C2E502);
if (Level.getLevel() >= 3) tint(255);
imageMode(CORNER);
image(img, x, y);
img.resize(size, int(sizeMushy));
noTint();
} else {
//explode();
x = -100;
y = -100;
}
}
boolean checkForDamage(Bullet bullet)
{
if (bullet.x >= x && bullet.x <= x + size + 10 && bullet.y >= y && bullet.y <= y + size + 10)
{
if (soundEnabled) hit.play();
damageState++;
changeScore(4);
//println("Mushroom damaged, at state of " + damageState);
return true;
//bullets.removeBullet(bullet);
}
return false;
}
void explode()
{
// compute a random displacement for each vertex
float x1 = random(-50, 50);
float y1 = random(-50, 50);
float x2 = random(-50, 50);
float y2 = random(-50, 50);
float x3 = random(-50, 50);
float y3 = random(-50, 50);
float x4 = random(-50, 50);
float y4 = random(-50, 50);
// draw the distorted image using the displaced vertices
image(img, x, y);
noStroke();
fill(255, 255, 255, 150);
beginShape();
vertex(x + x1, y + y1);
vertex(img.width + x2, y + y2);
vertex(img.width + x3, img.height + y3);
vertex(x + x4, img.height + y4);
endShape(CLOSE);
}
}
class MushroomsList
{
ArrayList<Mushroom> mushrooms = new ArrayList<>();
void generateMushrooms()
{
int numMushrooms = 100;
//(Level.getLevel()*100);
for (int i = 0; i < numMushrooms; i++)
{
int multWidth = width/size;
int multHeight = (width)/size;
int x = int(random(multWidth));
int y = int(random(multHeight));
while (validatePos(x, y))
{
x = int(random(multWidth));
y = int(random(multHeight));
}
mushrooms.add(new Mushroom(x*multWidth, y*multHeight));
}
}
void checkForDamage()
{
}
void spawnMushroom(int x, int y)
{
mushrooms.add(new Mushroom(x, y));
}
void clearMushrooms()
{
mushrooms.clear();
}
// For gridlike positioning
boolean validatePos(int x, int y)
{
return x == 0 || x == width/size || y == 0 || y >= (width/size)-2;
}
}