Learn Create Your Own Split Screen

Next Page

We've got all the structure to deal with pipes, but no pipes yet.

I'm going to imagine that, in a perfect world, there'd be a function that adds a pipe. The function would take three parameters:

  1. The x-position of the pipe. This position might extend well past the visible part of my canvas, way to the right, but would eventually travel far enough left to be visible.
  2. The y-position of the gap between the top and bottom halves. We'll just decide to identify the position of the gap by its topmost.
  3. The size of the gap. We might choose to make the gaps quite large to begin with, then as the game progresses, make the gaps more and more narrow.
Our imaginary function would look like this:
function add_pipe(x_pos, top_of_gap, gap_width) { // clever stuff in here }
Then it would be easy to call it as many times as I like to make as many pipes as I like:
add_pipe(500, 100, 140); add_pipe(800, 50, 140); // ... etc