67 lines
1.2 KiB
Plaintext
67 lines
1.2 KiB
Plaintext
import { Color, Gfx } from "@sdk:gfx";
|
|
import { Pad, Touch } from "@sdk:input";
|
|
import { Log } from "@sdk:log";
|
|
|
|
declare struct Vec2(x: int, y: int)
|
|
[
|
|
(x: int, y: int): (x, y) as default { }
|
|
(s: int): (s, s) as square { }
|
|
]
|
|
[[
|
|
ZERO: square(0)
|
|
]]
|
|
{
|
|
fn getX(self: this): int {
|
|
return x;
|
|
}
|
|
|
|
fn getY(self: this): int {
|
|
return y;
|
|
}
|
|
}
|
|
|
|
fn add(a: int, b: int): int {
|
|
return a + b;
|
|
}
|
|
|
|
fn is_higher(a: int, b: int): bool {
|
|
let c: int = a + b;
|
|
return c >= 30;
|
|
}
|
|
|
|
fn add2(a: int, b: int): int {
|
|
let c = add(a, b);
|
|
return c;
|
|
}
|
|
|
|
fn frame(): void {
|
|
let zero = Vec2.ZERO;
|
|
let zz = add2(zero.getX(), zero.getY());
|
|
|
|
// 1. Locals & Arithmetic
|
|
let x = 10;
|
|
let y = 20;
|
|
let z = add(x, y);
|
|
|
|
// 2. Control Flow (if)
|
|
if z == 30 {
|
|
// 3. Syscall Clear
|
|
Gfx.clear(Color.GREEN);
|
|
} else {
|
|
Gfx.clear(Color.RED);
|
|
}
|
|
|
|
// 4. Input Snapshot & Nested Member Access
|
|
let pad_a = Pad.a();
|
|
let touch_f = Touch.finger();
|
|
let is_pressed = pad_a.down || touch_f.down;
|
|
if is_pressed {
|
|
Gfx.clear(Color.BLUE);
|
|
}
|
|
|
|
if Pad.b().pressed {
|
|
Log.debug("B Pressed");
|
|
Gfx.clear(Color.RED);
|
|
}
|
|
}
|