makefuture / games / accept-the-cookie / game / entities / Algorithm.js
120 words
 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
export class Algorithm {
    constructor(scene) {
        this.scene = scene;
        this.bubble = scene.add.container(0, 0).setDepth(20).setScrollFactor(0);
        this.avatar = scene.add.circle(0, 0, 18, 0xffffff, 0.9);
        this.spark = scene.add.star(0, 0, 5, 4, 13, 0x111111, 0.9);
        this.panel = scene.add.rectangle(0, 0, 520, 54, 0x000000, 0.52).setOrigin(0, 0.5);
        this.text = scene.add.text(0, 0, '', {
            fontFamily: 'system-ui, sans-serif',
            fontSize: '14px',
            color: '#ffffff',
            wordWrap: { width: 490 },
        }).setOrigin(0, 0.5);
        this.bubble.add([this.panel, this.text, this.avatar, this.spark]);
        this.resize();
        scene.scale.on('resize', () => this.resize());
    }

    say(message) {
        this.text.setText(message);
        this.scene.tweens.add({
            targets: this.bubble,
            alpha: { from: 0.2, to: 1 },
            duration: 220,
            yoyo: true,
            hold: 2600,
        });
    }

    resize() {
        const width = this.scene.scale.width;
        this.bubble.setPosition(Math.min(110, width * 0.08), 82);
        this.panel.setPosition(42, 0);
        this.text.setPosition(60, 0);
        this.avatar.setPosition(18, 0);
        this.spark.setPosition(18, 0);
        this.panel.width = Math.min(520, width - 120);
        this.text.setWordWrapWidth(Math.max(220, this.panel.width - 30));
    }
}

static mirror of HEAD · about · clone: git clone https://git.makefuture.ro/makefuture.git