ludic/phase-update.html
2026-09-17 22:10:03 +00:00

53 lines
No EOL
2.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Update — Ludic</title>
<meta name="description" content="The ordinary per-frame game-logic step, run after Input and FixedUpdate.">
<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="api.html#phases">Phases</a> <span>›</span> <span class="here">Update</span></div>
<div class="item-head">
<span class="kind-badge kind-phase">phase</span>
<h1 id="top">Update</h1>
</div>
<code class="sig">phase Update</code>
<div class="desc"><p><code>Update</code> is the everyday game-logic phase, run each frame after <code>Input</code> and <code>FixedUpdate</code> and before <code>LateUpdate</code> and <code>Render</code>. It is where most gameplay lives when you are not being strict about determinism: spawn waves on a timer, apply the intent that <code>Input</code> recorded, check win/lose conditions, advance animations. Reach for <code>Update</code> by default and reserve <code>FixedUpdate</code> for the simulation you specifically want reproducible. Because it runs after <code>Input</code>, the current frame's key press is already reflected in your program <code>var</code>s by the time <code>Update</code> reads them.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program UpdateExample {
property Position { column: int = 0, row: int = 0 }
model Enemy { Position }
const GRID_WIDTH: int = 20
var elapsed_frames: int = 0
var score: int = 0
handler SpawnWave phase Update {
elapsed_frames = elapsed_frames + 1
if elapsed_frames % 30 == 0 {
let spawn_column = Random.range(low: 0, high: GRID_WIDTH - 1)
spawn Enemy { Position { column: spawn_column, row: 0 } }
score = score + 1
}
}
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
for (current_position) in query [Position, {Enemy}] {
Screen.fill_rectangle(x: current_position.column * 16, y: current_position.row * 16, width: 16, height: 16, color: Color.Crimson)
}
Screen.draw_number(x: 4, y: 4, value: score, color: Color.Gold, scale: 1)
Screen.show()
}
}</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>