{"action":"created","comment":{"url":"https://api.github.com/repos/nagado/educ/pulls/comments/46900697","id":46900697,"diff_hunk":"@@ -0,0 +1,141 @@\n+#include <SFML/Graphics.hpp>\n+#include \"Racquet.h\"\n+#include \"TextException.h\"\n+#include \"Utils.h\"\n+#include <math.h>\n+#include \"Ball.h\"\n+\n+//check that the speed is working, and that the recalculation happens only one in a hit. Add time calculation! Whoohoo\n+\n+void Ball::move()\n+{\n+  if (angle > 2 * Utils::PI || angle < 0 * Utils::PI)\n+    throw TextException(\"Unacceptable angle\\n\");\n+\n+  x += speed * cos(angle);\n+  y -= speed * sin(angle);\n+  setPosition(round(x), round(y));\n+}\n+\n+void Ball::changePosition(int xx, int yy)\n+{\n+  setPosition(xx, yy);\n+  x = xx;\n+  y = yy;\n+}\n+\n+void Ball::updatePosition(const Racquet& racquet)\n+{\n+  recalculateAngle(racquet);\n+  move();\n+}\n+\n+void Ball::draw(sf::RenderTarget& target, sf::RenderStates states) const\n+{\n+  int f = 1 - radius;\n+  int ddF_x = 1;\n+  int ddF_y = -2 * radius;\n+  int xx = 0;\n+  int yy = radius;\n+  std::vector<sf::Vertex> vertices;\n+\n+  vertices.push_back(sf::Vertex(sf::Vector2f(round(x), round(y) + radius)));\n+  vertices.push_back(sf::Vertex(sf::Vector2f(round(x), round(y) - radius)));\n+  vertices.push_back(sf::Vertex(sf::Vector2f(round(x) - radius, round(y))));  \n+  vertices.push_back(sf::Vertex(sf::Vector2f(round(x) + radius, round(y))));\n+\n+  while(xx < yy)\n+  {\n+    if(f >= 0) \n+    { \n+      yy--; \n+      ddF_y += 2; \n+      f += ddF_y; \n+    }\n+ \n+    xx++; \n+    ddF_x += 2; \n+    f += ddF_x; \n+\n+    vertices.push_back(sf::Vertex(sf::Vector2f(round(x) + xx, round(y) + yy)));\n+    vertices.push_back(sf::Vertex(sf::Vector2f(round(x) - xx, round(y) + yy)));\n+    vertices.push_back(sf::Vertex(sf::Vector2f(round(x) + xx, round(y) - yy)));  \n+    vertices.push_back(sf::Vertex(sf::Vector2f(round(x) - xx, round(y) - yy)));\n+    vertices.push_back(sf::Vertex(sf::Vector2f(round(x) + yy, round(y) + xx)));\n+    vertices.push_back(sf::Vertex(sf::Vector2f(round(x) - yy, round(y) + xx)));\n+    vertices.push_back(sf::Vertex(sf::Vector2f(round(x) + yy, round(y) - xx)));  \n+    vertices.push_back(sf::Vertex(sf::Vector2f(round(x) - yy, round(y) - xx)));\n+\n+  \n+  }\n+\n+  target.draw(&vertices[0], vertices.size(), sf::TrianglesFan);\n+}\n+\n+bool Ball::racquetZone_x(const Racquet& racquet)\n+{\n+  int nozone_racquet_left = racquet.getPosition().x - racquet.getDimentions().x / 2 - radius;\n+  int nozone_racquet_right = racquet.getPosition().x + racquet.getDimentions().x / 2 + radius;\n+\n+  if (getPosition().x >= nozone_racquet_left && getPosition().x <= nozone_racquet_right)\n+    return true;\n+  else\n+    return false; \n+  \n+}\n+\n+bool Ball::racquetZone_y(const Racquet& racquet)\n+{\n+  if (getPosition().y > Utils::nozone_catchline - int(speed) && getPosition().y <= Utils::nozone_catchline)\n+    return true;\n+  else\n+    return false;  \n+}\n+\n+double Ball::balanceAngle(double a)\n+{\n+  while (a < 0)\n+    a += 2 * Utils::PI;\n+\n+  while (a > 2 * Utils::PI)\n+    a -= 2 * Utils::PI;\n+\n+  return a;\n+}\n+\n+void Ball::recalculateAngle(const Racquet& racquet)\n+{\n+//make it impossible to have angle 0 or PI\n+\n+  if (getPosition().y <= Utils::nozone_top)\n+    angle = 2 * Utils::PI - angle;\n+  else if (getPosition().x <= Utils::nozone_left || getPosition().x >= Utils::nozone_right)\n+    angle = balanceAngle(1 * Utils::PI - angle);\n+  else if (racquetZone_y(racquet) && racquetZone_x(racquet))\n+  {\n+    angle = 2 * Utils::PI - angle;\n+    \n+    if (angle != racquet.getAngle() && racquet.getSpeed() != 0)\n+    {\n+      double side = 0;\n+      \n+      if (racquet.getAngle() == 0)\n+      {\n+        side = sqrt(speed * speed + racquet.getSpeed() * racquet.getSpeed() - 2 * speed * racquet.getSpeed() * cos(Utils::PI - angle));\n+        angle = acos((side * side + racquet.getSpeed() * racquet.getSpeed() - speed * speed) / (2 * side * racquet.getSpeed()));\n+      }\n+      else\n+      {\n+        side = sqrt(speed * speed + racquet.getSpeed() * racquet.getSpeed() - 2 * speed * racquet.getSpeed() * cos(angle));\n+        angle = Utils::PI - acos((side * side + racquet.getSpeed() * racquet.getSpeed() - speed * speed) / (2 * side * racquet.getSpeed()));\n+      }\n+\n+      if (side <= 0)\n+        throw TextException(\"Side calculations are wrong\\n\");","path":"sfml/Ball.cpp","position":134,"original_position":134,"commit_id":"75e816e7b169ede5a7fe5225277b5193bd8b96e0","original_commit_id":"75e816e7b169ede5a7fe5225277b5193bd8b96e0","user":{"login":"dlazarus","id":6580913,"avatar_url":"https://avatars.githubusercontent.com/u/6580913?v=3","gravatar_id":"","url":"https://api.github.com/users/dlazarus","html_url":"https://github.com/dlazarus","followers_url":"https://api.github.com/users/dlazarus/followers","following_url":"https://api.github.com/users/dlazarus/following{/other_user}","gists_url":"https://api.github.com/users/dlazarus/gists{/gist_id}","starred_url":"https://api.github.com/users/dlazarus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlazarus/subscriptions","organizations_url":"https://api.github.com/users/dlazarus/orgs","repos_url":"https://api.github.com/users/dlazarus/repos","events_url":"https://api.github.com/users/dlazarus/events{/privacy}","received_events_url":"https://api.github.com/users/dlazarus/received_events","type":"User","site_admin":false},"body":"Skip line","created_at":"2015-12-08T00:38:12Z","updated_at":"2015-12-08T00:38:12Z","html_url":"https://github.com/nagado/educ/pull/6#discussion_r46900697","pull_request_url":"https://api.github.com/repos/nagado/educ/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/nagado/educ/pulls/comments/46900697"},"html":{"href":"https://github.com/nagado/educ/pull/6#discussion_r46900697"},"pull_request":{"href":"https://api.github.com/repos/nagado/educ/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/nagado/educ/pulls/6","id":51487570,"html_url":"https://github.com/nagado/educ/pull/6","diff_url":"https://github.com/nagado/educ/pull/6.diff","patch_url":"https://github.com/nagado/educ/pull/6.patch","issue_url":"https://api.github.com/repos/nagado/educ/issues/6","number":6,"state":"open","locked":false,"title":"Squash game","user":{"login":"nagado","id":6580926,"avatar_url":"https://avatars.githubusercontent.com/u/6580926?v=3","gravatar_id":"","url":"https://api.github.com/users/nagado","html_url":"https://github.com/nagado","followers_url":"https://api.github.com/users/nagado/followers","following_url":"https://api.github.com/users/nagado/following{/other_user}","gists_url":"https://api.github.com/users/nagado/gists{/gist_id}","starred_url":"https://api.github.com/users/nagado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nagado/subscriptions","organizations_url":"https://api.github.com/users/nagado/orgs","repos_url":"https://api.github.com/users/nagado/repos","events_url":"https://api.github.com/users/nagado/events{/privacy}","received_events_url":"https://api.github.com/users/nagado/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-23T04:39:05Z","updated_at":"2015-12-08T00:38:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aafcd26f7ad14e78c4d7a45a2043cea961fb1767","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nagado/educ/pulls/6/commits","review_comments_url":"https://api.github.com/repos/nagado/educ/pulls/6/comments","review_comment_url":"https://api.github.com/repos/nagado/educ/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nagado/educ/issues/6/comments","statuses_url":"https://api.github.com/repos/nagado/educ/statuses/75e816e7b169ede5a7fe5225277b5193bd8b96e0","head":{"label":"nagado:squash_game","ref":"squash_game","sha":"75e816e7b169ede5a7fe5225277b5193bd8b96e0","user":{"login":"nagado","id":6580926,"avatar_url":"https://avatars.githubusercontent.com/u/6580926?v=3","gravatar_id":"","url":"https://api.github.com/users/nagado","html_url":"https://github.com/nagado","followers_url":"https://api.github.com/users/nagado/followers","following_url":"https://api.github.com/users/nagado/following{/other_user}","gists_url":"https://api.github.com/users/nagado/gists{/gist_id}","starred_url":"https://api.github.com/users/nagado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nagado/subscriptions","organizations_url":"https://api.github.com/users/nagado/orgs","repos_url":"https://api.github.com/users/nagado/repos","events_url":"https://api.github.com/users/nagado/events{/privacy}","received_events_url":"https://api.github.com/users/nagado/received_events","type":"User","site_admin":false},"repo":{"id":40633521,"name":"educ","full_name":"nagado/educ","owner":{"login":"nagado","id":6580926,"avatar_url":"https://avatars.githubusercontent.com/u/6580926?v=3","gravatar_id":"","url":"https://api.github.com/users/nagado","html_url":"https://github.com/nagado","followers_url":"https://api.github.com/users/nagado/followers","following_url":"https://api.github.com/users/nagado/following{/other_user}","gists_url":"https://api.github.com/users/nagado/gists{/gist_id}","starred_url":"https://api.github.com/users/nagado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nagado/subscriptions","organizations_url":"https://api.github.com/users/nagado/orgs","repos_url":"https://api.github.com/users/nagado/repos","events_url":"https://api.github.com/users/nagado/events{/privacy}","received_events_url":"https://api.github.com/users/nagado/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nagado/educ","description":"","fork":false,"url":"https://api.github.com/repos/nagado/educ","forks_url":"https://api.github.com/repos/nagado/educ/forks","keys_url":"https://api.github.com/repos/nagado/educ/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nagado/educ/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nagado/educ/teams","hooks_url":"https://api.github.com/repos/nagado/educ/hooks","issue_events_url":"https://api.github.com/repos/nagado/educ/issues/events{/number}","events_url":"https://api.github.com/repos/nagado/educ/events","assignees_url":"https://api.github.com/repos/nagado/educ/assignees{/user}","branches_url":"https://api.github.com/repos/nagado/educ/branches{/branch}","tags_url":"https://api.github.com/repos/nagado/educ/tags","blobs_url":"https://api.github.com/repos/nagado/educ/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nagado/educ/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nagado/educ/git/refs{/sha}","trees_url":"https://api.github.com/repos/nagado/educ/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nagado/educ/statuses/{sha}","languages_url":"https://api.github.com/repos/nagado/educ/languages","stargazers_url":"https://api.github.com/repos/nagado/educ/stargazers","contributors_url":"https://api.github.com/repos/nagado/educ/contributors","subscribers_url":"https://api.github.com/repos/nagado/educ/subscribers","subscription_url":"https://api.github.com/repos/nagado/educ/subscription","commits_url":"https://api.github.com/repos/nagado/educ/commits{/sha}","git_commits_url":"https://api.github.com/repos/nagado/educ/git/commits{/sha}","comments_url":"https://api.github.com/repos/nagado/educ/comments{/number}","issue_comment_url":"https://api.github.com/repos/nagado/educ/issues/comments{/number}","contents_url":"https://api.github.com/repos/nagado/educ/contents/{+path}","compare_url":"https://api.github.com/repos/nagado/educ/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nagado/educ/merges","archive_url":"https://api.github.com/repos/nagado/educ/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nagado/educ/downloads","issues_url":"https://api.github.com/repos/nagado/educ/issues{/number}","pulls_url":"https://api.github.com/repos/nagado/educ/pulls{/number}","milestones_url":"https://api.github.com/repos/nagado/educ/milestones{/number}","notifications_url":"https://api.github.com/repos/nagado/educ/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nagado/educ/labels{/name}","releases_url":"https://api.github.com/repos/nagado/educ/releases{/id}","created_at":"2015-08-13T01:52:34Z","updated_at":"2015-09-11T00:36:23Z","pushed_at":"2015-11-23T04:39:05Z","git_url":"git://github.com/nagado/educ.git","ssh_url":"git@github.com:nagado/educ.git","clone_url":"https://github.com/nagado/educ.git","svn_url":"https://github.com/nagado/educ","homepage":null,"size":50,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"nagado:master","ref":"master","sha":"8998ebb98576f8dc26ef5ad6133aa4e600eed530","user":{"login":"nagado","id":6580926,"avatar_url":"https://avatars.githubusercontent.com/u/6580926?v=3","gravatar_id":"","url":"https://api.github.com/users/nagado","html_url":"https://github.com/nagado","followers_url":"https://api.github.com/users/nagado/followers","following_url":"https://api.github.com/users/nagado/following{/other_user}","gists_url":"https://api.github.com/users/nagado/gists{/gist_id}","starred_url":"https://api.github.com/users/nagado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nagado/subscriptions","organizations_url":"https://api.github.com/users/nagado/orgs","repos_url":"https://api.github.com/users/nagado/repos","events_url":"https://api.github.com/users/nagado/events{/privacy}","received_events_url":"https://api.github.com/users/nagado/received_events","type":"User","site_admin":false},"repo":{"id":40633521,"name":"educ","full_name":"nagado/educ","owner":{"login":"nagado","id":6580926,"avatar_url":"https://avatars.githubusercontent.com/u/6580926?v=3","gravatar_id":"","url":"https://api.github.com/users/nagado","html_url":"https://github.com/nagado","followers_url":"https://api.github.com/users/nagado/followers","following_url":"https://api.github.com/users/nagado/following{/other_user}","gists_url":"https://api.github.com/users/nagado/gists{/gist_id}","starred_url":"https://api.github.com/users/nagado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nagado/subscriptions","organizations_url":"https://api.github.com/users/nagado/orgs","repos_url":"https://api.github.com/users/nagado/repos","events_url":"https://api.github.com/users/nagado/events{/privacy}","received_events_url":"https://api.github.com/users/nagado/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nagado/educ","description":"","fork":false,"url":"https://api.github.com/repos/nagado/educ","forks_url":"https://api.github.com/repos/nagado/educ/forks","keys_url":"https://api.github.com/repos/nagado/educ/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nagado/educ/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nagado/educ/teams","hooks_url":"https://api.github.com/repos/nagado/educ/hooks","issue_events_url":"https://api.github.com/repos/nagado/educ/issues/events{/number}","events_url":"https://api.github.com/repos/nagado/educ/events","assignees_url":"https://api.github.com/repos/nagado/educ/assignees{/user}","branches_url":"https://api.github.com/repos/nagado/educ/branches{/branch}","tags_url":"https://api.github.com/repos/nagado/educ/tags","blobs_url":"https://api.github.com/repos/nagado/educ/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nagado/educ/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nagado/educ/git/refs{/sha}","trees_url":"https://api.github.com/repos/nagado/educ/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nagado/educ/statuses/{sha}","languages_url":"https://api.github.com/repos/nagado/educ/languages","stargazers_url":"https://api.github.com/repos/nagado/educ/stargazers","contributors_url":"https://api.github.com/repos/nagado/educ/contributors","subscribers_url":"https://api.github.com/repos/nagado/educ/subscribers","subscription_url":"https://api.github.com/repos/nagado/educ/subscription","commits_url":"https://api.github.com/repos/nagado/educ/commits{/sha}","git_commits_url":"https://api.github.com/repos/nagado/educ/git/commits{/sha}","comments_url":"https://api.github.com/repos/nagado/educ/comments{/number}","issue_comment_url":"https://api.github.com/repos/nagado/educ/issues/comments{/number}","contents_url":"https://api.github.com/repos/nagado/educ/contents/{+path}","compare_url":"https://api.github.com/repos/nagado/educ/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nagado/educ/merges","archive_url":"https://api.github.com/repos/nagado/educ/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nagado/educ/downloads","issues_url":"https://api.github.com/repos/nagado/educ/issues{/number}","pulls_url":"https://api.github.com/repos/nagado/educ/pulls{/number}","milestones_url":"https://api.github.com/repos/nagado/educ/milestones{/number}","notifications_url":"https://api.github.com/repos/nagado/educ/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nagado/educ/labels{/name}","releases_url":"https://api.github.com/repos/nagado/educ/releases{/id}","created_at":"2015-08-13T01:52:34Z","updated_at":"2015-09-11T00:36:23Z","pushed_at":"2015-11-23T04:39:05Z","git_url":"git://github.com/nagado/educ.git","ssh_url":"git@github.com:nagado/educ.git","clone_url":"https://github.com/nagado/educ.git","svn_url":"https://github.com/nagado/educ","homepage":null,"size":50,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nagado/educ/pulls/6"},"html":{"href":"https://github.com/nagado/educ/pull/6"},"issue":{"href":"https://api.github.com/repos/nagado/educ/issues/6"},"comments":{"href":"https://api.github.com/repos/nagado/educ/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/nagado/educ/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/nagado/educ/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nagado/educ/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/nagado/educ/statuses/75e816e7b169ede5a7fe5225277b5193bd8b96e0"}}}}