42 lines
No EOL
3 KiB
HTML
42 lines
No EOL
3 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Query.within — Ludic</title>
|
||
<meta name="description" content="Every bearer of prop inside a radius of a point.">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="ns-query.html">Query</a> <span>›</span> <span class="here">Query.within</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-method">method</span>
|
||
<h1 id="top">Query.within</h1>
|
||
</div>
|
||
<code class="sig">Query.within(prop, pos, x, y, radius, x_field, y_field) -> []int</code>
|
||
<div class="desc"><p>Returns the live entities carrying <code>prop</code> whose position is within <code>radius</code> of <code>(x, y)</code>, as a <code>[]int</code> of entity ids in ascending id order — index it with <code>len</code> / <code>[i]</code>. Position is read from property <code>pos</code> at <code>x_field</code>/<code>y_field</code>, exactly as in <a href="query-nearest"><code>Query.nearest</code></a>. The boundary is inclusive (distance <code><= radius</code>), measured by exact integer distance. Use it for area-of-effect damage, proximity triggers, flocking neighbours, or "what's near the cursor".</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-prop"><code class="pname">prop</code><span class="pdesc">the property that filters which entities are considered</span></div><div class="param" id="param-pos"><code class="pname">pos</code><span class="pdesc">the property holding the coordinates</span></div><div class="param" id="param-radius"><code class="pname">radius</code><span class="pdesc">the inclusive radius</span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Demo {
|
||
property Position { col: int = 0, row: int = 0 }
|
||
property Unit { hp: int = 0 }
|
||
model Soldier { Position, Unit }
|
||
entry {
|
||
spawn Soldier { Position { col: 1, row: 1 }, Unit { hp: 5 } }
|
||
spawn Soldier { Position { col: 8, row: 8 }, Unit { hp: 5 } }
|
||
let U = World.prop_id("Unit")
|
||
let P = World.prop_id("Position")
|
||
let cx = World.field_id(P, "col")
|
||
let cy = World.field_id(P, "row")
|
||
let hit = Query.within(U, P, 0, 0, 3, cx, cy) # just the (1,1) soldier
|
||
print(len(hit)) # 1
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |