diff --git a/test-projects/fragments/.gitignore b/test-projects/fragments/.gitignore index eac60a76..40082061 100644 --- a/test-projects/fragments/.gitignore +++ b/test-projects/fragments/.gitignore @@ -14,3 +14,6 @@ Desktop.ini # Linux / Unix desktop metadata .directory *~ +/.codex/config.toml +/.studio/mcp/ +/assets/.prometeu/cache.json diff --git a/test-projects/fragments/README.md b/test-projects/fragments/README.md new file mode 100644 index 00000000..4221c0fa --- /dev/null +++ b/test-projects/fragments/README.md @@ -0,0 +1,15 @@ +# Fragments + +A procedural fractal/cloud effect with moving stars. Open the project in Studio, +build with Shipper and use Debug Play. The sample keeps its original logical +320×180 field and 8-pixel cells; the host framebuffer is 480×270. + +The effect's palette formulas produce RGB565 values. `rgb565()` explicitly expands +the 5/6/5-bit channels into the current RGBA8888 Color representation. No image +assets or controls are needed. + +`./run.sh` launches the current `build/` directory after a successful Studio build. +It reads `.studio/setup.json`, accepts `PROMETEU_RUNTIME` as an explicit override, +and uses the existing local `runtime` symlink only if no runtime was configured. +Python 3 is required by this convenience launcher. Historical `cartridge/` binaries +are preserved and are not used by this launcher. diff --git a/test-projects/fragments/prometeu.json b/test-projects/fragments/prometeu.json index 535eb3d0..93b11de4 100644 --- a/test-projects/fragments/prometeu.json +++ b/test-projects/fragments/prometeu.json @@ -1,9 +1,9 @@ { - "name": "fragments", - "version": "1.0.0", - "language": "pbs", - "stdlib": "1", - "target": "Game", - "dependencies": [ - ] -} + "name" : "fragments", + "version" : "1.0.0", + "language" : "pbs", + "stdlib" : "1", + "target" : "Game", + "dependencies" : [ ], + "app_id" : 477476525 +} \ No newline at end of file diff --git a/test-projects/fragments/run.sh b/test-projects/fragments/run.sh index 87315da6..ae3d1dce 100755 --- a/test-projects/fragments/run.sh +++ b/test-projects/fragments/run.sh @@ -1,7 +1,35 @@ -#!/bin/zsh +#!/bin/sh +set -eu -set -e +PROJECT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +for artifact in program.pbx manifest.json assets.pa; do + if [ ! -f "$PROJECT_DIR/build/$artifact" ]; then + printf '%s\n' "Build this project in Studio Shipper before running it." >&2 + exit 1 + fi +done -cp build/assets.pa cartridge -cp build/program.pbx cartridge -./runtime/prometeu run cartridge \ No newline at end of file +RUNTIME_PATH=${PROMETEU_RUNTIME:-} +if [ -z "$RUNTIME_PATH" ]; then + RUNTIME_PATH=$(python3 - "$PROJECT_DIR" <<'CONFIG_PY' +import json,sys +from pathlib import Path +root=Path(sys.argv[1]) +setup=root/'.studio/setup.json' +try: + value=json.loads(setup.read_text()).get('prometeuRuntimePath') if setup.exists() else None +except (ValueError,OSError) as error: + raise SystemExit('Cannot read project runtime configuration: '+str(error)) +print(value or root/'runtime') +CONFIG_PY + ) +fi +case "$RUNTIME_PATH" in + /*) ;; + *) RUNTIME_PATH="$PROJECT_DIR/$RUNTIME_PATH" ;; +esac +if [ ! -x "$RUNTIME_PATH/prometeu" ]; then + printf '%s\n' "Runtime not found: $RUNTIME_PATH/prometeu" "Select it in Studio or set PROMETEU_RUNTIME to its installation directory." >&2 + exit 1 +fi +exec "$RUNTIME_PATH/prometeu" run "$PROJECT_DIR/build" diff --git a/test-projects/fragments/src/main.pbs b/test-projects/fragments/src/main.pbs index ea29bd7c..ade7427f 100644 --- a/test-projects/fragments/src/main.pbs +++ b/test-projects/fragments/src/main.pbs @@ -20,6 +20,15 @@ fn abs_i(v: int) -> int return v; } +// The effect's palette arithmetic is RGB565. Current Color values are RGBA8888. +fn rgb565(value: int) -> Color +{ + let r: long = ((value / 2048) % 32) as long; + let g: long = ((value / 32) % 64) as long; + let b: long = (value % 32) as long; + return Color.rgb(r * 255 / 31, g * 255 / 63, b * 255 / 31); +} + [Frame] fn frame() -> void { @@ -28,7 +37,7 @@ fn frame() -> void let cy : int = SCREEN_H / 2; let phase : int = ticks / 2; - Gfx.clear(new Color(33)); + Gfx.clear(rgb565(33)); for y: int from 0 until SCREEN_H step CELL { let dy : int = y - cy; @@ -84,7 +93,7 @@ fn frame() -> void }; let color_raw : int = r * 2048 + g * 32 + b; - Gfx.fill_rect(x, y, CELL, CELL, new Color(color_raw)); + Gfx.fill_rect(x, y, CELL, CELL, rgb565(color_raw)); } } @@ -123,13 +132,12 @@ fn frame() -> void let star_c4 : int = 40159 + twinkle4 * 1696; let star_c5 : int = 52831 + twinkle5 * 992; - Gfx.fill_rect(star_a, star_y0, star_s0, star_s0, new Color(star_c0)); - Gfx.fill_rect(star_b, star_y1, star_s1, star_s1, new Color(star_c1)); - Gfx.fill_rect(star_c, star_y2, star_s2, star_s2, new Color(star_c2)); - Gfx.fill_rect(star_d, star_y3, star_s3, star_s3, new Color(star_c3)); - Gfx.fill_rect(star_e, star_y4, star_s4, star_s4, new Color(star_c4)); - Gfx.fill_rect(star_f, star_y5, star_s5, star_s5, new Color(star_c5)); + Gfx.fill_rect(star_a, star_y0, star_s0, star_s0, rgb565(star_c0)); + Gfx.fill_rect(star_b, star_y1, star_s1, star_s1, rgb565(star_c1)); + Gfx.fill_rect(star_c, star_y2, star_s2, star_s2, rgb565(star_c2)); + Gfx.fill_rect(star_d, star_y3, star_s3, star_s3, rgb565(star_c3)); + Gfx.fill_rect(star_e, star_y4, star_s4, star_s4, rgb565(star_c4)); + Gfx.fill_rect(star_f, star_y5, star_s5, star_s5, rgb565(star_c5)); - //Gfx.clear(new Color(33)); } // Estimated frame cost: ~920 fills + ~2760 fractal-iteration steps + 6 twinkling parallax stars/frame at CELL=8. diff --git a/test-projects/main/.gitignore b/test-projects/main/.gitignore index eac60a76..40082061 100644 --- a/test-projects/main/.gitignore +++ b/test-projects/main/.gitignore @@ -14,3 +14,6 @@ Desktop.ini # Linux / Unix desktop metadata .directory *~ +/.codex/config.toml +/.studio/mcp/ +/assets/.prometeu/cache.json diff --git a/test-projects/main/README.md b/test-projects/main/README.md new file mode 100644 index 00000000..d3e67097 --- /dev/null +++ b/test-projects/main/README.md @@ -0,0 +1,18 @@ +# Scene and touch demo + +Open this folder in Studio, build with Shipper and use Debug Play. The project +uses the current Pad/Button and Touch input APIs and the existing Composer API. +Touch advances the Link frames; releasing resets them. The camera pans through +the scene. A/B/X demonstrate the log levels. + +Packer preloads Zelda3 into glyph slot 0, tileset into glyph slot 1 and tiled2 +into scene slot 0. The scene is bound from Frame, after preloads complete. +The old missing `ui/atlas2` registration and empty sound bank are retained with +`included_in_build: false`; they are not required by this demo. Their identities +are preserved for future repair/removal through the Assets workspace. + +`./run.sh` launches the current `build/` directory after a successful Studio build. +It reads the selected runtime from `.studio/setup.json`; `PROMETEU_RUNTIME` can +supply an explicit installation override. If no runtime is configured, the existing +local `runtime` symlink is used. Python 3 is required by this convenience launcher. +The tracked historical `cartridge/` binaries are not rebuilt or used by the launcher. diff --git a/test-projects/main/assets/.prometeu/index.json b/test-projects/main/assets/.prometeu/index.json index aadb8c18..f54cd26c 100644 --- a/test-projects/main/assets/.prometeu/index.json +++ b/test-projects/main/assets/.prometeu/index.json @@ -5,12 +5,12 @@ "asset_id" : 3, "asset_uuid" : "21953cb8-4101-4790-9e5e-d95f5fbc9b5a", "root" : "ui/atlas2", - "included_in_build" : true + "included_in_build" : false }, { "asset_id" : 8, "asset_uuid" : "9a7386e7-6f0e-4e4c-9919-0de71e0b7031", "root" : "ui/sound", - "included_in_build" : true + "included_in_build" : false }, { "asset_id" : 15, "asset_uuid" : "87396aab-337e-479e-b1f4-ec296678389e", diff --git a/test-projects/main/prometeu.json b/test-projects/main/prometeu.json index f8b4a30c..14028c2f 100644 --- a/test-projects/main/prometeu.json +++ b/test-projects/main/prometeu.json @@ -1,9 +1,9 @@ { - "name": "main test project", - "version": "1.0.0", - "language": "pbs", - "stdlib": "1", - "target": "Game", - "dependencies": [ - ] -} + "name" : "main test project", + "version" : "1.0.0", + "language" : "pbs", + "stdlib" : "1", + "target" : "Game", + "dependencies" : [ ], + "app_id" : 377753220 +} \ No newline at end of file diff --git a/test-projects/main/run.sh b/test-projects/main/run.sh index df4ac3c5..ae3d1dce 100755 --- a/test-projects/main/run.sh +++ b/test-projects/main/run.sh @@ -1,5 +1,35 @@ -#!/bin/zsh +#!/bin/sh +set -eu -set -e +PROJECT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +for artifact in program.pbx manifest.json assets.pa; do + if [ ! -f "$PROJECT_DIR/build/$artifact" ]; then + printf '%s\n' "Build this project in Studio Shipper before running it." >&2 + exit 1 + fi +done -./runtime/prometeu run build +RUNTIME_PATH=${PROMETEU_RUNTIME:-} +if [ -z "$RUNTIME_PATH" ]; then + RUNTIME_PATH=$(python3 - "$PROJECT_DIR" <<'CONFIG_PY' +import json,sys +from pathlib import Path +root=Path(sys.argv[1]) +setup=root/'.studio/setup.json' +try: + value=json.loads(setup.read_text()).get('prometeuRuntimePath') if setup.exists() else None +except (ValueError,OSError) as error: + raise SystemExit('Cannot read project runtime configuration: '+str(error)) +print(value or root/'runtime') +CONFIG_PY + ) +fi +case "$RUNTIME_PATH" in + /*) ;; + *) RUNTIME_PATH="$PROJECT_DIR/$RUNTIME_PATH" ;; +esac +if [ ! -x "$RUNTIME_PATH/prometeu" ]; then + printf '%s\n' "Runtime not found: $RUNTIME_PATH/prometeu" "Select it in Studio or set PROMETEU_RUNTIME to its installation directory." >&2 + exit 1 +fi +exec "$RUNTIME_PATH/prometeu" run "$PROJECT_DIR/build" diff --git a/test-projects/main/src/main.pbs b/test-projects/main/src/main.pbs index 126d9b47..b620c1db 100644 --- a/test-projects/main/src/main.pbs +++ b/test-projects/main/src/main.pbs @@ -1,11 +1,10 @@ import { Log } from @sdk:log; import { Pad, Button, Touch } from @sdk:input; import { Composer } from @sdk:composer; -import { Gfx } from @sdk:gfx; -import { Assets } from @sdk:asset; -declare global loading_handle: int = -1; -declare global loading_status: int = -1; +// Preloaded by Packer: Zelda3 -> glyph slot 0, tileset -> glyph slot 1, +// tiled2 -> scene slot 0. No separate atlas load is needed. +declare global scene_bound: bool = false; declare global frame_counter: int = 0; declare global tile_id: int = 0; declare global camera_x: int = 0; @@ -13,49 +12,28 @@ declare global camera_mult: int = 1; declare const MAX_FRAMES: int = 4; declare const CAMERA_SPEED: int = 1; -declare struct Bla (a: int) {} - [Init] fn init() -> void { - loading_handle= -1; - loading_status = -1; + scene_bound = false; frame_counter = 0; tile_id = 0; camera_x = 0; camera_mult = 1; - Composer.bind_scene(0); - let bla: Bla = new Bla(1); } [Frame] fn frame() -> void { - if (loading_handle == -1) { - let t : (status: int, loading_handle: int) = Assets.load(assets.ui.atlas2, 3); - if (t.status != 0) { - Log.failure("load failed"); - } else { - loading_handle = t.loading_handle; - Log.info("state: loading"); - } - } else { - let s : int = Assets.status(loading_handle); - if (s == 2) { - let commit_status : int = Assets.commit(loading_handle); - if (commit_status != 0) { - Log.failure("commit failed"); - } - } else if (s == 3) { - let sprite_status : int = Composer.emit_sprite(0, 0, 150, 150, 1, 3, false, false, 1); - if (sprite_status != 0) { - Log.failure("emit_sprite failed"); - } - } else { - Log.info("state: waiting"); - } - } - + // Composer operations run during Frame, after preloads have completed. + if (!scene_bound) { + let status: int = Composer.bind_scene(0); + if (status != 0) { + Log.failure("Unable to bind the preloaded scene"); + return; + } + scene_bound = true; + } if (Touch.released()) { @@ -82,8 +60,6 @@ fn frame() -> void { camera_mult = -1 * camera_mult; } - Log.info("camera_x:" + camera_x); - Composer.set_camera(camera_x, 0); Composer.emit_sprite(tile_id, 0, (Touch.x() as int) - 16, (Touch.y() as int) + 8, 2, 0, true, false, 0); diff --git a/test-projects/pong/.gitignore b/test-projects/pong/.gitignore new file mode 100644 index 00000000..cf304ac7 --- /dev/null +++ b/test-projects/pong/.gitignore @@ -0,0 +1,14 @@ +.studio/ +.workspace/ +build/ + +.DS_Store +.AppleDouble +.LSOverride +Thumbs.db +Desktop.ini +.directory +*~ +/.codex/config.toml +/.studio/mcp/ +/assets/.prometeu/cache.json diff --git a/test-projects/pong/README.md b/test-projects/pong/README.md new file mode 100644 index 00000000..99aad9ad --- /dev/null +++ b/test-projects/pong/README.md @@ -0,0 +1,35 @@ +# Pong + +A small single-player Pong for Prometeu, written in PBS. You are the mint paddle +on the left; the CPU is coral on the right. First to five points wins. + +## Play through Studio + +Open this project in Prometeu Studio, select your runtime installation in the +project settings, build in Shipper and use Debug Play. The same saved sources +can be built and played through the project's DEV/MCP integration. + +| Control | Action | +| --- | --- | +| Up / Down | Move your paddle; opposing directions cancel | +| A / Start | Start a match, skip the serve countdown or play again | +| Start / B during a rally | Pause | +| A / Start while paused | Resume the same rally | +| B while paused or after a match | Return to the main menu | + +These are logical gamepad buttons; the desktop host supplies their keyboard or +controller bindings. Use the edge of your paddle to change the return angle. +The CPU moves more slowly and starts tracking when the ball enters its half. + +## Source + +`src/main.pbs` separates input, state transitions, simulation and rendering. +The game uses a fixed 480×270 field, quarter-pixel integer coordinates and four +small simulation substeps per logical frame. Ball speed is capped so it cannot +jump through a paddle. It uses the existing `@sdk:input`, `@sdk:gfx` and +`@core:color` modules; no external art, audio, save system or engine changes are +required for this first version. Every new match clears scores and positions. + +Studio owns `build/`, local `.studio/` settings and the assistant connection. +Keep those generated/local files out of version control. This initial game is +the first incremental result of AGD-0088, not the full platform qualification. diff --git a/test-projects/pong/assets/.prometeu/index.json b/test-projects/pong/assets/.prometeu/index.json new file mode 100644 index 00000000..184e1c08 --- /dev/null +++ b/test-projects/pong/assets/.prometeu/index.json @@ -0,0 +1,5 @@ +{ + "schema_version" : 1, + "next_asset_id" : 1, + "assets" : [ ] +} \ No newline at end of file diff --git a/test-projects/pong/prometeu.json b/test-projects/pong/prometeu.json new file mode 100644 index 00000000..8414f369 --- /dev/null +++ b/test-projects/pong/prometeu.json @@ -0,0 +1,9 @@ +{ + "name": "pong", + "version": "1.0.0", + "language": "pbs", + "stdlib": "1", + "target": "Game", + "app_id": 1508740446, + "dependencies": [] +} diff --git a/test-projects/pong/src/main.pbs b/test-projects/pong/src/main.pbs new file mode 100644 index 00000000..c07bfbc9 --- /dev/null +++ b/test-projects/pong/src/main.pbs @@ -0,0 +1,261 @@ +import { Color } from @core:color; +import { Gfx } from @sdk:gfx; +import { Pad, Button } from @sdk:input; + +// One logical frame is one game tick. Ball coordinates use quarter pixels. +declare const SCALE: int = 4; +declare const FIELD_TOP: int = 72; +declare const FIELD_BOTTOM: int = 238; +declare const PADDLE_H: int = 36; +declare const BALL_SIZE: int = 6; +declare const MENU: int = 0; +declare const SERVING: int = 1; +declare const PLAYING: int = 2; +declare const PAUSED: int = 3; +declare const FINISHED: int = 4; + +declare global phase: int = 0; +declare global resume_phase: int = 0; +declare global player_y: int = 137; +declare global cpu_y: int = 137; +declare global player_score: int = 0; +declare global cpu_score: int = 0; +declare global ball_x: int = 948; +declare global ball_y: int = 608; +declare global ball_vx: int = 4; +declare global ball_vy: int = 2; +declare global serve_ticks: int = 60; +declare global hit_flash: int = 0; + +fn clamp(value: int, low: int, high: int) -> int { + if value < low { return low; } + if value > high { return high; } + return value; +} + +fn abs_i(value: int) -> int { + if value < 0 { return -value; } + return value; +} + +fn prepare_serve(direction: int) -> void { + player_y = 137; + cpu_y = 137; + ball_x = 237 * SCALE; + ball_y = 152 * SCALE; + ball_vx = direction * 4; + ball_vy = if (player_score + cpu_score) % 2 == 0 { 2 } else { -3 }; + serve_ticks = 60; + hit_flash = 0; + phase = SERVING; +} + +fn new_match() -> void { + player_score = 0; + cpu_score = 0; + prepare_serve(1); +} + +[Init] +fn init() -> void { + new_match(); + phase = MENU; + resume_phase = MENU; +} + +fn move_player(up: bool, down: bool) -> void { + if up && !down { player_y = player_y - 4; } + if down && !up { player_y = player_y + 4; } + player_y = clamp(player_y, FIELD_TOP, FIELD_BOTTOM - PADDLE_H); +} + +fn move_cpu() -> void { + // The CPU reacts only in its half and is slower than the human paddle. + let target: int = 137; + if ball_vx > 0 && ball_x > 240 * SCALE { + target = ball_y / SCALE + BALL_SIZE / 2 - PADDLE_H / 2; + } + if target > cpu_y + 2 { cpu_y = cpu_y + 2; } + if target < cpu_y - 2 { cpu_y = cpu_y - 2; } + cpu_y = clamp(cpu_y, FIELD_TOP, FIELD_BOTTOM - PADDLE_H); +} + +fn bounce(paddle_y: int, direction: int) -> void { + let speed: int = clamp(abs_i(ball_vx) + 1, 4, 7); + ball_vx = direction * speed; + let offset: int = ball_y / SCALE + BALL_SIZE / 2 - paddle_y - PADDLE_H / 2; + ball_vy = clamp(offset / 5, -4, 4); + if ball_vy == 0 { + ball_vy = if (player_score + cpu_score) % 2 == 0 { -1 } else { 1 }; + } + hit_flash = 6; +} + +fn point(player_won: bool) -> void { + if player_won { player_score = player_score + 1; } + else { cpu_score = cpu_score + 1; } + if player_score == 5 || cpu_score == 5 { + phase = FINISHED; + return; + } + // The next ball travels toward the side that lost the point. + prepare_serve(if player_won { 1 } else { -1 }); +} + +fn move_ball() -> void { + // At max speed each substep travels 1.75 px, below the paddle thickness. + for substep: int from 0 until 4 { + ball_x = ball_x + ball_vx; + ball_y = ball_y + ball_vy; + + if ball_y < FIELD_TOP * SCALE { + ball_y = FIELD_TOP * SCALE; + ball_vy = abs_i(ball_vy); + } + if ball_y > (FIELD_BOTTOM - BALL_SIZE) * SCALE { + ball_y = (FIELD_BOTTOM - BALL_SIZE) * SCALE; + ball_vy = -abs_i(ball_vy); + } + + let x: int = ball_x / SCALE; + let y: int = ball_y / SCALE; + if ball_vx < 0 && x <= 50 && x + BALL_SIZE >= 42 { + if y + BALL_SIZE > player_y && y < player_y + PADDLE_H { + ball_x = 50 * SCALE; + bounce(player_y, 1); + } + } + if ball_vx > 0 && x + BALL_SIZE >= 430 && x <= 438 { + if y + BALL_SIZE > cpu_y && y < cpu_y + PADDLE_H { + ball_x = (430 - BALL_SIZE) * SCALE; + bounce(cpu_y, -1); + } + } + + if ball_x + BALL_SIZE * SCALE < 20 * SCALE { + point(false); + return; + } + if ball_x > 460 * SCALE { + point(true); + return; + } + } +} + +fn update(up: bool, down: bool, confirm: bool, start: bool, back: bool) -> void { + // Exactly one state branch runs per frame, including on input edges. + if phase == MENU { + if confirm || start { new_match(); } + return; + } + if phase == FINISHED { + if back { phase = MENU; } + else if confirm || start { new_match(); } + return; + } + if phase == PAUSED { + if back { phase = MENU; } + else if confirm || start { phase = resume_phase; } + return; + } + if phase == SERVING { + if back { resume_phase = SERVING; phase = PAUSED; return; } + move_player(up, down); + serve_ticks = serve_ticks - 1; + if confirm || start || serve_ticks <= 0 { phase = PLAYING; } + return; + } + if start || back { + resume_phase = PLAYING; + phase = PAUSED; + return; + } + move_player(up, down); + move_cpu(); + if hit_flash > 0 { hit_flash = hit_flash - 1; } + move_ball(); +} + +fn draw_digit(value: int, x: int, y: int, color: Color) -> void { + // Seven-segment score display. A match never needs digits above five. + if value != 1 && value != 4 { Gfx.fill_rect(x + 3, y, 12, 3, color); } + if value != 0 && value != 1 { Gfx.fill_rect(x + 3, y + 13, 12, 3, color); } + if value != 1 && value != 4 { Gfx.fill_rect(x + 3, y + 26, 12, 3, color); } + if value == 0 || value == 4 || value == 5 { Gfx.fill_rect(x, y + 3, 3, 10, color); } + if value != 5 { Gfx.fill_rect(x + 15, y + 3, 3, 10, color); } + if value == 0 || value == 2 { Gfx.fill_rect(x, y + 16, 3, 10, color); } + if value != 2 { Gfx.fill_rect(x + 15, y + 16, 3, 10, color); } +} + +fn draw_overlay(title: str, line_one: str, line_two: str) -> void { + Gfx.draw_square(112, 111, 256, 90, Color.rgb(57, 81, 106), Color.rgb(12, 22, 39)); + Gfx.fill_rect(112, 111, 3, 90, Color.rgb(77, 237, 205)); + Gfx.draw_text(136, 125, title, Color.rgb(236, 244, 250)); + Gfx.draw_text(136, 150, line_one, Color.rgb(155, 176, 198)); + Gfx.draw_text(136, 174, line_two, Color.rgb(77, 237, 205)); +} + +fn draw() -> void { + let white = Color.rgb(236, 244, 250); + let muted = Color.rgb(110, 135, 162); + let mint = Color.rgb(77, 237, 205); + let coral = Color.rgb(255, 132, 119); + Gfx.clear(Color.rgb(7, 14, 26)); + Gfx.draw_text(24, 17, "PONG", white); + Gfx.draw_text(24, 32, "PROMETEU", muted); + Gfx.draw_text(370, 17, "FIRST TO 5", muted); + Gfx.draw_text(138, 34, "YOU", mint); + Gfx.draw_text(313, 34, "CPU", coral); + draw_digit(player_score, 190, 19, mint); + draw_digit(cpu_score, 272, 19, coral); + Gfx.fill_rect(237, 28, 3, 3, muted); + Gfx.fill_rect(237, 39, 3, 3, muted); + + Gfx.draw_square(20, 66, 440, 178, Color.rgb(37, 57, 79), Color.rgb(13, 23, 40)); + for y: int from 76 until 238 step 13 { + Gfx.fill_rect(239, y, 2, 6, Color.rgb(43, 61, 82)); + } + Gfx.fill_rect(40, player_y + 3, 10, PADDLE_H, Color.rgb(20, 58, 60)); + Gfx.fill_rect(430, cpu_y + 3, 10, PADDLE_H, Color.rgb(65, 37, 46)); + Gfx.fill_rect(42, player_y, 8, PADDLE_H, mint); + Gfx.fill_rect(430, cpu_y, 8, PADDLE_H, coral); + + if phase == PLAYING || phase == SERVING || phase == PAUSED { + let x: int = ball_x / SCALE; + let y: int = ball_y / SCALE; + if phase == PLAYING { + Gfx.fill_rect(x - ball_vx * 2, y - ball_vy * 2, BALL_SIZE, BALL_SIZE, Color.rgb(28, 45, 66)); + Gfx.fill_rect(x - ball_vx, y - ball_vy, BALL_SIZE, BALL_SIZE, Color.rgb(64, 89, 114)); + } + Gfx.fill_rect(x, y, BALL_SIZE, BALL_SIZE, white); + if hit_flash > 0 { Gfx.draw_square(x - 2, y - 2, 10, 10, mint, white); } + } + + Gfx.draw_text(24, 254, "UP / DOWN MOVE", muted); + Gfx.draw_text(344, 254, "START PAUSE", muted); + if phase == MENU { + draw_overlay("LET'S PLAY PONG", "YOU VS CPU / FIRST TO 5", "A / START - PLAY"); + } else if phase == SERVING { + let countdown = if serve_ticks > 40 { "3" } else if serve_ticks > 20 { "2" } else { "1" }; + Gfx.draw_text(220, 111, "READY", mint); + Gfx.draw_text(236, 128, countdown, white); + Gfx.draw_text(190, 188, "A - SERVE NOW", muted); + } else if phase == PAUSED { + draw_overlay("PAUSED", "A / START - RESUME", "B - MAIN MENU"); + } else if phase == FINISHED { + let title = if player_score == 5 { "YOU WIN!" } else { "CPU WINS THIS MATCH" }; + draw_overlay(title, "A / START - PLAY AGAIN", "B - MAIN MENU"); + } +} + +[Frame] +fn frame() -> void { + let up = Pad.down(Button.Up); + let down = Pad.down(Button.Down); + let confirm = Pad.pressed(Button.A); + let start = Pad.pressed(Button.Start); + let back = Pad.pressed(Button.B); + update(up, down, confirm, start, back); + draw(); +} diff --git a/test-projects/pong/src/mod.barrel b/test-projects/pong/src/mod.barrel new file mode 100644 index 00000000..7c7443f6 --- /dev/null +++ b/test-projects/pong/src/mod.barrel @@ -0,0 +1,2 @@ +pub fn init() -> void; +pub fn frame() -> void;