rendom
This commit is contained in:
153
src/entities/Scooter.js
Normal file
153
src/entities/Scooter.js
Normal file
@@ -0,0 +1,153 @@
|
||||
class Scooter {
|
||||
constructor(scene, gridX, gridY) {
|
||||
this.scene = scene;
|
||||
this.gridX = gridX;
|
||||
this.gridY = gridY;
|
||||
this.iso = new IsometricUtils(48, 24); // Assuming global availability or import if needed, but classes usually have access if loaded.
|
||||
// Actually Scene has this.iso, better use that.
|
||||
|
||||
this.isBroken = true;
|
||||
this.isMounted = false;
|
||||
this.type = 'scooter'; // For interaction checks
|
||||
|
||||
this.createSprite();
|
||||
}
|
||||
|
||||
createSprite() {
|
||||
if (this.sprite) this.sprite.destroy();
|
||||
|
||||
const tex = this.isBroken ? 'scooter_broken' : 'scooter';
|
||||
const screenPos = this.scene.iso.toScreen(this.gridX, this.gridY);
|
||||
|
||||
this.sprite = this.scene.add.sprite(
|
||||
screenPos.x + this.scene.terrainOffsetX,
|
||||
screenPos.y + this.scene.terrainOffsetY,
|
||||
tex
|
||||
);
|
||||
this.sprite.setOrigin(0.5, 1);
|
||||
this.updateDepth();
|
||||
}
|
||||
|
||||
updateDepth() {
|
||||
if (this.sprite) {
|
||||
const layerBase = this.scene.iso.LAYER_OBJECTS || 200000;
|
||||
this.sprite.setDepth(layerBase + this.sprite.y);
|
||||
}
|
||||
}
|
||||
|
||||
interact(player) {
|
||||
if (this.isBroken) {
|
||||
this.tryFix(player);
|
||||
} else {
|
||||
this.toggleRide(player);
|
||||
}
|
||||
}
|
||||
|
||||
tryFix(player) {
|
||||
// Logic: Check if player has tools?
|
||||
// User said: "ga more popraviti" (needs to fix it).
|
||||
// Let's just require a short delay or check for 'wrench' if we had one.
|
||||
// For easter egg, let's say hitting it with a hammer works, or just interacting.
|
||||
// Let's make it simple: "Fixing Scooter..." progress.
|
||||
|
||||
console.log('🔧 Fixing Scooter...');
|
||||
this.scene.events.emit('show-floating-text', {
|
||||
x: this.sprite.x,
|
||||
y: this.sprite.y - 50,
|
||||
text: "Fixing...",
|
||||
color: '#FFFF00'
|
||||
});
|
||||
|
||||
// Plays sound
|
||||
if (this.scene.soundManager) this.scene.soundManager.playHit(); // Clank sounds
|
||||
|
||||
// Delay 2 seconds then fix
|
||||
this.scene.time.delayedCall(2000, () => {
|
||||
this.isBroken = false;
|
||||
this.createSprite(); // Update texture to shiny
|
||||
this.scene.events.emit('show-floating-text', {
|
||||
x: this.sprite.x,
|
||||
y: this.sprite.y - 50,
|
||||
text: "Scooter Fixed!",
|
||||
color: '#00FF00'
|
||||
});
|
||||
console.log('✅ Scooter Fixed!');
|
||||
});
|
||||
}
|
||||
|
||||
toggleRide(player) {
|
||||
if (this.isMounted) {
|
||||
this.dismount(player);
|
||||
} else {
|
||||
this.mount(player);
|
||||
}
|
||||
}
|
||||
|
||||
mount(player) {
|
||||
if (!player) return;
|
||||
this.isMounted = true;
|
||||
this.sprite.setVisible(false);
|
||||
|
||||
// Boost player speed
|
||||
this.originalSpeed = player.moveSpeed;
|
||||
this.originalMoveTime = player.gridMoveTime;
|
||||
|
||||
player.gridMoveTime = 100; // Faster (was 200)
|
||||
|
||||
// Attach a visual indicator to player?
|
||||
// Ideally we'd change player sprite, but we don't have 'player_scooter'.
|
||||
// We can create a "Scooter Attachment" sprite in Player, or just assume he's on it.
|
||||
// Let's update Player to have a "vehicle" property.
|
||||
player.vehicle = this;
|
||||
|
||||
this.scene.events.emit('show-floating-text', {
|
||||
x: player.sprite.x,
|
||||
y: player.sprite.y - 50,
|
||||
text: "Riding Scooter!",
|
||||
color: '#00FFFF'
|
||||
});
|
||||
}
|
||||
|
||||
dismount(player) {
|
||||
if (!player) return;
|
||||
this.isMounted = false;
|
||||
|
||||
// Reset player stats
|
||||
player.gridMoveTime = this.originalMoveTime || 200;
|
||||
player.vehicle = null;
|
||||
|
||||
// Place scooter at player's current position
|
||||
this.gridX = player.gridX;
|
||||
this.gridY = player.gridY;
|
||||
|
||||
const screenPos = this.scene.iso.toScreen(this.gridX, this.gridY);
|
||||
this.sprite.setPosition(
|
||||
screenPos.x + this.scene.terrainOffsetX,
|
||||
screenPos.y + this.scene.terrainOffsetY
|
||||
);
|
||||
this.sprite.setVisible(true);
|
||||
this.updateDepth();
|
||||
|
||||
this.scene.events.emit('show-floating-text', {
|
||||
x: player.sprite.x,
|
||||
y: player.sprite.y - 50,
|
||||
text: "Dismounted",
|
||||
color: '#CCCCCC'
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
if (this.isMounted && this.scene.player) {
|
||||
// Keep grid position synced with player for logic, even if invisible
|
||||
this.gridX = this.scene.player.gridX;
|
||||
this.gridY = this.scene.player.gridY;
|
||||
|
||||
// Also update sprite pos just in case
|
||||
const screenPos = this.scene.iso.toScreen(this.gridX, this.gridY);
|
||||
this.sprite.setPosition(
|
||||
screenPos.x + this.scene.terrainOffsetX,
|
||||
screenPos.y + this.scene.terrainOffsetY
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user