Implementacija rasti trave in inventarja za travo
This commit is contained in:
@@ -164,6 +164,15 @@ export default class GrassSceneClean extends Phaser.Scene {
|
|||||||
allowGravity: false
|
allowGravity: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// INVENTAR
|
||||||
|
this.inventory = { grass: 0 };
|
||||||
|
this.inventoryText = this.add.text(20, 20, 'Trava: 0', {
|
||||||
|
fontSize: '32px',
|
||||||
|
fill: '#ffffff',
|
||||||
|
stroke: '#000000',
|
||||||
|
strokeThickness: 4
|
||||||
|
}).setScrollFactor(0).setDepth(1000); // UI always on top
|
||||||
|
|
||||||
const GRASS_COUNT = 3000;
|
const GRASS_COUNT = 3000;
|
||||||
const SPREAD = 4000; // 4000px radius okoli centra
|
const SPREAD = 4000; // 4000px radius okoli centra
|
||||||
|
|
||||||
@@ -176,10 +185,21 @@ export default class GrassSceneClean extends Phaser.Scene {
|
|||||||
// Ustvari travo in jo dodaj v grupo
|
// Ustvari travo in jo dodaj v grupo
|
||||||
let grass = this.grassGroup.create(x, y, key);
|
let grass = this.grassGroup.create(x, y, key);
|
||||||
|
|
||||||
grass.setScale(0.5 + Math.random() * 0.5);
|
let targetScale = 0.5 + Math.random() * 0.5;
|
||||||
|
grass.setScale(0); // Start at 0 for growth animation
|
||||||
grass.setAngle(Math.random() * 20 - 10);
|
grass.setAngle(Math.random() * 20 - 10);
|
||||||
grass.setAlpha(0.8 + Math.random() * 0.2);
|
grass.setAlpha(0.8 + Math.random() * 0.2);
|
||||||
|
|
||||||
|
// Growth Tween
|
||||||
|
this.tweens.add({
|
||||||
|
targets: grass,
|
||||||
|
scaleX: targetScale,
|
||||||
|
scaleY: targetScale,
|
||||||
|
duration: 500 + Math.random() * 500,
|
||||||
|
delay: Math.random() * 1000,
|
||||||
|
ease: 'Back.out'
|
||||||
|
});
|
||||||
|
|
||||||
// Physics body (circle for better feel)
|
// Physics body (circle for better feel)
|
||||||
if (grass.body) {
|
if (grass.body) {
|
||||||
grass.body.setCircle(grass.width / 4);
|
grass.body.setCircle(grass.width / 4);
|
||||||
@@ -768,6 +788,10 @@ export default class GrassSceneClean extends Phaser.Scene {
|
|||||||
this.physics.overlap(this.kai, this.grassGroup, (player, grass) => {
|
this.physics.overlap(this.kai, this.grassGroup, (player, grass) => {
|
||||||
// 1. Uniči travo
|
// 1. Uniči travo
|
||||||
grass.destroy();
|
grass.destroy();
|
||||||
|
|
||||||
|
// 2. Dodaj v inventar
|
||||||
|
this.inventory.grass++;
|
||||||
|
this.inventoryText.setText('Trava: ' + this.inventory.grass);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user