WiiDuktape/source/game.js

51 lines
1 KiB
JavaScript
Raw Normal View History

2024-06-20 06:37:41 +00:00
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;
2024-06-20 06:37:41 +00:00
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");
2024-06-20 06:37:41 +00:00
swap_colors();
}
2024-06-20 06:37:41 +00:00
wii.grrlib.fill_screen(rgba(255, 255, 255, 255));
wii.grrlib.rectangle(0, 0, 320, 240, rectangle_color, true);
}