novi trgovc

This commit is contained in:
2025-12-07 23:21:12 +01:00
parent 6b8f9aee66
commit 22e7b1a6d2
7 changed files with 82 additions and 4 deletions

BIN
assets/merchant_new.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 KiB

View File

@@ -6,6 +6,7 @@ class NPC {
this.gridX = gridX;
this.gridY = gridY;
this.type = type;
console.log(`🎭 NPC Constructor called - Type: ${type} at (${gridX}, ${gridY})`);
// Terrain offset
this.offsetX = offsetX;
@@ -119,8 +120,14 @@ class NPC {
isAnimated = true;
} else if (this.type === 'zombie' && this.scene.textures.exists('zombie_sprite')) {
texKey = 'zombie_sprite';
} else if (this.type === 'merchant' && this.scene.textures.exists('merchant_sprite')) {
texKey = 'merchant_sprite';
} else if (this.type === 'merchant') {
// Uporabi generirano sliko, če obstaja
if (this.scene.textures.exists('merchant_new')) {
texKey = 'merchant_new';
} else {
texKey = 'merchant_texture'; // Fallback na proceduralno
}
console.log('🏪 Creating MERCHANT NPC with texture:', texKey);
} else if (!this.scene.textures.exists(texKey)) {
TextureGenerator.createNPCSprite(this.scene, texKey, this.type);
}
@@ -137,7 +144,9 @@ class NPC {
if (isAnimated) {
this.sprite.setScale(1.5);
} else {
this.sprite.setScale(0.3);
// Merchant manjši, ostali večji
const scale = (this.type === 'merchant') ? 0.2 : 0.5;
this.sprite.setScale(scale);
}
// HEALTH BAR

View File

@@ -110,7 +110,7 @@ class Player {
if (isAnimated) {
this.sprite.setScale(1.5);
} else {
this.sprite.setScale(0.3);
this.sprite.setScale(0.5); // Povečano
}
// --- HAND / HELD ITEM SPRITE ---

View File

@@ -74,6 +74,7 @@ class GameScene extends Phaser.Scene {
for (let i = 0; i < 3; i++) {
const randomX = Phaser.Math.Between(40, 60); // Closer to center
const randomY = Phaser.Math.Between(40, 60);
console.log(`👤 Spawning NPC type: ${npcTypes[i]} at (${randomX}, ${randomY})`);
const npc = new NPC(this, randomX, randomY, this.terrainOffsetX, this.terrainOffsetY, npcTypes[i]);
this.npcs.push(npc);
}

View File

@@ -50,6 +50,7 @@ class PreloadScene extends Phaser.Scene {
this.load.image('rock_small', 'assets/rock_small.png');
this.load.image('tree_dead_new', 'assets/tree_dead_new.png');
this.load.image('flowers_new', 'assets/flowers_new.png');
this.load.image('merchant_new', 'assets/merchant_new.png');
this.load.image('hill_sprite', 'assets/hill_sprite.png');
this.load.image('fence', 'assets/fence.png');
this.load.image('gravestone', 'assets/gravestone.png');
@@ -121,6 +122,7 @@ class PreloadScene extends Phaser.Scene {
'rock_1',
'rock_2',
'rock_small',
'merchant_new',
'tree_dead_new',
'flowers_new',
'hill_sprite',

View File

@@ -202,11 +202,14 @@ class SaveSystem {
this.scene.statsSystem.thirst = saveData.stats.thirst;
}
// 3. Load NPCs
// 3. Load NPCs
// Pobriši trenutne
this.scene.npcs.forEach(npc => npc.destroy());
this.scene.npcs = [];
let hasMerchant = false;
// Ustvari shranjene
if (saveData.npcs) {
saveData.npcs.forEach(npcData => {
@@ -219,9 +222,23 @@ class SaveSystem {
npcData.type
);
this.scene.npcs.push(npc);
if (npcData.type === 'merchant') hasMerchant = true;
});
}
// Force Spawn Merchant if missing
if (!hasMerchant) {
// Spawn near current player position so user can find him
const px = saveData.player ? saveData.player.x : 50;
const py = saveData.player ? saveData.player.y : 50;
const mX = Math.max(0, Math.min(99, Math.floor(px) + 3));
const mY = Math.max(0, Math.min(99, Math.floor(py) + 3));
const merchant = new NPC(this.scene, mX, mY, this.scene.terrainOffsetX, this.scene.terrainOffsetY, 'merchant');
this.scene.npcs.push(merchant);
console.log("🏪 FORCE SPAWNED MERCHANT at", mX, mY);
}
// 4. Camera
if (saveData.camera) {
this.scene.cameras.main.setZoom(saveData.camera.zoom);

View File

@@ -64,6 +64,54 @@ class TextureGenerator {
canvas.refresh();
}
static createMerchantSprite(scene, key = 'merchant_texture') {
if (scene.textures.exists(key)) return;
console.log('🧙‍♂️ Creating Merchant Sprite Texture...');
try {
const canvas = scene.textures.createCanvas(key, 32, 32);
const ctx = canvas.getContext();
ctx.clearRect(0, 0, 32, 32);
// Body (BRIGHT GOLD robe - zelo viden!)
ctx.fillStyle = '#FFD700'; // Gold
ctx.fillRect(8, 6, 16, 26);
// Head
ctx.fillStyle = '#FFE4C4'; // Bisque skin
ctx.fillRect(10, 4, 12, 12);
// Hat (Red Merchants Hat)
ctx.fillStyle = '#8B0000'; // DarkRed
ctx.fillRect(8, 2, 16, 4);
ctx.fillRect(10, 0, 12, 2); // Hat Top
// Backpack (Brown - visible on sides)
ctx.fillStyle = '#8B4513';
ctx.fillRect(4, 10, 4, 14); // Left side pack
ctx.fillRect(24, 10, 4, 14); // Right side pack
// Straps
ctx.fillStyle = '#A0522D';
ctx.fillRect(8, 10, 16, 2);
// Eyes
ctx.fillStyle = '#000000';
ctx.fillRect(13, 8, 2, 2);
ctx.fillRect(17, 8, 2, 2);
// Beard (White)
ctx.fillStyle = '#F5F5F5';
ctx.fillRect(10, 12, 12, 4);
ctx.fillRect(12, 16, 8, 2);
canvas.refresh();
console.log('✅ Merchant Sprite Created!');
}
catch (error) {
console.error('❌ ERROR creating merchant sprite:', error);
}
}
static createCloudSprite(scene, key = 'cloud') {
if (scene.textures.exists(key)) return;
const canvas = scene.textures.createCanvas(key, 64, 32);
@@ -336,6 +384,7 @@ class TextureGenerator {
TextureGenerator.createPlayerSprite(this.scene);
TextureGenerator.createPlayerWalkSprite(this.scene);
TextureGenerator.createNPCSprite(this.scene, 'npc', 'zombie');
TextureGenerator.createMerchantSprite(this.scene, 'merchant_texture');
TextureGenerator.createFlowerSprite(this.scene);
TextureGenerator.createBushSprite(this.scene);