From 14ee4bb39e805a15993ac9ac38bf7310217edd0d Mon Sep 17 00:00:00 2001 From: David Kotnik Date: Sat, 31 Jan 2026 08:18:25 +0100 Subject: [PATCH] Implementacija trganja trave in ustvarjanja potk (SPACE) --- .../src/scenes/GrassScene_Clean.js | 73 ++++++++++++++----- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/nova farma TRAE/src/scenes/GrassScene_Clean.js b/nova farma TRAE/src/scenes/GrassScene_Clean.js index d300598dd..1d2b7f825 100644 --- a/nova farma TRAE/src/scenes/GrassScene_Clean.js +++ b/nova farma TRAE/src/scenes/GrassScene_Clean.js @@ -14,6 +14,9 @@ export default class GrassSceneClean extends Phaser.Scene { this.load.image('stream_final_v7', 'DEMO_FAZA1/Environment/stream_final_v7.png'); // Removed extensions for now + // 2. Load path/mud assets + this.load.image('path_mud', 'DEMO_FAZA1/Ground/path_mud_0.png'); + // 3. Foliage this.load.image('grass_dense', 'DEMO_FAZA1/Vegetation/grass_cluster_dense.png'); this.load.image('grass_tall', 'DEMO_FAZA1/Vegetation/visoka_trava.png'); @@ -158,35 +161,43 @@ export default class GrassSceneClean extends Phaser.Scene { }); */ - // --- 3. FOLIAGE (Trava - Šopi) --- - // Generiranje trave okoli igralca (ne po celi mapi zaradi performance) + // --- 3. FOLIAGE (Trava) --- + this.grassGroup = this.physics.add.group({ + immovable: true, + allowGravity: false + }); + + // Path group (za potke) + this.pathGroup = this.add.group(); + const GRASS_COUNT = 3000; const SPREAD = 4000; // 4000px radius okoli centra for (let i = 0; i < GRASS_COUNT; i++) { - // Random pozicija okoli centra let x = (WORLD_W / 2) + (Math.random() * SPREAD * 2 - SPREAD); let y = (WORLD_H / 2) + (Math.random() * SPREAD * 2 - SPREAD); - // 80% verjetnost za navadno travo, 20% za visoko let key = Math.random() > 0.2 ? 'grass_dense' : 'grass_tall'; - let grass = this.add.image(x, y, key); + // Ustvari travo in jo dodaj v grupo + let grass = this.grassGroup.create(x, y, key); - // Randomizacija - grass.setScale(0.5 + Math.random() * 0.5); // 0.5 do 1.0 - grass.setAngle(Math.random() * 20 - 10); // Rahla rotacija - grass.setAlpha(0.8 + Math.random() * 0.2); // Rahla prosojnost + grass.setScale(0.5 + Math.random() * 0.5); + grass.setAngle(Math.random() * 20 - 10); + grass.setAlpha(0.8 + Math.random() * 0.2); - if (key === 'grass_tall') { - grass.setOrigin(0.5, 0.9); // Pivot spodaj - grass.setDepth(y); // Y-sortiranje za visoko travo - } else { - grass.setDepth(y - 50); // Nizka trava je vedno pod igralcem, a nad tlemi + // Physics body (circle for better feel) + if (grass.body) { + grass.body.setCircle(grass.width / 4); + grass.body.setOffset(grass.width / 4, grass.height / 4); + } + + if (key === 'grass_tall') { + grass.setOrigin(0.5, 0.9); + grass.setDepth(y); + } else { + grass.setDepth(y - 50); } - - // Interakcija (opcijsko, za lepši občutek) - // grass.setInteractive(); } // --- 4. ITEMS & OBSTACLES --- @@ -756,6 +767,34 @@ export default class GrassSceneClean extends Phaser.Scene { const right = this.cursors.right.isDown || this.keys.right.isDown; const up = this.cursors.up.isDown || this.keys.up.isDown; const down = this.cursors.down.isDown || this.keys.down.isDown; + const space = this.cursors.space.isDown; + + // --- GRASS PLUCKING MECHANIC (Trganje trave) --- + if (space) { + this.physics.overlap(this.kai, this.grassGroup, (player, grass) => { + // 1. Uniči travo + grass.destroy(); + + // 2. Ustvari potko (če še ne obstaja na tej lokaciji) + // Preverimo, če je že kakšna potka zelo blizu, da ne spamamo spritov + let pathExists = false; + this.pathGroup.getChildren().forEach(path => { + if (Phaser.Math.Distance.Between(path.x, path.y, player.x, player.y) < 30) { + pathExists = true; + } + }); + + if (!pathExists) { + // Ustvari blatno potko pod igralcem + let mud = this.add.image(player.x, player.y + 20, 'path_mud'); // Malo zamika pod noge + mud.setDepth(-90); // Tik nad tlemi (-100), pod vsem ostalim + mud.setAlpha(0.7); + mud.setAngle(Math.random() * 360); + mud.setScale(0.8 + Math.random() * 0.4); + this.pathGroup.add(mud); + } + }); + } if (left) { this.kai.setVelocityX(-speed);