Camera look-ahead

Point right and compare zero lead with maximum lead. Which key enters the frame while the courier stands still?
Interactive demo#TopDownHotline Miami
Shifting the camera toward a point of interest gives the player more screen space in that direction.
The dashed line marks screen centre. The courier stands on the same floor tile throughout. Aim right and the camera shifts ahead, revealing more of the room beyond the lamp. Lead sets the maximum shift in pixels.
Code
namespace camera_look_ahead_lesson;
import stage;
import std;
import math;
var body = CourierTurn {};
// Move the camera centre in the aim direction.
fn look_offset(aim: f64, lead: f64) -> f64 {
clamp(aim, -1.0, 1.0) * lead
}
export "camera-look-ahead" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
let aim = if hover { clamp((px - 80) / 50.0, -1.0, 1.0) } else { sin(time * 0.8) };
let target = if aim >= 0 { 0.0 } else { PI };
let facing = steer_courier(body, time, 160, 52, 0, 0, target);
save();
translate(-80 - look_offset(aim, number_control("lead", 30)), 0);
tiles(320, 100);
for x in [47, 107, 198, 257] {
cabinet(x, 22, 18, 13);
}
for x in [61, 91, 222, 249] {
key(x, 68, true);
}
beam(160, 52, facing, 0.55, 43);
draw_steering_courier(body);
restore();
line(80, 0, 80, 100, "#91a3b8", 1, 5);
}

Comments
No comments yet.