-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationManager.js
131 lines (113 loc) · 3.7 KB
/
AnimationManager.js
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
class AnimationManager {
constructor() {
}
static async animationBoilerPlate() {
//Setup animation variables
let canvas = get();
animationFrame = 0;
let lastState = state;
state = STATE.ANIMATION;
//Draw animation
push();
while (animationFrame < 30) {
image(canvas, 0, 0);
await sleep(2);
}
pop();
//Return to previous state
state = lastState;
}
static async throwBall() {
//Setup animation variables
let canvas = get();
animationFrame = 0;
let lastState = state;
state = STATE.ANIMATION;
//Draw animation
push();
while (animationFrame < 40) {
image(canvas, 0, 0);
noStroke();
ellipseMode(CENTER);
fill(0, 0, 255);
angleMode(DEGREES);
let m = map(animationFrame, 0, 40, 0, 130);
let x = animationFrame * 8 + 135;
let y = sin(m) * -270 + 350;
ellipse(x, y, 40);
await sleep(2);
}
pop();
//Return to previous state
state = lastState;
}
static async beginBattle() {
playSound(sounds.encounter);
//Setup animation variables
animationFrame = 0;
let lastState = state;
state = STATE.ANIMATION;
//Draw animation
push();
while (animationFrame < 90) {
noStroke();
fill(0);
let x = animationFrame % 10;
let y = Math.floor(animationFrame / 10);
rect(x * 60, y * 60, 60);
await sleep(2);
}
pop();
//Return to previous state
state = lastState;
}
//Animation played during evolution. Returns false, if the evolution is cancelled.
static async evolution(baseMonster, evolvedMonster, monsterName) {
//Setup animation variables
let canvas = get();
animationFrame = 0;
let lastState = state;
state = STATE.ANIMATION;
//Draw animation
push();
background(255);
let duration = 8
AnimationManager.drawMonster(baseMonster.id, width / 2 - 120, height / 2 - 120);
await dialogue.load([{ type: "timed", line: `What? ${monsterName} is evolving!`, time: 1000 }]);
let animationDelta = animationFrame;
while (animationFrame < animationDelta + fps * duration) {
if ((animationDelta - animationFrame) % 2 == 0) {
background(255);
let mapped = map(Math.random(), 0, 1, 0, fps * duration);
if (mapped > -(animationDelta - animationFrame)) {
AnimationManager.drawMonster(baseMonster.id, width / 2 - 120, height / 2 - 120);
} else {
AnimationManager.drawMonster(evolvedMonster.id, width / 2 - 120, height / 2 - 120)
}
}
if (keyIsDown(KEYS.B_KEY)) {
state = lastState;
AnimationManager.drawMonster(baseMonster.id, width / 2 - 120, height / 2 - 120);
return true;
}
await sleep(2);
}
AnimationManager.drawMonster(evolvedMonster.id, width / 2 - 120, height / 2 - 120);
pop();
//Return to previous state
state = lastState;
return false;
}
static drawMonster(model, x, y) {
model = model.toString().padStart(3, 0);
if (model == 0) {
push();
fill(0, 250, 0);
noStroke();
rect(x, y, 120, 120);
pop();
} else {
image(globalSpriteList.monsters[`${model}`], x, y, 180, 180);
}
}
}