game.js
// Move the player to a given point
Move the player to a given point
Move the player to a given point
function move(dy, dx) {
		var y = player[0] + dy;
		var x = player[1] + dx;
		var safe = (
			state[y][x] == ' '
			|| state[y][x] == '!'
		) && (
			!holding
			|| state[y-1][x] == ' '
			|| state[y-1][x] == '>'
			|| state[y-1][x] == '<'
		);
		var win = state[y][x] == '!';
		if (safe) {
			swap(player[0], player[1], y, x);
			if (holding) swap(player[0]-1, player[1], y-1, x);
			if (win) state[player[0]][player[1]] = ' ';
			player = [y, x];
		}
		if (win) {
			lvlnum++;
			load();
			return this;
		}
		if (safe && state[y+1][x] == ' ' || state[y+1][x] == '!') {
			return move(1, 0);
		}
		return this;
	}
function move ( dy , dx ) { var y = player [ 0 ] + dy ; var x = player [ 1 ] + dx ; var safe = ( state [ y ] [ x ] == ' ' || state [ y ] [ x ] == '!' ) && ( ! holding || state [ y - 1 ] [ x ] == ' ' || state [ y - 1 ] [ x ] == '>' || state [ y - 1 ] [ x ] == '<' ) ; var win = state [ y ] [ x ] == '!' ; if ( safe ) { swap ( player [ 0 ] , player [ 1 ] , y , x ) ; if ( holding ) swap ( player [ 0 ] - 1 , player [ 1 ] , y - 1 , x ) ; if ( win ) state [ player [ 0 ] ] [ player [ 1 ] ] = ' ' ; player = [ y , x ] ; } if ( win ) { lvlnum ++ ; load ( ) ; return this ; } if ( safe && state [ y + 1 ] [ x ] == ' ' || state [ y + 1 ] [ x ] == '!' ) { return move ( 1 , 0 ) ; } return this ; }
Move the player to a given point
Move the player to a given point
// Safe to move if nothing is in the way // Win if moving into the '!' // Do the move // Load the next level upon winning // Apply gravity to the player