različne velikosti dreves

This commit is contained in:
2025-12-07 03:40:50 +01:00
parent 9eb57ed117
commit 521468c797
8 changed files with 323 additions and 109 deletions

View File

@@ -61,7 +61,6 @@ class TerrainSystem {
}
);
// Tipi terena z threshold vrednostmi + Y-LAYER STACKING
this.terrainTypes = {
WATER: { threshold: 0.3, color: 0x2166aa, name: 'water', texture: 'tile_water', yLayer: -1 },
@@ -73,6 +72,7 @@ class TerrainSystem {
DIRT: { threshold: 0.75, color: 0x8b6f47, name: 'dirt', texture: 'tile_dirt', yLayer: 2 }, // C: Full dirt
STONE: { threshold: 1.0, color: 0x7d7d7d, name: 'stone', texture: 'tile_stone', yLayer: 3 },
PATH: { threshold: 999, color: 0x9b7653, name: 'path', texture: 'tile_path', yLayer: 0 }, // Pot/Road
FARMLAND: { threshold: 999, color: 0x4a3c2a, name: 'farmland', texture: 'tile_farmland', yLayer: 0 }
};
}
@@ -115,7 +115,7 @@ class TerrainSystem {
const tileW = this.iso.tileWidth;
const tileH = this.iso.tileHeight;
const thickness = 25; // Minecraft-style thickness (increased from 10)
const thickness = 8; // Minimal thickness - nearly 2D
const graphics = this.scene.make.graphics({ x: 0, y: 0, add: false });
@@ -197,6 +197,14 @@ class TerrainSystem {
const py = Math.random() * tileH;
graphics.fillRect(px, py, 2, 1);
}
} else if (type.name === 'path') {
// Path texture: Small gravel stones
graphics.fillStyle(0x7a5e42, 0.5); // Darker brown
for (let i = 0; i < 12; i++) {
const px = Math.random() * tileW;
const py = Math.random() * tileH;
graphics.fillRect(px, py, 2, 2);
}
}
// 5. Crisp black outline for block definition
@@ -294,6 +302,16 @@ class TerrainSystem {
// Get terrain type based on BOTH noise and elevation (Y-layer)
let terrainType = this.getTerrainTypeByElevation(noiseValue, elevation);
// === PATH GENERATION ===
// Use a separate noise layer for paths (higher frequency for winding roads)
const pathNoise = this.noise.getNormalized(x, y, 0.08, 2);
// Create minimal paths - if noise is in a very specific narrow band
// Avoid water (0.3 threshold) and edges
if (pathNoise > 0.48 && pathNoise < 0.52 && noiseValue > 0.35) {
terrainType = this.terrainTypes.PATH;
}
// === FLOATING ISLAND EDGE ===
const edgeDistance = 2; // Tiles from edge (tighter border)
const isNearEdge = x < edgeDistance || x >= this.width - edgeDistance ||
@@ -333,20 +351,20 @@ class TerrainSystem {
let decorType = null;
let maxHp = 1;
if (terrainType.name === 'grass') {
if (terrainType.name.includes('grass')) { // Check ANY grass type
const rand = Math.random();
// Na hribih več kamnov
if (elevation > 0.6 && rand < 0.05) {
decorType = 'bush'; // Kamni (bomo kasneje naredili 'stone' tip)
decorType = 'bush'; // Kamni
maxHp = 5;
} else if (rand < 0.01) {
} else if (rand < 0.025) { // Reduced to 2.5% trees (optimum balance)
decorType = 'tree';
maxHp = 5;
} else if (rand < 0.015) {
} else if (rand < 0.03) {
decorType = 'gravestone'; // 💀 Nagrobniki
maxHp = 10; // Težje uničiti
} else if (rand < 0.1) {
} else if (rand < 0.08) {
decorType = 'flower';
maxHp = 1;
}
@@ -595,7 +613,11 @@ class TerrainSystem {
this.visibleTiles.set(key, sprite);
}
// Crop Logic (render before decor or after? Same layer mostly)
// Elevation effect matching tile logic
const tileData = this.tiles[y][x];
const elevationOffset = tileData.elevation * -25;
// Crop Logic
if (this.tiles[y][x].hasCrop) {
neededCropKeys.add(key);
if (!this.visibleCrops.has(key)) {
@@ -606,7 +628,7 @@ class TerrainSystem {
sprite.setTexture(`crop_stage_${cropData.stage}`);
sprite.setPosition(
cropPos.x + this.offsetX,
cropPos.y + this.offsetY + this.iso.tileHeight / 2
cropPos.y + this.offsetY + this.iso.tileHeight / 2 + elevationOffset
);
const depth = this.iso.getDepth(x, y);
sprite.setDepth(depth + 1); // Just slightly above tile
@@ -628,9 +650,11 @@ class TerrainSystem {
const decorPos = this.iso.toScreen(x, y);
const sprite = this.decorationPool.get();
sprite.setTexture(decor.type);
// Apply same elevation offset as tile
sprite.setPosition(
decorPos.x + this.offsetX,
decorPos.y + this.offsetY + this.iso.tileHeight / 2
decorPos.y + this.offsetY + this.iso.tileHeight / 2 + elevationOffset
);
const depth = this.iso.getDepth(x, y);
@@ -638,6 +662,20 @@ class TerrainSystem {
else sprite.setDepth(depth + 1000); // Taller objects update depth
sprite.flipX = (x + y) % 2 === 0;
// INTERACTIVITY FIX: Allow clicking sprites directly
sprite.setInteractive({ pixelPerfect: true, useHandCursor: true });
// Clear old listeners
sprite.off('pointerdown');
// Add click listener
sprite.on('pointerdown', (pointer) => {
if (this.scene.interactionSystem) {
// Manually trigger interaction logic
this.scene.interactionSystem.handleDecorationClick(x, y);
}
});
this.visibleDecorations.set(key, sprite);
}
}