use JS classes
This commit is contained in:
parent
7158cd3b29
commit
ad4dc2332b
2 changed files with 14 additions and 25 deletions
|
@ -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();
|
||||
|
|
6
types.d.ts
vendored
6
types.d.ts
vendored
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue