diff options
Diffstat (limited to 'test-client')
-rw-r--r-- | test-client/main.ts | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/test-client/main.ts b/test-client/main.ts index 5d3a6d11..2e14fc04 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -359,10 +359,26 @@ export function get_interact_target(): V2 | undefined { if (interacting) return interacting const me = players.get(my_id) if (!me) return - return { - x: Math.floor(me.position.x + Math.sin(me.rot)), - y: Math.floor(me.position.y + Math.cos(me.rot)) + const rx = me.position.x + Math.sin(me.rot) * 0.7 + const ry = me.position.y + Math.cos(me.rot) * 0.7 + const bx = Math.floor(rx) + const by = Math.floor(ry) + let best = { x: bx, y: by } + let best_d = 100 + for (let ox = -1; ox <= 1; ox++) for (let oy = -1; oy <= 1; oy++) { + const t = tiles.get([bx + ox, by + oy] + "") + if (!t) continue + if (data.tile_interact[t.kind]) { + const dx = rx - (bx + ox + 0.5) + const dy = ry - (by + oy + 0.5) + const d = Math.sqrt(dx * dx + dy * dy) + if (d < 1.5 && d < best_d) { + best_d = d + best = { x: bx + ox, y: by + oy } + } + } } + return best } function set_interact(edge: boolean) { |