• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Circular loop through 2D array

FrostyCat

Redemption Seeker
You could have scrolled a little further down and found the C++ answer, which is basically copy-and-paste except for minor syntax adjustments.
Code:
var X = array_length_2d(arr, 0),
    Y = array_height_2d(arr),
    xx = 0,
    yy = 0,
    dx = 0,
    dy = -1;
repeat (sqr(max(X, Y))) {
    if ((-X/2 <= xx) && (xx <= X/2) && (-Y/2 <= yy) && (yy <= Y/2)) {
        // DO STUFF...
    }
    if ((xx == yy) || ((xx < 0) && (xx == -yy)) || ((xx > 0) && (xx == 1-yy))) {
        var t = dx;
        dx = -dy;
        dy = t;
    }
    xx += dx;
    yy += dy;
}
 
Top