carakter
This commit is contained in:
@@ -107,15 +107,16 @@ class Player {
|
||||
this.sprite = this.scene.add.sprite(
|
||||
screenPos.x + this.offsetX,
|
||||
screenPos.y + this.offsetY,
|
||||
texKey
|
||||
texKey,
|
||||
0 // CRITICAL: Start with frame 0 (first frame only)
|
||||
);
|
||||
this.sprite.setOrigin(0.5, 0.8); // Changed from 1 to 0.8 to show legs
|
||||
this.sprite.setOrigin(0.5, 1.0); // Bottom center - new sprite has full character!
|
||||
|
||||
// Scale based on sprite type
|
||||
if (texKey === 'player_protagonist') {
|
||||
this.sprite.setScale(1.0); // Smaller protagonist sprite
|
||||
this.sprite.setScale(0.5); // 256x256 frames scaled to 128x128 display size
|
||||
} else {
|
||||
this.sprite.setScale(1.0); // Fallback sprite
|
||||
this.sprite.setScale(0.5); // Fallback sprite
|
||||
}
|
||||
|
||||
|
||||
@@ -328,39 +329,65 @@ class Player {
|
||||
|
||||
// Update Facing Direction and Last Dir
|
||||
if (moved) {
|
||||
// Keep diagonal input clean or prioritize one axis?
|
||||
// Just use the calculated dx/dy.
|
||||
// Note: If both UP and LEFT pressed, logic above overwrites dx/dy.
|
||||
// Let's refine to allow diagonal accumulation if needed, but existing logic prioritized axis.
|
||||
// Current logic: RIGHT/LEFT overwrites UP/DOWN. This is fine for now.
|
||||
|
||||
this.lastDir = { x: dx, y: dy };
|
||||
this.sprite.setFlipX(!facingRight);
|
||||
|
||||
// Play walking animation (with safety check)
|
||||
// Determine animation direction (4 directions)
|
||||
let animDir = 'down'; // default
|
||||
|
||||
// UP/DOWN (isometric: dx changes)
|
||||
if (dx < 0 && dy === 0) {
|
||||
animDir = 'up'; // Moving up (NW in isometric)
|
||||
} else if (dx > 0 && dy === 0) {
|
||||
animDir = 'down'; // Moving down (SE in isometric)
|
||||
}
|
||||
// LEFT/RIGHT (isometric: dy changes)
|
||||
else if (dy > 0 && dx === 0) {
|
||||
animDir = 'left'; // Moving left (SW in isometric)
|
||||
} else if (dy < 0 && dx === 0) {
|
||||
animDir = 'right'; // Moving right (NE in isometric)
|
||||
}
|
||||
|
||||
this.direction = animDir;
|
||||
|
||||
// Play walking animation for the direction
|
||||
if (this.sprite.anims) {
|
||||
try {
|
||||
if (this.scene.anims.exists('protagonist_walk') && !this.sprite.anims.isPlaying) {
|
||||
this.sprite.play('protagonist_walk');
|
||||
const walkAnim = `protagonist_walk_${animDir}`;
|
||||
|
||||
// Debug
|
||||
console.log(`🎬 Trying to play: ${walkAnim}`);
|
||||
console.log(`Animation exists: ${this.scene.anims.exists(walkAnim)}`);
|
||||
|
||||
if (this.scene.anims.exists(walkAnim)) {
|
||||
this.sprite.play(walkAnim, true); // Force restart animation
|
||||
console.log(`✅ Playing: ${walkAnim}`);
|
||||
} else {
|
||||
console.warn(`⚠️ Animation not found: ${walkAnim}`);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore animation errors
|
||||
console.error('Animation error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Hand offset
|
||||
const handOffset = facingRight ? 10 : -10;
|
||||
this.handSprite.setX(this.sprite.x + handOffset);
|
||||
this.handSprite.setFlipX(!facingRight);
|
||||
// Hand offset based on direction
|
||||
const handOffsets = {
|
||||
'left': -10,
|
||||
'right': 10,
|
||||
'up': 0,
|
||||
'down': 0
|
||||
};
|
||||
this.handSprite.setX(this.sprite.x + (handOffsets[animDir] || 0));
|
||||
} else {
|
||||
// Stop animation when idle (with safety check)
|
||||
// Stop animation when idle
|
||||
if (this.sprite.anims) {
|
||||
try {
|
||||
if (this.sprite.anims.isPlaying) {
|
||||
this.sprite.stop();
|
||||
}
|
||||
if (this.scene.anims.exists('protagonist_idle')) {
|
||||
this.sprite.play('protagonist_idle');
|
||||
// Play idle animation for current direction
|
||||
const idleAnim = `protagonist_idle_${this.direction}`;
|
||||
if (this.scene.anims.exists(idleAnim)) {
|
||||
this.sprite.play(idleAnim);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore animation errors
|
||||
@@ -431,12 +458,20 @@ class Player {
|
||||
|
||||
const targetScreen = this.iso.toScreen(targetX, targetY);
|
||||
|
||||
// Play walk animation - SAFE CHECK
|
||||
if (this.sprite.texture.key === 'player_dreadlocks') {
|
||||
// Play walk animation - SAFE CHECK (updated for protagonist)
|
||||
const texKey = this.sprite.texture.key;
|
||||
|
||||
if (texKey === 'player_protagonist') {
|
||||
// KRVAVA ŽETEV: Use directional animations
|
||||
const walkAnim = `protagonist_walk_${this.direction}`;
|
||||
if (this.scene.anims.exists(walkAnim)) {
|
||||
this.sprite.play(walkAnim, true);
|
||||
}
|
||||
} else if (texKey === 'player_dreadlocks') {
|
||||
if (this.scene.anims.exists('player_dreadlocks_walk')) {
|
||||
this.sprite.play('player_dreadlocks_walk', true);
|
||||
}
|
||||
} else if (this.sprite.texture.key === 'player_walk') {
|
||||
} else if (texKey === 'player_walk') {
|
||||
if (this.scene.anims.exists('player_walk_anim')) {
|
||||
this.sprite.play('player_walk_anim', true);
|
||||
}
|
||||
@@ -452,11 +487,19 @@ class Player {
|
||||
this.isMoving = false;
|
||||
this.updatePosition();
|
||||
|
||||
// Stop animation
|
||||
if (this.sprite.texture.key === 'player_dreadlocks') {
|
||||
// Stop animation (updated for protagonist)
|
||||
if (texKey === 'player_protagonist') {
|
||||
// Play idle animation
|
||||
const idleAnim = `protagonist_idle_${this.direction}`;
|
||||
if (this.scene.anims.exists(idleAnim)) {
|
||||
this.sprite.play(idleAnim);
|
||||
} else {
|
||||
this.sprite.stop();
|
||||
}
|
||||
} else if (texKey === 'player_dreadlocks') {
|
||||
this.sprite.stop();
|
||||
this.sprite.setFrame(0);
|
||||
} else if (this.sprite.texture.key === 'player_walk') {
|
||||
} else if (texKey === 'player_walk') {
|
||||
this.sprite.stop();
|
||||
this.sprite.setFrame(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user