class GameScene extends Phaser.Scene { constructor() { super({ key: 'GameScene' }); } preload() { // Load Kai sprite (real character, not fallback!) console.log('👤 Loading Kai sprite...'); this.load.image('kai_main', 'assets/sprites/smooth/kai_main.png'); // Load Grass Texture (Using tile version) this.load.image('grass_main', 'assets/slike/teren/grass_tile.png'); console.log('⏭️ Assets loaded'); } create(data) { console.log('🌟 GAME START: Mode =', data ? data.startMode : 'Standard'); // --- AMNESIA MODE HANDLER --- this.amnesiaMode = data && data.startMode === 'AMNESIA_WAKEUP'; this.introMusic = data ? data.backgroundMusic : null; // 1. BACKGROUND (Phaser TileSprite) console.log('🌾 Creating Phaser grass background...'); const centerX = this.scale.width / 2; const centerY = this.scale.height / 2; console.log('🟡 Creating Yellow Debug Rect'); this.grassBg = this.add.rectangle(centerX, centerY, 4000, 4000, 0x2a5a2a); this.grassBg.setScrollFactor(0); this.grassBg.setDepth(0); console.log('✅ Background created: SOLID GREEN RECT (Depth 0)'); // 2. DUMMY SYSTEMS this.terrainSystem = { tiles: [], getTileAt: () => null, width: 100, height: 100 }; this.farmingSystem = { update: () => { } }; this.buildSystem = {}; this.inventorySystem = new InventorySystem(this); this.scene.launch('UIScene'); // 3. PLAYER (Kai) try { const spawnX = 50 * 48; const spawnY = 50 * 48; this.player = new Player(this, spawnX, spawnY, 0, 0); if (this.player.sprite) { this.player.sprite.setScale(0.25); } console.log('✅ Player created at 50,50'); // --- AMNESIA WAKEUP LOCK --- if (this.amnesiaMode) { // Lock Controls (Assuming Player class checks this or we disable simple controls) // Since Player update is called in our update(), we can set a flag here this.input.keyboard.enabled = false; // Global lock initially // Visual Effect: Dizzy/Blur (Simulated with Overlay) this.amnesiaOverlay = this.add.rectangle(centerX, centerY, 4000, 4000, 0x000000) .setScrollFactor(0) .setDepth(1000) .setAlpha(0.8); // Pulse Alpha to simulate waking up this.tweens.add({ targets: this.amnesiaOverlay, alpha: 0.4, duration: 2000, yoyo: true, repeat: -1, ease: 'Sine.easeInOut' }); // Camera Wobble this.cameras.main.zoom = 1.5; this.tweens.add({ targets: this.cameras.main, zoom: 1.6, rotation: 0.05, duration: 3000, yoyo: true, repeat: -1 }); // Prompt this.wakeupText = this.add.text(centerX, centerY + 100, "Press [E] to Wake Up", { fontFamily: 'Courier', fontSize: '24px', color: '#ffffff' }).setScrollFactor(0).setDepth(1001).setOrigin(0.5).setAlpha(0); this.tweens.add({ targets: this.wakeupText, alpha: 1, duration: 1000, delay: 2000, yoyo: true, repeat: -1 }); // Wake Up Input this.input.keyboard.enabled = true; // Enable just for our listener this.input.keyboard.on('keydown-E', () => { this.wakeUpKai(); }); } // DECORATION this.addStarterCampDecoration(spawnX, spawnY); // 4. KAMERA this.cameras.main.startFollow(this.player.sprite, true, 0.1, 0.1); this.cameras.main.setLerp(0.1, 0.1); if (!this.amnesiaMode) this.cameras.main.setZoom(0.8); // CAMERA CONTROLS this.cursors = this.input.keyboard.createCursorKeys(); this.cameraSpeed = 8; this.isDraggingCamera = false; this.input.on('wheel', (pointer, gameObjects, deltaX, deltaY, deltaZ) => { let newZoom = this.cameras.main.zoom; newZoom += (deltaY > 0) ? -0.1 : 0.1; newZoom = Phaser.Math.Clamp(newZoom, 0.4, 3.0); this.tweens.add({ targets: this.cameras.main, zoom: newZoom, duration: 200, ease: 'Sine.easeOut' }); }); this.input.on('pointerdown', (pointer) => { if (pointer.rightButtonDown()) { this.cameras.main.stopFollow(); this.isDraggingCamera = true; this.dragStartX = pointer.x; this.dragStartY = pointer.y; } }); this.input.on('pointermove', (pointer) => { if (this.isDraggingCamera) { this.cameras.main.scrollX += (this.dragStartX - pointer.x); this.cameras.main.scrollY += (this.dragStartY - pointer.y); this.dragStartX = pointer.x; this.dragStartY = pointer.y; } }); this.input.on('pointerup', () => { this.isDraggingCamera = false; }); console.log('🎮 Camera controls initialized'); } catch (e) { console.error('❌ CRITICAL: Player creation failed:', e); const emergencyKai = this.add.sprite(2400, 2400, 'player_style32'); emergencyKai.setScale(0.25); this.cameras.main.startFollow(emergencyKai); } console.log('🚀 CLEAN SLATE INITIALIZATION COMPLETE'); } wakeUpKai() { console.log('🌅 Kai is waking up...'); this.input.keyboard.off('keydown-E'); // Remove listener // 1. Fade out Overlay this.tweens.add({ targets: this.amnesiaOverlay, alpha: 0, duration: 2000, onComplete: () => { this.amnesiaOverlay.destroy(); this.wakeupText.destroy(); } }); // 2. Normalize Camera this.tweens.add({ targets: this.cameras.main, zoom: 0.8, rotation: 0, duration: 2000, ease: 'Power2' }); // 3. Fade Out Intro Music (to Silence or Game Loop) if (this.introMusic) { this.tweens.add({ targets: this.introMusic, volume: 0, duration: 3000, onComplete: () => { this.introMusic.stop(); // Here we could start normal farm music } }); } // 4. Enable Gameplay // NOTE: We might need to enable specific Player controls if they were locked this.amnesiaMode = false; } addStarterCampDecoration(centerX, centerY) { console.log('🌲 Adding starter camp decoration (Graphics)...'); // TALL GRASS (10 green circles with SWAYING animation) for (let i = 0; i < 10; i++) { const angle = (Math.PI * 2 / 10) * i + Math.random() * 0.5; const distance = 100 + Math.random() * 150; const x = centerX + Math.cos(angle) * distance; const y = centerY + Math.sin(angle) * distance; const grass = this.add.circle(x, y, 8 + Math.random() * 6, 0x4a8a4a, 0.8); grass.setDepth(-50); grass.setStrokeStyle(2, 0x2a5a2a, 1); // SWAYING ANIMATION (wind effect) this.tweens.add({ targets: grass, x: x + (Math.random() - 0.5) * 10, // Sway left/right scaleY: 0.9 + Math.random() * 0.2, // Slight height variation duration: 1000 + Math.random() * 1000, yoyo: true, repeat: -1, // Infinite loop ease: 'Sine.easeInOut', delay: Math.random() * 1000 // Random start time }); } // TREES (3 dark green triangles around camp) const treePositions = [ { x: centerX - 200, y: centerY - 150 }, { x: centerX + 220, y: centerY - 100 }, { x: centerX - 180, y: centerY + 180 } ]; treePositions.forEach(pos => { // Tree trunk (brown rectangle) const trunk = this.add.rectangle(pos.x, pos.y + 20, 10, 30, 0x6b4423); trunk.setDepth(-40); // Tree crown (green triangle) const crown = this.add.triangle(pos.x, pos.y - 10, 0, 40, -30, -20, 30, -20, 0x2a6a2a); crown.setDepth(-40); crown.setStrokeStyle(3, 0x1a4a1a, 1); }); console.log('✅ Starter camp decoration added!'); } update(time, delta) { // 1. PLAYER UPDATE if (this.player) { this.player.update(time, delta); } // 2. MANUAL CAMERA CONTROLS (Arrow Keys) if (this.cursors) { const speed = this.cameraSpeed || 8; let moved = false; if (this.cursors.left.isDown) { this.cameras.main.scrollX -= speed; moved = true; } else if (this.cursors.right.isDown) { this.cameras.main.scrollX += speed; moved = true; } if (this.cursors.up.isDown) { this.cameras.main.scrollY -= speed; moved = true; } else if (this.cursors.down.isDown) { this.cameras.main.scrollY += speed; moved = true; } // If manual movement detected, stop following player if (moved) { this.cameras.main.stopFollow(); } } // 3. TILESPRITE PARALLAX (Native Phaser) if (this.grassBg) { // Keep background visible at scale this.grassBg.setX(this.cameras.main.scrollX + this.scale.width / 2); this.grassBg.setY(this.cameras.main.scrollY + this.scale.height / 2); // Scroll texture this.grassBg.tilePositionX = this.cameras.main.scrollX; this.grassBg.tilePositionY = this.cameras.main.scrollY; } } }