[DeviceMotionCapture] Modify the coordinate formula
authorsh919.park <sh919.park@samsung.com>
Tue, 18 Jun 2013 14:24:42 +0000 (23:24 +0900)
committersh919.park <sh919.park@samsung.com>
Tue, 18 Jun 2013 14:31:11 +0000 (23:31 +0900)
[Title] Modify the coordinate formula
[Issue#] N_SE-40704
[Problem] The ball should not bounce on bottom right of the screen.
[Solution] Modify the coordinate formula

Change-Id: I86bc421ea88a1bc30a68b8d46e60bba32ca67d2c

js/main.js

index efe9d5b..777655e 100755 (executable)
@@ -23,23 +23,23 @@ function deviceMotionEvents() {
                 vx = vx * 0.98;
                 vy = vy * 0.98;
 
-                x = parseInt(x + (vx / 20));
-                y = parseInt(y + (vy / 20));
+                x = parseInt(Math.round(x + (vx / 20)));
+                y = parseInt(Math.round(y + (vy / 20)));
 
                 // Bound Check
-                if (x < 0) {
+                if (x <= 0) {
                         x = 0;
                         vx = -vx;
                 }
-                if (y < 0) {
+                if (y <= 0) {
                         y = 0;
                         vy = -vy;
                 }
-                if (x > document.documentElement.clientWidth - 80) {
+                if (x >= document.documentElement.clientWidth - 80) {
                         x = document.documentElement.clientWidth - 80;
                         vx = -vx;
                 }
-                if (y > document.documentElement.clientHeight - 80) {
+                if (y >= document.documentElement.clientHeight - 80) {
                         y = document.documentElement.clientHeight - 80;
                         vy = -vy;
                 }