popravek zombijo
This commit is contained in:
@@ -316,6 +316,7 @@ class NPC {
|
||||
if (this.attackCooldownTimer > 0) return;
|
||||
this.attackCooldownTimer = 1500;
|
||||
|
||||
// Attack Animation (Jump)
|
||||
if (this.sprite) {
|
||||
this.scene.tweens.add({
|
||||
targets: this.sprite,
|
||||
@@ -324,9 +325,12 @@ class NPC {
|
||||
});
|
||||
}
|
||||
|
||||
if (this.scene.statsSystem) {
|
||||
// Apply Damage to Player
|
||||
if (this.scene.player && this.scene.player.takeDamage) {
|
||||
console.log('🧟 Zombie ATTACKS Player!');
|
||||
this.scene.player.takeDamage(10);
|
||||
} else if (this.scene.statsSystem) {
|
||||
this.scene.statsSystem.takeDamage(10);
|
||||
this.scene.cameras.main.shake(100, 0.005);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,6 +445,52 @@ class NPC {
|
||||
if (idx > -1) this.scene.npcs.splice(idx, 1);
|
||||
}
|
||||
|
||||
tame() {
|
||||
if (this.state === 'TAMED' || this.type !== 'zombie') return;
|
||||
|
||||
this.state = 'TAMED';
|
||||
console.log('🧟❤️ Zombie TAMED!');
|
||||
|
||||
// Visual Feedback
|
||||
const headX = this.sprite.x;
|
||||
const headY = this.sprite.y - 40;
|
||||
|
||||
const heart = this.scene.add.text(headX, headY, '❤️', { fontSize: '20px' });
|
||||
heart.setOrigin(0.5);
|
||||
heart.setDepth(this.sprite.depth + 100);
|
||||
|
||||
this.scene.tweens.add({
|
||||
targets: heart,
|
||||
y: headY - 30,
|
||||
alpha: 0,
|
||||
duration: 1500,
|
||||
onComplete: () => heart.destroy()
|
||||
});
|
||||
|
||||
// Change color slightly to indicate friend
|
||||
this.sprite.setTint(0xAAFFAA);
|
||||
|
||||
// Hide Health Bar if tamed (optional)
|
||||
if (this.healthBarBg) {
|
||||
this.healthBarBg.setVisible(false);
|
||||
this.healthBar.setVisible(false);
|
||||
}
|
||||
|
||||
this.addTamedEyes();
|
||||
}
|
||||
|
||||
addTamedEyes() {
|
||||
if (this.eyesGroup) return;
|
||||
|
||||
this.eyesGroup = this.scene.add.container(this.sprite.x, this.sprite.y);
|
||||
this.eyesGroup.setDepth(this.sprite.depth + 1);
|
||||
|
||||
const eyeL = this.scene.add.rectangle(-4, -54, 4, 4, 0x00FFFF); // Cyan eyes
|
||||
const eyeR = this.scene.add.rectangle(4, -54, 4, 4, 0x00FFFF);
|
||||
|
||||
this.eyesGroup.add([eyeL, eyeR]);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this.sprite) this.sprite.destroy();
|
||||
if (this.healthBar) this.healthBar.destroy();
|
||||
|
||||
@@ -21,6 +21,11 @@ class Player {
|
||||
this.direction = 'down';
|
||||
this.lastDir = { x: 0, y: 1 }; // Default south
|
||||
|
||||
// Stats
|
||||
this.hp = 100;
|
||||
this.maxHp = 100;
|
||||
this.isDead = false;
|
||||
|
||||
// Kreira sprite
|
||||
this.createSprite();
|
||||
|
||||
@@ -29,13 +34,52 @@ class Player {
|
||||
|
||||
// Space za napad
|
||||
this.scene.input.keyboard.on('keydown-SPACE', () => {
|
||||
this.attack();
|
||||
if (!this.isDead) this.attack();
|
||||
});
|
||||
|
||||
// Začetna pozicija
|
||||
this.updatePosition();
|
||||
}
|
||||
|
||||
takeDamage(amount) {
|
||||
if (this.isDead) return;
|
||||
|
||||
this.hp -= amount;
|
||||
console.log(`Player HP: ${this.hp}`);
|
||||
|
||||
// Visual Feedback
|
||||
this.scene.cameras.main.shake(100, 0.01);
|
||||
this.sprite.setTint(0xff0000);
|
||||
this.scene.time.delayedCall(200, () => {
|
||||
if (!this.isDead) this.sprite.clearTint();
|
||||
});
|
||||
|
||||
// Update UI (če obstaja StatsSystem ali UI)
|
||||
if (this.scene.statsSystem) {
|
||||
// Scene specific stats update if linked
|
||||
}
|
||||
|
||||
if (this.hp <= 0) {
|
||||
this.die();
|
||||
}
|
||||
}
|
||||
|
||||
die() {
|
||||
this.isDead = true;
|
||||
this.sprite.setTint(0x555555);
|
||||
this.sprite.setRotation(Math.PI / 2); // Lie down
|
||||
console.log('💀 PLAYER DIED');
|
||||
|
||||
// Show Game Over / Reload
|
||||
const txt = this.scene.add.text(this.scene.cameras.main.midPoint.x, this.scene.cameras.main.midPoint.y, 'YOU DIED', {
|
||||
fontSize: '64px', color: '#ff0000', fontStyle: 'bold', stroke: '#000', strokeThickness: 6
|
||||
}).setOrigin(0.5).setDepth(20000);
|
||||
|
||||
this.scene.time.delayedCall(3000, () => {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
createSprite() {
|
||||
// Prefer animated sprite if available
|
||||
let texKey = 'player_walk'; // Spritesheet
|
||||
|
||||
Reference in New Issue
Block a user