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() { console.log('🌟 GAME START: Clean Slate Mode'); // 1. BACKGROUND (Phaser TileSprite) // No more CSS hacks! console.log('🌾 Creating Phaser grass background...'); const centerX = this.scale.width / 2; const centerY = this.scale.height / 2; // DEBUG: YELLOW RECTANGLE PRIMITIVE // If this fails, coordinate system is broken console.log('🟡 Creating Yellow Debug Rect'); // FINAL BACKGROUND: Solid Green (Safe & Reliable) // Using visible depth 0 and slightly lighter green to distinguish from CSS this.grassBg = this.add.rectangle(centerX, centerY, 4000, 4000, 0x2a5a2a); this.grassBg.setScrollFactor(0); this.grassBg.setDepth(0); // GUARANTEED VISIBILITY (Same plane as player) console.log('✅ Background created: SOLID GREEN RECT (Depth 0)'); // 2. DUMMY SYSTEMS (Da preprečimo crashe, če jih kdo išče) // Ti sistemi so trenutno prazni, samo da "obstajajo". this.terrainSystem = { tiles: [], getTileAt: () => null, width: 100, height: 100 }; this.farmingSystem = { update: () => { } }; this.buildSystem = {}; this.inventorySystem = new InventorySystem(this); this.scene.launch('UIScene'); // UI must be active for Player interaction // (Cleanup complete) // 3. PLAYER (Kai) try { // Spawn point (Sredina 100x100 mape -> 50,50) const spawnX = 50 * 48; const spawnY = 50 * 48; // Predpostavljamo, da je Player class naložen globalno iz src/entities/Player.js // Argumenti: scene, x, y, offsetX, offsetY this.player = new Player(this, spawnX, spawnY, 0, 0); // Scale Fix if (this.player.sprite) { this.player.sprite.setScale(0.25); } console.log('✅ Player created at 50,50'); // DECORATION: Tall Grass & Trees (Starter Camp) this.addStarterCampDecoration(spawnX, spawnY); // 4. KAMERA (SMOOTH WebGL) this.cameras.main.startFollow(this.player.sprite, true, 0.1, 0.1); this.cameras.main.setLerp(0.1, 0.1); // Ultra-smooth WebGL lerp this.cameras.main.setZoom(0.8); // 🎥 INITIAL WIDE ANGLE (0.8) // CAMERA CONTROLS (Arrow keys + Mouse drag + ZOOM) this.cursors = this.input.keyboard.createCursorKeys(); this.cameraSpeed = 8; this.isDraggingCamera = false; // ZOOM CONTROL (Mouse Wheel) this.input.on('wheel', (pointer, gameObjects, deltaX, deltaY, deltaZ) => { let newZoom = this.cameras.main.zoom; // Scroll Down -> Zoom OUT (Wider) | Scroll Up -> Zoom IN (Closer) newZoom += (deltaY > 0) ? -0.1 : 0.1; // Clamp Zoom (Min: 0.4, Max: 3.0) newZoom = Phaser.Math.Clamp(newZoom, 0.4, 3.0); // Smoothly Tween Zoom this.tweens.add({ targets: this.cameras.main, zoom: newZoom, duration: 200, ease: 'Sine.easeOut' }); }); // Right-click drag to pan camera 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) { const dx = this.dragStartX - pointer.x; const dy = this.dragStartY - pointer.y; this.cameras.main.scrollX += dx; this.cameras.main.scrollY += dy; this.dragStartX = pointer.x; this.dragStartY = pointer.y; } }); this.input.on('pointerup', () => { this.isDraggingCamera = false; }); console.log('🎮 Camera controls: Arrow keys + Right-click drag'); } catch (e) { console.error('❌ CRITICAL: Player creation failed:', e); // Emergency Kai const emergencyKai = this.add.sprite(2400, 2400, 'player_style32'); emergencyKai.setScale(0.25); this.cameras.main.startFollow(emergencyKai); } console.log('🚀 CLEAN SLATE INITIALIZATION COMPLETE'); } 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; } } }