/
Utils.pde
79 lines (77 loc) · 1.44 KB
/
Utils.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
static class Vector {
static Point getVectorToTarget(Point from, Point to, float v) {
float r = atan2(to.y - from.y, to.x - from.x);
float vx = cos(r) * v;
float vy = sin(r) * v;
return new Point(vx, vy);
}
}
class Tick {
int tick;
int c;
Tick(int tick, boolean random, boolean first) {
this.tick = tick;
if (first) {
c = tick;
}
if (random) {
c = int(float(c)*random(1));
}
}
boolean check() {
if (c >= tick) {
c = 0;
return true;
}
c++;
return false;
}
void reset() {
c = tick;
}
}
class Fader {
int alpha = 0;
boolean complete = false;
String fadeMode = "";
int speed = 8;
PImage screen = loadImage("./texture/screen/waitingScreen.png");
void fadeIn() {
fadeMode = "in";
alpha = 255;
complete = false;
}
void fadeOut() {
fadeMode = "out";
alpha = 0;
complete = false;
}
void reset() {
complete = false;
fadeMode = "";
}
void render() {
if (fadeMode == "in") {
alpha -= speed;
if (alpha <= 0) {
complete = true;
alpha = 0;
fadeMode = "";
}
tint(255, 255, 255, alpha);
image(screen, 0, 0);
noTint();
}
else if (fadeMode == "out") {
alpha += speed;
if (alpha >= 500) {
complete = true;
alpha = 255;
fadeMode = "";
}
tint(255, 255, 255, alpha);
image(screen, 0, 0);
noTint();
}
}
}