diff --git a/source/game.js b/source/game.js index 5486f29..6e643e1 100644 --- a/source/game.js +++ b/source/game.js @@ -86,34 +86,29 @@ function update_bird() { wii.grrlib.draw_img(0, bird.position, nonNull(bird.texture), 0, 1, 1, WHITE_COLOR); } -function create_pipe() { +function Pipe() { const top_max = 200; const top_y = random_range(0, top_max); wii.grrlib.draw_img(100, -top_y, nonNull(pipe_flipped), 0, 1, 1, WHITE_COLOR); wii.grrlib.draw_img(100, top_y + 400, nonNull(pipe), 0, 1, 1, WHITE_COLOR); - return { - top_y: -top_y, - bottom_y: -top_y + 400, - position: 650, - time_active: 0 - } + this.top_y = -top_y + this.bottom_y = -top_y + 400 + this.position = 650 + this.time_active = 0 } -/** - * @param {Pipe} pipe - */ -function update_pipe(pipe) { - if (pipe.time_active >= PIPE_MAX_TIME) { - const index = pipes.indexOf(pipe); +Pipe.prototype.update = function () { + if (this.time_active >= PIPE_MAX_TIME) { + const index = pipes.indexOf(this); pipes.splice(index, -1); return; } - wii.grrlib.draw_img(pipe.position, pipe.top_y, nonNull(pipe_flipped), 0, 1, 1, WHITE_COLOR); - wii.grrlib.draw_img(pipe.position, pipe.bottom_y, nonNull(globalThis.pipe), 0, 1, 1, WHITE_COLOR); - pipe.position -= 100 * wii.get_deltatime(); - pipe.time_active += wii.get_deltatime(); + wii.grrlib.draw_img(this.position, this.top_y, nonNull(pipe_flipped), 0, 1, 1, WHITE_COLOR); + wii.grrlib.draw_img(this.position, this.bottom_y, nonNull(pipe), 0, 1, 1, WHITE_COLOR); + this.position -= 100 * wii.get_deltatime(); + this.time_active += wii.get_deltatime(); } function update() { @@ -133,13 +128,13 @@ function update() { } if (timer == 0) { - pipes.push(create_pipe()); + pipes.push(new Pipe()); } wii.grrlib.draw_img(0, 0, nonNull(background), 0, 1, 1, WHITE_COLOR); update_bird(); for (var i = 0; i < pipes.length; i++) { - update_pipe(pipes[i]); + pipes[i].update(); } wii.print("deltatime: " + wii.get_deltatime()) globalThis.timer += wii.get_deltatime(); diff --git a/types.d.ts b/types.d.ts index d7a9d1e..9371fec 100644 --- a/types.d.ts +++ b/types.d.ts @@ -7,12 +7,6 @@ declare interface FilePtr { declare interface GRRLibTexture { __brand: "GRRLibTexture" } -declare interface Pipe { - top_y: number - bottom_y: number - position: number - time_active: number -}; declare namespace wii { function print(message: string): void