docs(0.S): the doc fences migrated by ludic migrate state; LANGUAGE.md's state section says what the tool and the checker do now; no module-level var left in the docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
19fcf60599
commit
a476ec7976
79 changed files with 481 additions and 355 deletions
|
|
@ -15,18 +15,20 @@ order: 1
|
|||
program InputExample {
|
||||
const DIRECTION_LEFT: int = 0
|
||||
const DIRECTION_RIGHT: int = 1
|
||||
var facing: int = DIRECTION_RIGHT
|
||||
|
||||
handler ReadControls phase Input {
|
||||
let pressed_key = Input.key()
|
||||
if pressed_key == 'a' { facing = DIRECTION_LEFT }
|
||||
if pressed_key == 'd' { facing = DIRECTION_RIGHT }
|
||||
state InputExampleState {
|
||||
facing: int = DIRECTION_RIGHT
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler ReadControls(input_example_st: mut InputExampleState) phase Input {
|
||||
let pressed_key = Input.key()
|
||||
if pressed_key == 'a' { input_example_st.facing = DIRECTION_LEFT }
|
||||
if pressed_key == 'd' { input_example_st.facing = DIRECTION_RIGHT }
|
||||
}
|
||||
|
||||
handler DrawWorld(input_example_st: InputExampleState) phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
var marker_x = 40
|
||||
if facing == DIRECTION_RIGHT { marker_x = 200 }
|
||||
if input_example_st.facing == DIRECTION_RIGHT { marker_x = 200 }
|
||||
Screen.fill_rectangle(x: marker_x, y: 100, width: 16, height: 16, color: Color.LimeGreen)
|
||||
Screen.show()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ program FollowCamera {
|
|||
property Position { column: int = 0, row: int = 0 }
|
||||
model Player { Position }
|
||||
|
||||
var camera_column: int = 0
|
||||
state FollowCameraState {
|
||||
camera_column: int = 0
|
||||
}
|
||||
|
||||
handler SpawnPlayer phase Start {
|
||||
spawn Player { Position { column: 12, row: 0 } }
|
||||
|
|
@ -29,8 +31,8 @@ program FollowCamera {
|
|||
|
||||
# runs after MovePlayer, so the camera sees the final position
|
||||
@Queries(these: [Position])
|
||||
handler TrackPlayer phase LateUpdate {
|
||||
camera_column = Position.column
|
||||
handler TrackPlayer(follow_camera_st: mut FollowCameraState) phase LateUpdate {
|
||||
follow_camera_st.camera_column = Position.column
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ program OverlayExample {
|
|||
model Player { Position }
|
||||
|
||||
const TILE_SIZE: int = 16
|
||||
var score: int = 0
|
||||
let score: int = 0
|
||||
|
||||
handler PlacePlayer phase Start {
|
||||
spawn Player { Position { column: 5, row: 6 } }
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ program RenderExample {
|
|||
model Player { Position }
|
||||
|
||||
const TILE_SIZE: int = 16
|
||||
var score: int = 0
|
||||
let score: int = 0
|
||||
|
||||
handler PlacePlayer phase Start {
|
||||
spawn Player { Position { column: 5, row: 6 } }
|
||||
|
|
|
|||
|
|
@ -17,18 +17,20 @@ program StartExample {
|
|||
model Player { Position }
|
||||
|
||||
const GRID_WIDTH: int = 20
|
||||
var score: int = 0
|
||||
state StartExampleState {
|
||||
score: int = 0
|
||||
}
|
||||
|
||||
handler SetUpWorld phase Start {
|
||||
handler SetUpWorld(start_example_st: mut StartExampleState) phase Start {
|
||||
Random.seed(value: 1)
|
||||
Map.size(width: GRID_WIDTH, height: 15)
|
||||
score = 0
|
||||
start_example_st.score = 0
|
||||
spawn Player { Position { column: 10, row: 7 } }
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler DrawWorld(start_example_st: StartExampleState) phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
Screen.draw_number(x: 4, y: 4, value: score, color: Color.Gold, scale: 1)
|
||||
Screen.draw_number(x: 4, y: 4, value: start_example_st.score, color: Color.Gold, scale: 1)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,24 +17,26 @@ program UpdateExample {
|
|||
model Enemy { Position }
|
||||
|
||||
const GRID_WIDTH: int = 20
|
||||
var elapsed_frames: int = 0
|
||||
var score: int = 0
|
||||
state UpdateExampleState {
|
||||
elapsed_frames: int = 0
|
||||
score: int = 0
|
||||
}
|
||||
|
||||
handler SpawnWave phase Update {
|
||||
elapsed_frames = elapsed_frames + 1
|
||||
if elapsed_frames % 30 == 0 {
|
||||
handler SpawnWave(update_example_st: mut UpdateExampleState) phase Update {
|
||||
update_example_st.elapsed_frames = update_example_st.elapsed_frames + 1
|
||||
if update_example_st.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
|
||||
update_example_st.score = update_example_st.score + 1
|
||||
}
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler DrawWorld(update_example_st: UpdateExampleState) 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.draw_number(x: 4, y: 4, value: update_example_st.score, color: Color.Gold, scale: 1)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue