export default class GrassScene extends Phaser.Scene { constructor() { super({ key: 'GrassScene' }); this.baseTime = 12; // Start at 12:00 this.timeSpeed = 0.5; } preload() { console.log("🌿 Loading Clean Assets..."); // 1. PATHS (Absolute from server root) const PATHS = { ground: '/assets/DEMO_FAZA1/Ground/', veg: '/assets/DEMO_FAZA1/Vegetation/' }; // 2. LOAD ASSETS // Ground this.load.image('ground_base', PATHS.ground + 'tla_trava_tekstura.png'); // Vegetation - Grass this.load.image('grass_tuft', PATHS.veg + 'trava_sop.png'); this.load.image('grass_tall', PATHS.veg + 'visoka_trava.png'); // Vegetation - Trees (All phases) this.load.image('tree_f1', PATHS.veg + 'drevo_faza_1.png'); // Kalcek this.load.image('tree_f2', PATHS.veg + 'drevo_faza_2.png'); // Mlado this.load.image('tree_small', PATHS.veg + 'drevo_majhno.png'); this.load.image('tree_medium', PATHS.veg + 'drevo_srednje.png'); this.load.image('tree_large', PATHS.veg + 'drevo_veliko.png'); // Hero // Error handling this.load.on('loaderror', (file) => { console.error('FAILED TO LOAD:', file.src); }); } create() { const { width, height } = this.scale; // 1. BACKGROUND (Tiling Sprite - Base Layer) this.ground = this.add.tileSprite(0, 0, width, height, 'ground_base') .setOrigin(0, 0); // 2. VEGETATION GROUPS this.grasses = []; this.trees = []; // 3. GENERATE WORLD this.generateGrass(width, height); this.generateTrees(width, height); // 4. DAY/NIGHT OVERLAY this.dayNightOverlay = this.add.rectangle(0, 0, width, height, 0x000000, 0) .setOrigin(0, 0) .setDepth(9000); // Top layer // 5. UI INFO this.infoText = this.add.text(20, 20, 'Time: 12:00', { fontFamily: 'monospace', fontSize: '24px', fill: '#ffffff', stroke: '#000000', strokeThickness: 4 }).setDepth(10000); } generateGrass(w, h) { // A) Small Tufts (Decoration) - High Density // "Naključno razporedi trava_sop.png za vizualno gostoto" for (let i = 0; i < 150; i++) { let x = Phaser.Math.Between(0, w); let y = Phaser.Math.Between(0, h); let tuft = this.add.image(x, y, 'grass_tuft'); tuft.setScale(0.3 + Math.random() * 0.2); // Random size tuft.setAlpha(0.9); tuft.setDepth(y); // Simple Y-sort } // B) Tall Grass (Interactive) - Medium Density // "Postavi visoka_trava.png ... dodaj nežen sinusni efekt" for (let i = 0; i < 40; i++) { let x = Phaser.Math.Between(50, w - 50); let y = Phaser.Math.Between(50, h - 50); let grass = this.add.image(x, y, 'grass_tall'); grass.setScale(0.4); grass.setOrigin(0.5, 1); // Pivot at bottom grass.setDepth(y); // Custom properties for wind animation grass.swaySpeed = 0.002 + Math.random() * 0.001; grass.swayOffset = Math.random() * 100; this.grasses.push(grass); } } generateTrees(w, h) { const treeTypes = ['tree_f1', 'tree_f2', 'tree_small', 'tree_medium', 'tree_large']; for (let i = 0; i < 12; i++) { let x = Phaser.Math.Between(50, w - 50); let y = Phaser.Math.Between(50, h - 50); // Randomly pick a growth stage let type = Phaser.Math.RND.pick(treeTypes); let tree = this.add.image(x, y, type); tree.setOrigin(0.5, 0.9); // Pivot near bottom tree.setDepth(y); // Sort by Y // Scale adjustments to look good if (type === 'tree_large') tree.setScale(0.8); else if (type === 'tree_medium') tree.setScale(0.7); else tree.setScale(0.6); // Subtle sway for trees too tree.swaySpeed = 0.0005 + Math.random() * 0.0005; tree.swayOffset = Math.random() * 100; this.trees.push(tree); } } update(time, delta) { // 1. WIND ANIMATION // "Dodaj nežen sinusni efekt za plapolanje" this.grasses.forEach(g => { g.rotation = Math.sin((time * g.swaySpeed) + g.swayOffset) * 0.15; // Stronger sway for grass }); this.trees.forEach(t => { t.rotation = Math.sin((time * t.swaySpeed) + t.swayOffset) * 0.02; // Very subtle for trees }); // 2. DAY/NIGHT CYCLE this.baseTime += (delta * 0.001 * this.timeSpeed); if (this.baseTime >= 24) this.baseTime = 0; this.updateLighting(this.baseTime); // Update UI let hour = Math.floor(this.baseTime); let minute = Math.floor((this.baseTime % 1) * 60).toString().padStart(2, '0'); this.infoText.setText(`Time: ${hour}:${minute}`); } updateLighting(hour) { let alpha = 0; let color = 0x000000; // Simple Day/Night Logic if (hour >= 20 || hour < 5) { alpha = 0.7; // Night color = 0x000022; } else if (hour >= 5 && hour < 8) { alpha = 0.3; // Dawn color = 0xFF4500; } else if (hour >= 18 && hour < 20) { alpha = 0.4; // Dusk color = 0xFF4500; } else { alpha = 0; // Day } this.dayNightOverlay.setFillStyle(color, alpha); } }