Update the new JavaFX UI's frame sizing and pointer cancellation while preserving zoom and scrolling. Adapt Pong, Fragments and the camera scene to the native viewport, and update exact visual references and IPC fixtures. Build and run all three examples against qualified installed runtimes. Observe an actual Pong paddle collision and verify native frame captures. Retain the qualification evidence generated for the tested native bundles. Validated by the complete verify and desktop integration gates, including the existing 30-second Play measurement and 20 Play/Stop cycles. Work: WRK-0016 / DEC-0001 / PLN-0001 Commit and push explicitly authorized by the user after completion.
263 lines
8.9 KiB
Plaintext
263 lines
8.9 KiB
Plaintext
import { Color } from @core:color;
|
|
import { Gfx } from @sdk:gfx;
|
|
import { Pad, Button } from @sdk:input;
|
|
|
|
// Native 640x360 arena. One logical frame is one game tick; ball uses quarter pixels.
|
|
// Speeds track the larger playfield while paddle/ball art and mechanics stay unchanged.
|
|
declare const SCALE: int = 4;
|
|
declare const FIELD_TOP: int = 72;
|
|
declare const FIELD_BOTTOM: int = 328;
|
|
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 = 182;
|
|
declare global cpu_y: int = 182;
|
|
declare global player_score: int = 0;
|
|
declare global cpu_score: int = 0;
|
|
declare global ball_x: int = 1268;
|
|
declare global ball_y: int = 788;
|
|
declare global ball_vx: int = 6;
|
|
declare global ball_vy: int = 3;
|
|
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 = 182;
|
|
cpu_y = 182;
|
|
ball_x = 317 * SCALE;
|
|
ball_y = 197 * SCALE;
|
|
ball_vx = direction * 6;
|
|
ball_vy = if (player_score + cpu_score) % 2 == 0 { 3 } else { -4 };
|
|
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 - 6; }
|
|
if down && !up { player_y = player_y + 6; }
|
|
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 = 182;
|
|
if ball_vx > 0 && ball_x > 320 * SCALE {
|
|
target = ball_y / SCALE + BALL_SIZE / 2 - PADDLE_H / 2;
|
|
}
|
|
if target > cpu_y + 3 { cpu_y = cpu_y + 3; }
|
|
if target < cpu_y - 3 { cpu_y = cpu_y - 3; }
|
|
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, 6, 10);
|
|
ball_vx = direction * speed;
|
|
let offset: int = ball_y / SCALE + BALL_SIZE / 2 - paddle_y - PADDLE_H / 2;
|
|
ball_vy = clamp(offset * 3 / 10, -6, 6);
|
|
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 2.5 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 >= 590 && x <= 598 {
|
|
if y + BALL_SIZE > cpu_y && y < cpu_y + PADDLE_H {
|
|
ball_x = (590 - BALL_SIZE) * SCALE;
|
|
bounce(cpu_y, -1);
|
|
}
|
|
}
|
|
|
|
if ball_x + BALL_SIZE * SCALE < 20 * SCALE {
|
|
point(false);
|
|
return;
|
|
}
|
|
if ball_x > 620 * 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(192, 156, 256, 90, Color.rgb(57, 81, 106), Color.rgb(12, 22, 39));
|
|
Gfx.fill_rect(192, 156, 3, 90, Color.rgb(77, 237, 205));
|
|
Gfx.draw_text(216, 170, title, Color.rgb(236, 244, 250));
|
|
Gfx.draw_text(216, 195, line_one, Color.rgb(155, 176, 198));
|
|
Gfx.draw_text(216, 219, 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(530, 17, "FIRST TO 5", muted);
|
|
Gfx.draw_text(218, 34, "YOU", mint);
|
|
Gfx.draw_text(393, 34, "CPU", coral);
|
|
draw_digit(player_score, 270, 19, mint);
|
|
draw_digit(cpu_score, 352, 19, coral);
|
|
Gfx.fill_rect(317, 28, 3, 3, muted);
|
|
Gfx.fill_rect(317, 39, 3, 3, muted);
|
|
|
|
Gfx.draw_square(20, 66, 600, 268, Color.rgb(37, 57, 79), Color.rgb(13, 23, 40));
|
|
for y: int from 76 until 328 step 13 {
|
|
Gfx.fill_rect(319, 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(590, cpu_y + 3, 10, PADDLE_H, Color.rgb(65, 37, 46));
|
|
Gfx.fill_rect(42, player_y, 8, PADDLE_H, mint);
|
|
Gfx.fill_rect(590, 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, 344, "UP / DOWN MOVE", muted);
|
|
Gfx.draw_text(504, 344, "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(300, 156, "READY", mint);
|
|
Gfx.draw_text(316, 173, countdown, white);
|
|
Gfx.draw_text(270, 233, "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();
|
|
}
|