v0.6: Actor system (rigidbody) replaces pixel player
- New actors.rs: Rigidbody Actor with gravity, grid collision, powder displacement - Actor rendered as colored rectangle on pixel buffer (zoom-scaled) - WASM API: spawn_actor, move_actor, update_actor, actor_x/y - WASD/Arrow keys control actor, camera follows with soft lerp - displace_powders pushes sand/dirt out of actor area - Collision: stops at solids, walks through powders - Updated AGENTS.md with actor documentation
This commit is contained in:
+17
-7
@@ -99,9 +99,9 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
// === Spawn point: center on the castle ===
|
||||
engine.spawnActor(400, 550);
|
||||
camera.x = 400;
|
||||
camera.y = 630;
|
||||
camera.y = 550;
|
||||
|
||||
const rw = engine.renderWidth();
|
||||
const rh = engine.renderHeight();
|
||||
@@ -184,11 +184,21 @@ async function main() {
|
||||
);
|
||||
}
|
||||
|
||||
const speed = 200;
|
||||
if (input.isDown("KeyA") || input.isDown("ArrowLeft")) camera.x -= speed * dt;
|
||||
if (input.isDown("KeyD") || input.isDown("ArrowRight")) camera.x += speed * dt;
|
||||
if (input.isDown("KeyW") || input.isDown("ArrowUp")) camera.y -= speed * dt;
|
||||
if (input.isDown("KeyS") || input.isDown("ArrowDown")) camera.y += speed * dt;
|
||||
let mx = 0;
|
||||
let my = 0;
|
||||
if (input.isDown("KeyA") || input.isDown("ArrowLeft")) mx = -1;
|
||||
if (input.isDown("KeyD") || input.isDown("ArrowRight")) mx = 1;
|
||||
if (input.isDown("KeyW") || input.isDown("ArrowUp")) my = -1;
|
||||
engine.moveActor(mx, my);
|
||||
engine.updateActor(dt);
|
||||
|
||||
const ax = engine.actorX();
|
||||
const ay = engine.actorY();
|
||||
if (ax > 0 || ay > 0) {
|
||||
camera.x += (ax - camera.x) * 10 * dt;
|
||||
camera.y += (ay - 60 - camera.y) * 10 * dt;
|
||||
}
|
||||
|
||||
if (input.isDown("Equal")) camera.setZoom(camera.zoom + 2 * dt);
|
||||
if (input.isDown("Minus")) camera.setZoom(camera.zoom - 2 * dt);
|
||||
if (input.wheel !== 0) {
|
||||
|
||||
Reference in New Issue
Block a user