makefuture / games / accept-the-cookie / game / entities / AdEnemy.js
90 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
export class AdEnemy {
    constructor(scene, x, y, label, color = 0xff004d) {
        this.scene = scene;
        this.sprite = scene.add.container(x, y);
        this.box = scene.add.rectangle(0, 0, 96, 42, color, 0.96);
        this.text = scene.add.text(0, 0, label, {
            fontFamily: 'system-ui, sans-serif',
            fontSize: '12px',
            color: '#ffffff',
            fontStyle: '700',
            align: 'center',
            wordWrap: { width: 84 },
        }).setOrigin(0.5);
        this.sprite.add([this.box, this.text]);
        scene.physics.add.existing(this.sprite);
        this.sprite.body.setSize(96, 42);
        this.sprite.body.setOffset(-48, -21);
        this.sprite.body.allowGravity = false;
        this.sprite.body.setVelocityX(-80 - Math.random() * 90);
    }

    update(time) {
        this.sprite.y += Math.sin(time / 220 + this.sprite.x * 0.01) * 0.25;
        if (this.sprite.x < this.scene.cameras.main.scrollX - 160) {
            this.sprite.destroy();
        }
    }
}

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