feat(studio): adopt the 640x360 native graphics contract
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.
This commit is contained in:
@@ -2,10 +2,11 @@ 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.
|
||||
// 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 = 238;
|
||||
declare const FIELD_BOTTOM: int = 328;
|
||||
declare const PADDLE_H: int = 36;
|
||||
declare const BALL_SIZE: int = 6;
|
||||
declare const MENU: int = 0;
|
||||
@@ -16,14 +17,14 @@ 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_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 = 948;
|
||||
declare global ball_y: int = 608;
|
||||
declare global ball_vx: int = 4;
|
||||
declare global ball_vy: int = 2;
|
||||
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;
|
||||
|
||||
@@ -39,12 +40,12 @@ fn abs_i(value: int) -> int {
|
||||
}
|
||||
|
||||
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 };
|
||||
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;
|
||||
@@ -64,27 +65,27 @@ fn init() -> void {
|
||||
}
|
||||
|
||||
fn move_player(up: bool, down: bool) -> void {
|
||||
if up && !down { player_y = player_y - 4; }
|
||||
if down && !up { player_y = player_y + 4; }
|
||||
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 = 137;
|
||||
if ball_vx > 0 && ball_x > 240 * SCALE {
|
||||
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 + 2 { cpu_y = cpu_y + 2; }
|
||||
if target < cpu_y - 2 { cpu_y = cpu_y - 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, 4, 7);
|
||||
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 / 5, -4, 4);
|
||||
ball_vy = clamp(offset * 3 / 10, -6, 6);
|
||||
if ball_vy == 0 {
|
||||
ball_vy = if (player_score + cpu_score) % 2 == 0 { -1 } else { 1 };
|
||||
}
|
||||
@@ -103,7 +104,7 @@ fn point(player_won: bool) -> void {
|
||||
}
|
||||
|
||||
fn move_ball() -> void {
|
||||
// At max speed each substep travels 1.75 px, below the paddle thickness.
|
||||
// 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;
|
||||
@@ -125,9 +126,9 @@ fn move_ball() -> void {
|
||||
bounce(player_y, 1);
|
||||
}
|
||||
}
|
||||
if ball_vx > 0 && x + BALL_SIZE >= 430 && x <= 438 {
|
||||
if ball_vx > 0 && x + BALL_SIZE >= 590 && x <= 598 {
|
||||
if y + BALL_SIZE > cpu_y && y < cpu_y + PADDLE_H {
|
||||
ball_x = (430 - BALL_SIZE) * SCALE;
|
||||
ball_x = (590 - BALL_SIZE) * SCALE;
|
||||
bounce(cpu_y, -1);
|
||||
}
|
||||
}
|
||||
@@ -136,7 +137,7 @@ fn move_ball() -> void {
|
||||
point(false);
|
||||
return;
|
||||
}
|
||||
if ball_x > 460 * SCALE {
|
||||
if ball_x > 620 * SCALE {
|
||||
point(true);
|
||||
return;
|
||||
}
|
||||
@@ -189,11 +190,11 @@ fn draw_digit(value: int, x: int, y: int, color: Color) -> void {
|
||||
}
|
||||
|
||||
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));
|
||||
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 {
|
||||
@@ -204,22 +205,22 @@ fn draw() -> void {
|
||||
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_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, 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.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(430, cpu_y + 3, 10, PADDLE_H, Color.rgb(65, 37, 46));
|
||||
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(430, cpu_y, 8, PADDLE_H, coral);
|
||||
Gfx.fill_rect(590, cpu_y, 8, PADDLE_H, coral);
|
||||
|
||||
if phase == PLAYING || phase == SERVING || phase == PAUSED {
|
||||
let x: int = ball_x / SCALE;
|
||||
@@ -232,15 +233,15 @@ fn draw() -> void {
|
||||
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);
|
||||
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(220, 111, "READY", mint);
|
||||
Gfx.draw_text(236, 128, countdown, white);
|
||||
Gfx.draw_text(190, 188, "A - SERVE NOW", muted);
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user