Now we make the pipe-halves appear in the
correct position.
Dealing with the x-position is easy.
Remember that MySprite positions are expressed in terms of their top-left corner. So setting a correct y-position requires a little bit of addition and subtraction.
function add_pipe(x_pos, top_of_gap, gap_width) {
// First the top pipe
var top_pipe = new MySprite();
top_pipe.MyImg = pipe_piece;
top_pipe.x = x_pos;
top_pipe.y = top_of_gap - pipe_piece.height;
pipes.push(top_pipe);
// Then the bottom pipe
var bottom_pipe = new MySprite();
bottom_pipe.MyImg = pipe_piece;
bottom_pipe.flipV = true;
bottom_pipe.x = x_pos;
bottom_pipe.y = top_of_gap + gap_width;
pipes.push(bottom_pipe );
}
But how will we make the pipes move?