nalaganje tiled mape. ozadje ni OK.
This commit is contained in:
@@ -115,7 +115,12 @@ class Player {
|
||||
}
|
||||
|
||||
// Kreira sprite
|
||||
const screenPos = this.iso.toScreen(this.gridX, this.gridY);
|
||||
// 🎨 FLAT 2D (NEW!) - Direct screen conversion
|
||||
const tileSize = 48;
|
||||
const screenPos = {
|
||||
x: Math.round((this.gridX * tileSize) + (tileSize / 2)),
|
||||
y: Math.round((this.gridY * tileSize) + (tileSize / 2))
|
||||
};
|
||||
this.sprite = this.scene.add.sprite(
|
||||
screenPos.x + this.offsetX,
|
||||
screenPos.y + this.offsetY,
|
||||
@@ -268,9 +273,11 @@ class Player {
|
||||
|
||||
// Update grid position from pixel position
|
||||
const screenPos = { x: this.sprite.x - this.offsetX, y: this.sprite.y - this.offsetY };
|
||||
const gridPos = this.iso.toGrid(screenPos.x, screenPos.y);
|
||||
this.gridX = Math.floor(gridPos.x);
|
||||
this.gridY = Math.floor(gridPos.y);
|
||||
|
||||
// 🎨 FLAT 2D (NEW!) - Direct grid conversion
|
||||
const tileSize = 48;
|
||||
this.gridX = Math.floor(screenPos.x / tileSize);
|
||||
this.gridY = Math.floor(screenPos.y / tileSize);
|
||||
|
||||
// Check if moving
|
||||
const speed = Math.sqrt(this.velocity.x ** 2 + this.velocity.y ** 2);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,7 +36,8 @@ class PreloadScene extends Phaser.Scene {
|
||||
// this.load.tilemapTiledJSON('micro_farm_128x128', 'assets/maps/micro_farm_128x128.json'); // 🌾 Testna farma
|
||||
// this.load.tilemapTiledJSON('micro_farm_8x8', 'assets/maps/micro_farm_8x8.json'); // 🏕️ Manjša test mapa
|
||||
// 🗺️ TILED MAP (User's NovaFarma)
|
||||
this.load.tilemapTiledJSON('NovaFarma', 'assets/maps/NovaFarma.json');
|
||||
// Add cache busting to force reload of new exports
|
||||
this.load.tilemapTiledJSON('NovaFarma', `assets/maps/NovaFarma.json?v=${Date.now()}`);
|
||||
|
||||
// 🎨 TILED TILESETS (Manual Loading)
|
||||
const kzPath = 'assets/narezano_in_majhno/krvava_zetev_sprites/';
|
||||
|
||||
@@ -69,6 +69,91 @@ class Flat2DTerrainSystem {
|
||||
console.log('✅ Flat 2D map ready!');
|
||||
}
|
||||
|
||||
// 🗺️ Load map directly from Tiled JSON (User Created)
|
||||
loadFromTiled(map) {
|
||||
this.tiledMap = map;
|
||||
console.log('🗺️ Loading terrain from Tiled map:', map.key);
|
||||
|
||||
// Update system dimensions
|
||||
this.width = map.width;
|
||||
this.height = map.height;
|
||||
this.tileSize = map.tileWidth;
|
||||
|
||||
// Prepare tilesets array
|
||||
const tilesets = [];
|
||||
|
||||
// Helper to map tileset names to Phaser keys (similar to TiledTestScene)
|
||||
const getTilesetKey = (name) => {
|
||||
const mapping = {
|
||||
'grass': 'tileset_grass',
|
||||
'dirt': 'tileset_dirt',
|
||||
'water': 'tileset_water',
|
||||
'decorations': 'tileset_decorations',
|
||||
'01_Ground': 'tileset_01_Ground',
|
||||
'02_Obstacles': 'tileset_02_Obstacles',
|
||||
'03_Fences': 'tileset_03_Fences',
|
||||
'04_Buildings': 'tileset_04_Buildings',
|
||||
'05_Tools_Items': 'tileset_05_Tools_Items'
|
||||
};
|
||||
return mapping[name] || `tileset_${name}`;
|
||||
};
|
||||
|
||||
// Load tilesets
|
||||
map.tilesets.forEach(tilesetData => {
|
||||
let textureKey = getTilesetKey(tilesetData.name);
|
||||
|
||||
// 🕵️ Try to find texture (Prefix matched OR Exact name)
|
||||
if (!this.scene.textures.exists(textureKey)) {
|
||||
// Fallback: Try the raw tileset name as key
|
||||
if (this.scene.textures.exists(tilesetData.name)) {
|
||||
textureKey = tilesetData.name;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.scene.textures.exists(textureKey)) {
|
||||
try {
|
||||
const tileset = map.addTilesetImage(tilesetData.name, textureKey);
|
||||
if (tileset) {
|
||||
tilesets.push(tileset);
|
||||
console.log(` ✅ Tileset mapped: "${tilesetData.name}" -> Key: "${textureKey}"`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(` ❌ Failed to add tileset: ${tilesetData.name}`, e);
|
||||
}
|
||||
} else {
|
||||
console.warn(` ⚠️ Texture not found for tileset: "${tilesetData.name}". Tried keys: "tileset_${tilesetData.name}", "${tilesetData.name}"`);
|
||||
}
|
||||
});
|
||||
|
||||
// Create layers
|
||||
console.log(` Found ${map.layers.length} layers in map.`);
|
||||
map.layers.forEach((layerData, index) => {
|
||||
console.log(` Processing Layer ${index}: Name="${layerData.name}", Type="${layerData.type}", Visible=${layerData.visible}`);
|
||||
|
||||
if (layerData.visible && layerData.type === 'tilelayer') {
|
||||
const layer = map.createLayer(layerData.name, tilesets, 0, 0);
|
||||
if (layer) {
|
||||
console.log(` ✅ Layer created: ${layerData.name}`);
|
||||
|
||||
// Depth sorting
|
||||
if (layerData.name.toLowerCase().includes('ground')) layer.setDepth(1);
|
||||
else if (layerData.name.toLowerCase().includes('path')) layer.setDepth(2);
|
||||
else if (layerData.name.toLowerCase().includes('decor') || layerData.name.toLowerCase().includes('obstacle')) layer.setDepth(3);
|
||||
else if (layerData.name.toLowerCase().includes('buidling') || layerData.name.toLowerCase().includes('fence') || layerData.name.toLowerCase().includes('player')) layer.setDepth(4);
|
||||
else layer.setDepth(2);
|
||||
|
||||
// Scale if needed (usually 1 for Tiled maps if assets match)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Setup camera bounds
|
||||
this.scene.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
|
||||
this.scene.cameras.main.centerOn(map.widthInPixels / 2, map.heightInPixels / 2);
|
||||
|
||||
console.log('✅ Tiled map loaded and rendered!');
|
||||
}
|
||||
|
||||
// 🌍 PHASE 28: Create simple biome-aware background
|
||||
createBiomeBackground() {
|
||||
const size = this.tileSize;
|
||||
|
||||
@@ -10,7 +10,7 @@ class PathfindingSystem {
|
||||
// Ustvarimo workerja
|
||||
this.worker = new Worker('src/workers/pathfinding.worker.js');
|
||||
this.worker.onmessage = this.handleMessage.bind(this);
|
||||
console.log('✅ PathfindingWorker initialized.');
|
||||
console.log('✅ PathfindingWorker initialized (v2.1 - Tiled Support Ready).');
|
||||
this.initialized = true;
|
||||
} catch (err) {
|
||||
console.error('❌ Failed to init PathfindingWorker:', err);
|
||||
@@ -31,26 +31,46 @@ class PathfindingSystem {
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
let blocked = 0;
|
||||
const tile = ts.tiles[y][x];
|
||||
|
||||
// 1. Voda in void
|
||||
if (!tile || tile.type === 'water' || tile.type === 'void') {
|
||||
blocked = 1;
|
||||
} else {
|
||||
// 2. Dekoracije (Ovire)
|
||||
// Uporabimo že obstoječo logiko v TerrainSystemu (če obstaja) ali preverimo dekoracije
|
||||
const key = `${x},${y}`;
|
||||
const decor = ts.decorationsMap.get(key);
|
||||
if (decor) {
|
||||
const solidTypes = [
|
||||
'tree', 'tree_green', 'tree_blue', 'tree_dead',
|
||||
'tree_green_new', 'tree_blue_new', 'tree_dead_new',
|
||||
'rock', 'rock_asset', 'rock_new', 'rock_small', 'rock_1', 'rock_2',
|
||||
'wall', 'fence', 'house', 'gravestone'
|
||||
];
|
||||
// Preverimo substring za tipe (npr. 'tree' ujame 'tree_blue')
|
||||
const isSolid = solidTypes.some(t => decor.type.includes(t));
|
||||
if (isSolid) blocked = 1;
|
||||
// 🗺️ 1. TILED MAP SUPPORT
|
||||
if (ts.tiledMap) {
|
||||
// Check various obstacle layers
|
||||
const obstacleLayers = ['Obstacles', 'Buildings', 'Fences', '02_Obstacles', '03_Fences', '04_Buildings'];
|
||||
let isBlocked = false;
|
||||
|
||||
for (const layerName of obstacleLayers) {
|
||||
const tile = ts.tiledMap.getTileAt(x, y, true, layerName);
|
||||
if (tile && tile.index !== -1) {
|
||||
isBlocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlocked) {
|
||||
blocked = 1;
|
||||
}
|
||||
}
|
||||
// 📊 2. PROCEDURAL / FLAT TILES SUPPORT
|
||||
else {
|
||||
const tile = ts.tiles && ts.tiles[y] ? ts.tiles[y][x] : null;
|
||||
|
||||
// 1. Voda in void
|
||||
if (!tile || tile.type === 'water' || tile.type === 'void') {
|
||||
blocked = 1;
|
||||
} else {
|
||||
// 2. Dekoracije (Ovire)
|
||||
const key = `${x},${y}`;
|
||||
const decor = ts.decorationsMap.get(key);
|
||||
if (decor) {
|
||||
const solidTypes = [
|
||||
'tree', 'tree_green', 'tree_blue', 'tree_dead',
|
||||
'tree_green_new', 'tree_blue_new', 'tree_dead_new',
|
||||
'rock', 'rock_asset', 'rock_new', 'rock_small', 'rock_1', 'rock_2',
|
||||
'wall', 'fence', 'house', 'gravestone'
|
||||
];
|
||||
const isSolid = solidTypes.some(t => decor.type && decor.type.includes(t));
|
||||
if (isSolid) blocked = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user