Skip to content

Commit 7338b44

Browse files
rjcorwinclaude
andcommitted
Fix ship visibility and player control issues
Fixed two critical issues with the ship riding implementation: Issue #1: Ship not visible - Replaced player sprite placeholder with proper ship graphics - Ship now renders as a large brown rectangle with black outline - Rectangle size matches deck boundary dimensions - Ship uses centered origin (0.5, 0.5) for proper positioning - Generated unique texture per ship from graphics Issue #2: Player wanders off ship when controlling - Added check to disable player movement when controllingShip is active - Arrow keys only control ship (steering/sails), not player movement - Player animation stops when controlling ship - Player remains stationary on deck while operating controls - Can still walk around when not actively controlling Technical changes: - Ship sprite created using Phaser.Graphics with fillRect/strokeRect - Graphics converted to texture using generateTexture() - Player movement code wrapped in !this.controllingShip check - Player animation stops in else branch when controlling Files Modified: - clients/mew-world/src/game/GameScene.ts Players can now: - See the ship as a large brown platform - Control ship without wandering off deck - Walk on deck when not controlling - Ride along smoothly as ship moves 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 4521a88 commit 7338b44

File tree

1 file changed

+54
-35
lines changed

1 file changed

+54
-35
lines changed

clients/mew-world/src/game/GameScene.ts

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,27 @@ export class GameScene extends Phaser.Scene {
334334
let ship = this.ships.get(update.participantId);
335335

336336
if (!ship) {
337-
// Create new ship
337+
// Create new ship using graphics (large visible rectangle)
338+
const shipGraphics = this.add.graphics();
339+
shipGraphics.fillStyle(0x8b4513, 1); // Brown
340+
shipGraphics.fillRect(-update.shipData.deckBoundary.width / 2, -update.shipData.deckBoundary.height / 2,
341+
update.shipData.deckBoundary.width, update.shipData.deckBoundary.height);
342+
shipGraphics.lineStyle(4, 0x000000, 1); // Black outline
343+
shipGraphics.strokeRect(-update.shipData.deckBoundary.width / 2, -update.shipData.deckBoundary.height / 2,
344+
update.shipData.deckBoundary.width, update.shipData.deckBoundary.height);
345+
shipGraphics.setPosition(update.worldCoords.x, update.worldCoords.y);
346+
347+
// Generate texture from graphics so we can use it as a sprite
348+
const key = `ship-${update.participantId}`;
349+
shipGraphics.generateTexture(key, update.shipData.deckBoundary.width, update.shipData.deckBoundary.height);
350+
shipGraphics.destroy();
351+
338352
const shipSprite = this.add.sprite(
339353
update.worldCoords.x,
340354
update.worldCoords.y,
341-
'player' // TODO: Use actual ship sprite
355+
key
342356
);
343-
shipSprite.setOrigin(0.5, 0.8);
344-
shipSprite.setTint(0x8b4513); // Brown color for ship
357+
shipSprite.setOrigin(0.5, 0.5);
345358

346359
// Create control point indicators
347360
const wheelGraphics = this.add.graphics();
@@ -403,45 +416,51 @@ export class GameScene extends Phaser.Scene {
403416
}
404417

405418
update(time: number, delta: number) {
406-
// Handle local player movement
419+
// Handle local player movement (only if not controlling ship)
407420
const velocity = new Phaser.Math.Vector2(0, 0);
408421

409-
if (this.cursors.left?.isDown) {
410-
velocity.x -= 1;
411-
}
412-
if (this.cursors.right?.isDown) {
413-
velocity.x += 1;
414-
}
415-
if (this.cursors.up?.isDown) {
416-
velocity.y -= 1;
417-
}
418-
if (this.cursors.down?.isDown) {
419-
velocity.y += 1;
420-
}
422+
// Only allow player movement if NOT currently controlling ship
423+
if (!this.controllingShip) {
424+
if (this.cursors.left?.isDown) {
425+
velocity.x -= 1;
426+
}
427+
if (this.cursors.right?.isDown) {
428+
velocity.x += 1;
429+
}
430+
if (this.cursors.up?.isDown) {
431+
velocity.y -= 1;
432+
}
433+
if (this.cursors.down?.isDown) {
434+
velocity.y += 1;
435+
}
421436

422-
// Normalize diagonal movement
423-
if (velocity.length() > 0) {
424-
velocity.normalize();
425-
velocity.scale(MOVE_SPEED * (delta / 1000));
437+
// Normalize diagonal movement
438+
if (velocity.length() > 0) {
439+
velocity.normalize();
440+
velocity.scale(MOVE_SPEED * (delta / 1000));
426441

427-
// Calculate intended new position
428-
const newX = this.localPlayer.x + velocity.x;
429-
const newY = this.localPlayer.y + velocity.y;
442+
// Calculate intended new position
443+
const newX = this.localPlayer.x + velocity.x;
444+
const newY = this.localPlayer.y + velocity.y;
430445

431-
// Check collision at new position
432-
const collision = this.checkTileCollision(newX, newY);
446+
// Check collision at new position
447+
const collision = this.checkTileCollision(newX, newY);
433448

434-
if (collision.walkable) {
435-
// Apply movement with speed modifier
436-
this.localPlayer.x += velocity.x * collision.speedModifier;
437-
this.localPlayer.y += velocity.y * collision.speedModifier;
438-
}
439-
// If not walkable, don't move (collision!)
449+
if (collision.walkable) {
450+
// Apply movement with speed modifier
451+
this.localPlayer.x += velocity.x * collision.speedModifier;
452+
this.localPlayer.y += velocity.y * collision.speedModifier;
453+
}
454+
// If not walkable, don't move (collision!)
440455

441-
// Update animation based on movement direction and store facing
442-
this.lastFacing = this.updatePlayerAnimation(this.localPlayer, velocity);
456+
// Update animation based on movement direction and store facing
457+
this.lastFacing = this.updatePlayerAnimation(this.localPlayer, velocity);
458+
} else {
459+
// Stop animation when idle
460+
this.localPlayer.anims.stop();
461+
}
443462
} else {
444-
// Stop animation when idle
463+
// Player is controlling ship - stop player animation
445464
this.localPlayer.anims.stop();
446465
}
447466

0 commit comments

Comments
 (0)