-
Notifications
You must be signed in to change notification settings - Fork 1
/
Coin.js
84 lines (63 loc) · 2.11 KB
/
Coin.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
const borschtWordMockup = [
[1,1,0,0,0,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,1,0,1,0,1,1,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,1,0],
[1,1,0,0,1,0,1,0,1,1,0,0,1,1,1,0,1,0,0,0,1,1,1,0,0,1,0],
[1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0],
[1,1,0,0,0,1,0,0,1,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,1,0]
];
class Coin extends PIXI.Sprite {
constructor(num, y) {
super(resources["images/coin.png"].texture);
this.initialProportion = this.width/this.height;
this.width = Math.ceil(50 * sizeScale());
this.height = this.width*this.initialProportion;
this.y = y;
this.x = app.renderer.width + (num)*this.width + 5*num;
app.stage.addChild(this);
}
}
class CoinsRaw {
buildRaw() {
this.y = 50 + Math.random()*app.renderer.height/3.2;
this.parts = [0,1,2,3,4].map(x => new Coin(x+3, this.y));
for (let raw = 0; Math.floor(Math.random() * 3); raw++) {
this.y += this.parts[0].height + 5;
this.parts = this.parts.concat([0,1,2,3,4].map(x => new Coin(x+3, this.y)));
}
for (let extra = 0; Math.floor(Math.random() * 3); extra++) {
this.parts.unshift(new Coin(2-extra, this.y));
}
}
constructor() {
this.buildRaw();
this.speed = 2;
}
whenRunAway() {
this.buildRaw();
}
nextStep(xSpeedFactor) {
for (let partN in this.parts) {
this.parts[partN].x -= this.speed*xSpeedFactor;
}
if (this.parts[this.parts.length-1].x < -this.parts[this.parts.length-1].width*2) {
this.whenRunAway();
}
}
}
class CoinsWord extends CoinsRaw {
buildRaw() {
this.parts = [];
for (let raw in borschtWordMockup) {
for (let cell in borschtWordMockup[raw]) {
if (borschtWordMockup[raw][cell]) {
this.parts.push(new Coin(+cell-13, (80+raw*50)*sizeScale()));
}
}
}
}
whenRunAway() {
if (this.parts.length > 15) {
game.prewordShown = true;
}
}
}