Game Development Reference
In-Depth Information
// around each window. If it goes too far to
the right, and
// wanders off one window, it needs to wrap
to the left side
// of the next window.
snake.pos.x += snake.dir.x * snake.speed;
snake.pos.x %= frames.width * frames.length;
snake.pos.y += snake.speed * snake.dir.y;
if (snake.pos.y < 0)
snake.pos.y = frames.height - snake.h;
if (snake.pos.y + snake.h > frames.height)
snake.pos.y = 0;
if (snake.pos.x < 0)
snake.pos.x = (frames.width - snake.w) *
frames.width * frames.length;
var shouldDraw;
for (var i = 0, len = frames.length; i < len;
i++) {
// Determine which window the snake is in,
and tell only that
// window that it needs to render the snake
shouldDraw = snake.pos.x + snake.w <=
frames.width * (i + 1) &&
snake.pos.x >= frames.width * i ||
snake.pos.x <= frames.width * (i + 1) &&
snake.pos.x >= frames.width * i;
// Lastly, we pass all this information to
each window in canvas coordinates.
frames[i].postMessage({
x: snake.pos.x % frames.width,
y: snake.pos.y,
w: snake.w,
h: snake.h,
shouldDraw: shouldDraw,
color: snake.color
}, "*");
}
}
Search WWH ::




Custom Search