dreva in kamni top

This commit is contained in:
2025-12-07 22:32:45 +01:00
parent 974141c08c
commit 6b8f9aee66
13 changed files with 384 additions and 90 deletions

View File

@@ -4,6 +4,12 @@ class IsometricUtils {
constructor(tileWidth = 48, tileHeight = 24) {
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
// Layer Constants
this.LAYER_FLOOR = 0;
this.LAYER_GRID_DECO = 100000; // Decorations on floor (shadows)
this.LAYER_OBJECTS = 200000; // Dynamic entities (Trees, Player, NPCs)
this.LAYER_UI = 300000;
}
// Kartezične (grid) koordinate -> Isometrične (screen) koordinate
@@ -21,12 +27,10 @@ class IsometricUtils {
}
// Izračun depth (z-index) za pravilno sortiranje
// Izračun depth (z-index)
// V Phaserju je najbolje uporabiti kar Y koordinato spritha.
// Tu vrnemo pričakovano Y pozicijo za grid celico.
getDepth(gridX, gridY) {
// (gridX + gridY) * tileHeight/2 je točno screenY
return (gridX + gridY) * (this.tileHeight / 2);
getDepth(gridX, gridY, layerBase = 0) {
// Depth = LayerBase + ScreenY
// To zagotovi, da so objekti v layerju sortirani po Y
return layerBase + ((gridX + gridY) * (this.tileHeight / 2));
}
// Izračun centerja tile-a

View File

@@ -311,6 +311,26 @@ class TextureGenerator {
});
}
static createSaplingSprite(scene, key = 'tree_sapling') {
if (scene.textures.exists(key)) return;
const size = 32;
const canvas = scene.textures.createCanvas(key, size, size);
const ctx = canvas.getContext();
ctx.clearRect(0, 0, size, size);
// Majhno steblo
ctx.fillStyle = '#8B4513';
ctx.fillRect(14, 20, 4, 12);
// Parnosti listov
ctx.fillStyle = '#32CD32';
ctx.beginPath(); ctx.arc(12, 18, 4, 0, Math.PI * 2); ctx.fill();
ctx.beginPath(); ctx.arc(20, 18, 4, 0, Math.PI * 2); ctx.fill();
ctx.beginPath(); ctx.arc(16, 12, 5, 0, Math.PI * 2); ctx.fill();
canvas.refresh();
}
// Helper to generate ALL textures at once
generateAll() {
TextureGenerator.createPlayerSprite(this.scene);
@@ -319,6 +339,7 @@ class TextureGenerator {
TextureGenerator.createFlowerSprite(this.scene);
TextureGenerator.createBushSprite(this.scene);
TextureGenerator.createSaplingSprite(this.scene, 'tree_sapling'); // Dodano
TextureGenerator.createTreeSprite(this.scene); // Volumetric
TextureGenerator.createRockSprite(this.scene); // Volumetric
TextureGenerator.createCloudSprite(this.scene);