PageSourceSearch

https://ctn-playfun.pages.dev/js/components/SceneSixEnemyType3.js?v=3

js ctn-playfun.pages.dev collected 2026-10-03 06:38:29 UTC 3,884 bytes, 99 lines download raw bytes

1class SceneSixEnemyType3 extends Phaser.Physics.Arcade.Sprite {
2    constructor(scene, x, y, texture, frame, initialVerticalState = 'top') {
3        super(scene, x, y, texture, frame); // Initial y is less important as it will snap
4        scene.add.existing(this);
5        scene.physics.add.existing(this);
6
7        // Basic properties
8        this.setScale(0.5); // Adjust scale as needed for this larger sprite
9        this.setImmovable(true);
10        this.body.pushable = false; // Explicitly set pushable to false
11
12        // Animation
13        if (this.scene.anims.exists('irs_ship3_idle')) {
14            this.play('irs_ship3_idle');
15        } else {
16            console.warn("SceneSixEnemyType3: 'irs_ship3_idle' animation not found!");
17        }
18
19        // Movement properties
20        this.horizontalSpeed = 120; // Pixels per second
21        this.yTopBoundary = scene.scale.height * 0.2;
22        this.yBottomBoundary = scene.scale.height * 0.8;
23        this.currentVerticalPositionState = initialVerticalState; // 'top' or 'bottom'
24        this.horizontalTravelDuration = Phaser.Math.Between(2000, 3500); // ms to travel horizontally before teleporting
25        this.timeOnCurrentSegment = 0;
26
27        // Health
28        this.health = 10;
29
30        // Snap to initial vertical position
31        this.y = (this.currentVerticalPositionState === 'top') ? this.yTopBoundary : this.yBottomBoundary;
32    }
33
34    update(time, delta) {
35        // Horizontal Movement
36        this.x -= this.horizontalSpeed * (delta / 1000);
37
38        // Teleporting Logic
39        this.timeOnCurrentSegment += delta;
40        if (this.timeOnCurrentSegment >= this.horizontalTravelDuration) {
41            this.timeOnCurrentSegment = 0;
42            this.horizontalTravelDuration = Phaser.Math.Between(2000, 3500); // Randomize next segment duration
43
44            // Switch vertical position state
45            if (this.currentVerticalPositionState === 'top') {
46                this.currentVerticalPositionState = 'bottom';
47                this.y = this.yBottomBoundary;
48            } else {
49                this.currentVerticalPositionState = 'top';
50                this.y = this.yTopBoundary;
51            }
52        }
53
54        // Deactivate if it moves off the left side of the camera's view
55        if (this.x < this.scene.cameras.main.scrollX - this.displayWidth) {
56            this.setActive(false);
57            this.setVisible(false);
58            this.destroy();
59        }
60    }
61
62    takeHit() {
63        this.health--;
64        console.log(`SceneSixEnemyType3 hit! Health: ${this.health}`);
65
66        this.setTint(0xff0000); // Turn red
67        this.scene.time.delayedCall(100, () => {
68            if (this.active) { // Check if sprite still exists
69                this.clearTint(); // Clear red tint
70            }
71        });
72
73        if (this.health <= 0) {
74            // Play.fun: award points for destroying teleporter
75            awardPoints(25);
76
77            if (window.EffectUtils && typeof window.EffectUtils.playExplosion === 'function') {
78                // Make explosion slightly larger for this bigger enemy
79                window.EffectUtils.playExplosion(this.scene, this.x, this.y, 'standard_explosion', 0.75);
80            }
81
82            // --- Play Ship Explode Sound ---
83            if (this.scene && this.scene.sound) {
84                this.scene.sound.play('shipExplode', { volume: 0.1 }); // Slightly louder for a bigger ship
85            } else {
86                console.warn("SceneSixEnemyType3: Could not play 'shipExplode' sound. Scene or sound manager missing.");
87            }
88            // --- End Play Ship Explode Sound ---
89
90            this.destroy();
91            console.log('SceneSixEnemyType3 destroyed!');
92        }
93    }
94}
95
96// Make class available if using script tags in index.html
97if (typeof window !== 'undefined') {
98    window.SceneSixEnemyType3 = SceneSixEnemyType3;
99} 

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.