feat: player entity with WASD movement, tile collision, camera follow (Phase 4.1)
Player spawns at walkable tile near map center. WASD controls movement (150px/s, normalized diagonal). Tile collision with wall-sliding prevents walking through acid pools, crystals, geysers. Camera follows player with smooth lerp. 39 new tests (134 total). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -67,3 +67,29 @@ export function updateCamera(
|
||||
if (keys.up.isDown) camera.scrollY -= speed * dt;
|
||||
if (keys.down.isDown) camera.scrollY += speed * dt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up camera for player-follow mode.
|
||||
* No WASD movement — camera follows the player entity.
|
||||
* Zoom via mouse wheel, bounds clamped to world size.
|
||||
*/
|
||||
export function setupPlayerCamera(
|
||||
scene: Phaser.Scene,
|
||||
worldPixelWidth: number,
|
||||
worldPixelHeight: number,
|
||||
): void {
|
||||
const camera = scene.cameras.main;
|
||||
camera.setBounds(0, 0, worldPixelWidth, worldPixelHeight);
|
||||
camera.setZoom(2); // closer view for gameplay
|
||||
|
||||
// Mouse wheel zoom (0.5x – 3x)
|
||||
scene.input.on('wheel', (
|
||||
_pointer: unknown,
|
||||
_gameObjects: unknown,
|
||||
_deltaX: number,
|
||||
deltaY: number,
|
||||
) => {
|
||||
const newZoom = Phaser.Math.Clamp(camera.zoom - deltaY * 0.001, 0.5, 3);
|
||||
camera.setZoom(newZoom);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user