-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCasterContainer.pde
44 lines (36 loc) · 1.4 KB
/
CasterContainer.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
int SHADOW_DIST = 25;
int SHADOW_AMOUNT = 5;
class CasterContainer {
Caster caster;
ArrayList<Caster> shadows;
CasterContainer(PVector initialPosition) {
this.caster = new Caster(initialPosition, 150, #ffffff, 1);
this.shadows = new ArrayList<Caster>();
for (int i = 0; i < SHADOW_AMOUNT; i++)
this.shadows.add(new Caster(new PVector(initialPosition.x, initialPosition.y)));
}
CasterContainer(PVector initialPosition, color backgroundCollor) {
this.caster = new Caster(initialPosition, backgroundCollor);
this.shadows = new ArrayList<Caster>();
for (int i = 0; i < SHADOW_AMOUNT; i++)
this.shadows.add(new Caster(new PVector(initialPosition.x, initialPosition.y)));
}
void castRays(ArrayList<LineBoundary> lines) {
this.caster.castRays(lines);
}
void castBackground(ArrayList<LineBoundary> lines) {
this.caster.castBackground(lines);
this.shadows.forEach((shadowCaster) ->
shadowCaster.castBackground(lines, color(this.caster.rayBackGroundCollor, 50)));
this.caster.castPoint();
this.shadows.forEach((shadowCaster) ->
shadowCaster.castPoint());
}
void setPosition(float x, float y) {
this.caster.setPosition(x, y);
for (int i = 0; i < this.shadows.size(); i++) {
float a = map(i, 0, this.shadows.size(), 0, TWO_PI);
this.shadows.get(i).setPosition(x + (sin(a) * SHADOW_DIST), y + (cos(a) * SHADOW_DIST));
}
}
}