Overflow Posted August 22, 2014 Share Posted August 22, 2014 I have two arrays, one of them is to display the tiles on a map and the other is to detect collision. At the moment I can't move my player at all and the colArray doesn't seem to be working properly. Would anyone mind taking a look at my code?My colArray is the following (I've also included a fiddle below): function loadCollision() { var colArray = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ]; var posiX = 0; var posiY = 0; for (var x = 0; x < colArray.length; x++) { for (var y = 0; y < colArray[x].length; y++) { if (colArray[i][j] === 0) { } if (colArray[i][j] == 1) { $('#player').stop(); // stop player from moving } posiX += 32; } posiX = 0; posiY += 32; } }fiddle: http://jsfiddle.net/c7tk1ks6/5/Thanks! Quote Link to comment Share on other sites More sharing options...
Deban Posted August 28, 2014 Share Posted August 28, 2014 You are using x-y in your for, and i-j to access the array. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.