50 lines
1 KiB
JavaScript
50 lines
1 KiB
JavaScript
function rgba(r, g, b, a) {
|
|
const buffer = Uint8Array.allocPlain(4);
|
|
buffer[0] = r;
|
|
buffer[1] = g;
|
|
buffer[2] = b;
|
|
buffer[3] = a;
|
|
return buffer;
|
|
}
|
|
|
|
const PAD_BUTTON_START = 0x1000;
|
|
const PAD_BUTTON_A = 0x0100;
|
|
const RED_COLOR = rgba(255, 0, 0, 255);
|
|
const GREEN_COLOR = rgba(0, 255, 0, 255);
|
|
|
|
function rgba_compare(rgba1, rgba2) {
|
|
return (rgba1[0] == rgba2[0]) &&
|
|
(rgba1[1] == rgba2[1]) &&
|
|
(rgba1[2] == rgba2[2]) &&
|
|
(rgba1[3] == rgba2[3]);
|
|
}
|
|
|
|
globalThis.rectangle_color = RED_COLOR;
|
|
|
|
function swap_colors() {
|
|
if (rgba_compare(rectangle_color, RED_COLOR)) {
|
|
rectangle_color = GREEN_COLOR;
|
|
} else if (rgba_compare(rectangle_color, GREEN_COLOR)) {
|
|
rectangle_color = RED_COLOR;
|
|
}
|
|
}
|
|
|
|
function start() {
|
|
}
|
|
|
|
function update() {
|
|
const pressed = wii.pad.buttons_down();
|
|
|
|
if (pressed & PAD_BUTTON_START) {
|
|
wii.print("exiting from js");
|
|
wii.exit();
|
|
}
|
|
|
|
if (pressed & PAD_BUTTON_A) {
|
|
wii.print("a pressed");
|
|
swap_colors();
|
|
}
|
|
|
|
wii.grrlib.fill_screen(rgba(255, 255, 255, 255));
|
|
wii.grrlib.rectangle(0, 0, 320, 240, rectangle_color, true);
|
|
}
|