WiiDuktape/source/game.js
Fries 3362687710 get the bird to draw.
the bird now draws! i also got a font loaded too.
2024-06-21 00:45:28 -07:00

70 lines
1.6 KiB
JavaScript

/**
* returns an RGBA buffer
* @param {number} r red
* @param {number} g green
* @param {number} b blue
* @param {number} a alpha
* @returns {RGBA}
*/
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);
const WHITE_COLOR = rgba(255, 255, 255, 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;
/** @type {GRRLibTexture} */
globalThis.background = null;
/** @type {GRRLibTexture} */
globalThis.bird = null;
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() {
const background = wii.get_file("background-day.png");
const bird = wii.get_file("yellowbird-midflap.png");
globalThis.background = wii.grrlib.load_texture(background);
globalThis.bird = wii.grrlib.load_texture(bird);
}
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(WHITE_COLOR);
wii.grrlib.draw_img(0, 0, background, 0, 1, 1, WHITE_COLOR);
wii.grrlib.draw_img(0, 0, bird, 0, 1, 1, WHITE_COLOR);
}