DEADSOFTWARE

Optimization
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GamePhysics.java
index 94f6f36d9dd6aa37e0b4ffc4a4f2caf7d3d338e2..88791dc67a59d337235c8a79d55c9080cb117c04 100644 (file)
@@ -26,20 +26,14 @@ class GamePhysics {
 
     private boolean checkJump(Rectangle rect, int dir) {
         int bl;
-        switch (dir) {
-            case 0:
-                bl = gp.world.getForeMap((int) ((rect.x - 8) / 16), (int) ((rect.y + rect.height - 8) / 16));
-                if (checkColl(new Rectangle(rect.x - 8, rect.y - 18, rect.width, rect.height))) bl = 0;
-                break;
-            case 1:
-                bl = gp.world.getForeMap((int) ((rect.x + rect.width + 8) / 16), (int) ((rect.y + rect.height - 8) / 16));
-                if (checkColl(new Rectangle(rect.x + rect.width + 8, rect.y - 18, rect.width, rect.height))) bl = 0;
-                break;
-            default:
-                bl = 0;
-        }
+        int blX = (int) (rect.x + rect.width * dir - 8 + 16 * dir);
+        int blY = (int) (rect.y + rect.height - 8);
+
+        bl = gp.world.getForeMap(blX / 16, blY / 16);
+        if (checkColl(new Rectangle(blX, rect.y - 18, rect.width, rect.height))) bl = 0;
+
         return (bl > 0 && GameItems.getBlock(bl).toJump() &&
-                (rect.y + rect.height) - GameItems.getBlock(bl).getRect((int) ((rect.x - 8) / 16), (int) ((rect.y + rect.height - 8) / 16)).y > 8);
+                (rect.y + rect.height) - GameItems.getBlock(bl).getRect(blX / 16, blY / 16).y > 8);
     }
 
     private boolean checkColl(Rectangle rect) {