fixed issues with Input API
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
pub declare struct Color(raw: bounded)
|
||||
[[
|
||||
BLACK: Color(0b),
|
||||
WHITE: Color(65535b),
|
||||
RED: Color(63488b),
|
||||
GREEN: Color(2016b),
|
||||
BLUE: Color(31b)
|
||||
]]
|
||||
@@ -1,12 +1,3 @@
|
||||
pub declare struct Color(raw: bounded)
|
||||
[[
|
||||
BLACK: Color(0b),
|
||||
WHITE: Color(65535b),
|
||||
RED: Color(63488b),
|
||||
GREEN: Color(2016b),
|
||||
BLUE: Color(31b)
|
||||
]]
|
||||
|
||||
pub declare contract Gfx host {
|
||||
fn clear(color: Color): void;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
pub declare struct Button(
|
||||
pressed: bool,
|
||||
released: bool,
|
||||
down: bool,
|
||||
hold_frames: bounded
|
||||
)
|
||||
@@ -1,25 +1,20 @@
|
||||
pub declare struct ButtonState(
|
||||
pressed: bool,
|
||||
released: bool,
|
||||
down: bool,
|
||||
hold_frames: bounded
|
||||
)
|
||||
pub declare contract Pad host {
|
||||
fn up(): Button;
|
||||
fn down(): Button;
|
||||
fn left(): Button;
|
||||
fn right(): Button;
|
||||
fn a(): Button;
|
||||
fn b(): Button;
|
||||
fn x(): Button;
|
||||
fn y(): Button;
|
||||
fn l(): Button;
|
||||
fn r(): Button;
|
||||
fn start(): Button;
|
||||
fn select(): Button;
|
||||
}
|
||||
|
||||
pub declare struct Pad(
|
||||
up: ButtonState,
|
||||
down: ButtonState,
|
||||
left: ButtonState,
|
||||
right: ButtonState,
|
||||
a: ButtonState,
|
||||
b: ButtonState,
|
||||
x: ButtonState,
|
||||
y: ButtonState,
|
||||
l: ButtonState,
|
||||
r: ButtonState,
|
||||
start: ButtonState,
|
||||
select: ButtonState
|
||||
)
|
||||
|
||||
pub declare contract Input host {
|
||||
fn pad(): Pad;
|
||||
pub declare contract Touch host {
|
||||
fn screen_x(): int;
|
||||
fn screen_y(): int;
|
||||
fn finger(): Button;
|
||||
}
|
||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
import { Color, Gfx } from "@sdk:gfx";
|
||||
import { Input } from "@sdk:input";
|
||||
import { Pad, Touch } from "@sdk:input";
|
||||
|
||||
declare struct Vec2(x: int, y: int)
|
||||
[
|
||||
@@ -51,8 +51,10 @@ fn frame(): void {
|
||||
}
|
||||
|
||||
// 4. Input Snapshot & Nested Member Access
|
||||
let p = Input.pad();
|
||||
if p.a.down {
|
||||
let pad = Pad.a();
|
||||
let touch = Touch.finger();
|
||||
let is_pressed = pad.down || touch.down;
|
||||
if is_pressed {
|
||||
Gfx.clear(Color.BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user