use JS classes

This commit is contained in:
easrng 2024-06-24 21:50:57 -04:00 committed by Fries
parent 7158cd3b29
commit ad4dc2332b
2 changed files with 14 additions and 25 deletions

View file

@ -86,34 +86,29 @@ function update_bird() {
wii.grrlib.draw_img(0, bird.position, nonNull(bird.texture), 0, 1, 1, WHITE_COLOR); 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_max = 200;
const top_y = random_range(0, top_max); 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, nonNull(pipe_flipped), 0, 1, 1, WHITE_COLOR);
wii.grrlib.draw_img(100, top_y + 400, nonNull(pipe), 0, 1, 1, WHITE_COLOR); wii.grrlib.draw_img(100, top_y + 400, nonNull(pipe), 0, 1, 1, WHITE_COLOR);
return { this.top_y = -top_y
top_y: -top_y, this.bottom_y = -top_y + 400
bottom_y: -top_y + 400, this.position = 650
position: 650, this.time_active = 0
time_active: 0
}
} }
/** Pipe.prototype.update = function () {
* @param {Pipe} pipe if (this.time_active >= PIPE_MAX_TIME) {
*/ const index = pipes.indexOf(this);
function update_pipe(pipe) {
if (pipe.time_active >= PIPE_MAX_TIME) {
const index = pipes.indexOf(pipe);
pipes.splice(index, -1); pipes.splice(index, -1);
return; return;
} }
wii.grrlib.draw_img(pipe.position, pipe.top_y, nonNull(pipe_flipped), 0, 1, 1, WHITE_COLOR); wii.grrlib.draw_img(this.position, this.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); wii.grrlib.draw_img(this.position, this.bottom_y, nonNull(pipe), 0, 1, 1, WHITE_COLOR);
pipe.position -= 100 * wii.get_deltatime(); this.position -= 100 * wii.get_deltatime();
pipe.time_active += wii.get_deltatime(); this.time_active += wii.get_deltatime();
} }
function update() { function update() {
@ -133,13 +128,13 @@ function update() {
} }
if (timer == 0) { if (timer == 0) {
pipes.push(create_pipe()); pipes.push(new Pipe());
} }
wii.grrlib.draw_img(0, 0, nonNull(background), 0, 1, 1, WHITE_COLOR); wii.grrlib.draw_img(0, 0, nonNull(background), 0, 1, 1, WHITE_COLOR);
update_bird(); update_bird();
for (var i = 0; i < pipes.length; i++) { for (var i = 0; i < pipes.length; i++) {
update_pipe(pipes[i]); pipes[i].update();
} }
wii.print("deltatime: " + wii.get_deltatime()) wii.print("deltatime: " + wii.get_deltatime())
globalThis.timer += wii.get_deltatime(); globalThis.timer += wii.get_deltatime();

6
types.d.ts vendored
View file

@ -7,12 +7,6 @@ declare interface FilePtr {
declare interface GRRLibTexture { declare interface GRRLibTexture {
__brand: "GRRLibTexture" __brand: "GRRLibTexture"
} }
declare interface Pipe {
top_y: number
bottom_y: number
position: number
time_active: number
};
declare namespace wii { declare namespace wii {
function print(message: string): void function print(message: string): void