{"action":"created","issue":{"url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/42","repository_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot","labels_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/42/labels{/name}","comments_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/42/comments","events_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/42/events","html_url":"https://github.com/ErmiyaEskandary/Slither.io-bot/issues/42","id":152697775,"number":42,"title":"I started to work on collision...heres what i have","user":{"login":"chancity","id":8220501,"avatar_url":"https://avatars.githubusercontent.com/u/8220501?v=3","gravatar_id":"","url":"https://api.github.com/users/chancity","html_url":"https://github.com/chancity","followers_url":"https://api.github.com/users/chancity/followers","following_url":"https://api.github.com/users/chancity/following{/other_user}","gists_url":"https://api.github.com/users/chancity/gists{/gist_id}","starred_url":"https://api.github.com/users/chancity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chancity/subscriptions","organizations_url":"https://api.github.com/users/chancity/orgs","repos_url":"https://api.github.com/users/chancity/repos","events_url":"https://api.github.com/users/chancity/events{/privacy}","received_events_url":"https://api.github.com/users/chancity/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/labels/Discussion","name":"Discussion","color":"5319E7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-05-03T04:33:04Z","updated_at":"2016-05-03T14:17:36Z","closed_at":null,"body":"```\r\nwindow.checkCollision` = function() {\r\n\tvar isTrue = false;\r\n\tfor (var snake in window.snakes){\r\n\t\tif (window.snakes[snake].nk != window.snake.nk) {\r\n\t\t\tfor (var y = window.snakes[snake].pts.length - 1; 0 <= y; y--){\r\n\t\t\t\tif(!window.snakes[snake].pts[y].dying) {\r\n\t\t\t\t\tvar enemyCoordinates = window.mapToMouse(window.snakes[snake].pts[y].xx, window.snakes[snake].pts[y].yy);\r\n\t\t\t\t\tenemyCoordinates = window.mouseToScreen(enemyCoordinates[0], enemyCoordinates[1]);\r\n\t\t\t\t\tenemyCoordinates = window.screenToCanvas(enemyCoordinates[0], enemyCoordinates[1]);\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (window.lineIntersect({xx: enemyCoordinates[0], yy: enemyCoordinates[1]}, 13*window.snakes[snake].sc*getScale())){\r\n\t\t\t\t\t\tisTrue = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\t\t\r\n\treturn isTrue;\r\n};\r\n\r\nwindow.lineIntersect = function(circleMiddle, circleRadius){\r\n\tvar A = window.mapToMouse(window.getX(),window.getY());\r\n\tA = window.mouseToScreen(A[0], A[1]);\r\n\tA = window.screenToCanvas(A[0], A[1]);\r\n\t\r\n\tvar B = window.goalCoordinates;\r\n\tB = window.mouseToScreen(B[0], B[1]);\r\n\tB = window.screenToCanvas(B[0], B[1]);\r\n\t\r\n\t\r\n\tvar C = circleMiddle;\r\n\t\r\n\tvar Ax = A[0];\r\n\tvar Ay = A[1];\r\n\t\r\n\tvar Bx = B[0];\r\n\tvar By = B[1];\r\n\t\r\n\tvar Cx = C.xx;\r\n\tvar Cy = C.yy;\r\n\t\r\n\t\r\n\t//console.log(Ax + \", \" + Ay)\r\n\t//console.log(Bx + \", \" + By)\r\n\t//console.log(Cx + \", \" + Cy)\r\n\t// compute the euclidean distance between A and B\r\n\tvar LAB = Math.sqrt(Math.pow(Bx-Ax, 2) + Math.pow(By-Ay,2))\r\n\r\n\t// compute the direction vector D from A to B\r\n\tvar Dx = (Bx-Ax)/LAB\r\n\tvar Dy = (By-Ay)/LAB\r\n\r\n\t// Now the line equation is x = Dx*t + Ax, y = Dy*t + Ay with 0 <= t <= 1.\r\n\r\n\t// compute the value t of the closest point to the circle center (Cx, Cy)\r\n\tvar t = Dx*(Cx-Ax) + Dy*(Cy-Ay)    \r\n\r\n\t// This is the projection of C on the line from A to B.\r\n\r\n\t// compute the coordinates of the point E on line and closest to C\r\n\tvar Ex = t*Dx+Ax\r\n\tvar Ey = t*Dy+Ay\r\n\r\n\t// compute the euclidean distance from E to C\r\n\tLEC = Math.sqrt(Math.pow(Ex-Cx,2) + Math.pow(Ey-Cy,2))\r\n\r\n\t//console.log(LEC + \",  > \" + window.csc * circleRadius)\r\n\t// test if the line intersects the circle\r\n\tif( LEC < window.csc * circleRadius){\r\n\t\treturn true;\r\n\t\t// compute distance from t to circle intersection point\r\n\t\tdt = Math.sqrt(Math.pow(R,2) - Math.pow(LEC,2))\r\n\r\n\t\t// compute first intersection point\r\n\t\tFx = (t-dt)*Dx + Ax\r\n\t\tFy = (t-dt)*Dy + Ay\r\n\r\n\t\t// compute second intersection point\r\n\t\tGx = (t+dt)*Dx + Ax\r\n\t\tGy = (t+dt)*Dy + Ay\r\n\r\n\t// else test if the line is tangent to circle\r\n\t} else if( LEC == circleRadius) {\r\n\t\treturn false;\r\n\t}else{\r\n\t\treturn false;\r\n\t}\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/comments/216542610","html_url":"https://github.com/ErmiyaEskandary/Slither.io-bot/issues/42#issuecomment-216542610","issue_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/42","id":216542610,"user":{"login":"ErmiyaEskandary","id":18369104,"avatar_url":"https://avatars.githubusercontent.com/u/18369104?v=3","gravatar_id":"","url":"https://api.github.com/users/ErmiyaEskandary","html_url":"https://github.com/ErmiyaEskandary","followers_url":"https://api.github.com/users/ErmiyaEskandary/followers","following_url":"https://api.github.com/users/ErmiyaEskandary/following{/other_user}","gists_url":"https://api.github.com/users/ErmiyaEskandary/gists{/gist_id}","starred_url":"https://api.github.com/users/ErmiyaEskandary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ErmiyaEskandary/subscriptions","organizations_url":"https://api.github.com/users/ErmiyaEskandary/orgs","repos_url":"https://api.github.com/users/ErmiyaEskandary/repos","events_url":"https://api.github.com/users/ErmiyaEskandary/events{/privacy}","received_events_url":"https://api.github.com/users/ErmiyaEskandary/received_events","type":"User","site_admin":false},"created_at":"2016-05-03T14:17:36Z","updated_at":"2016-05-03T14:17:36Z","body":"Could you post a screenshot ?"}}