DEADSOFTWARE

Some mobs refactor
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GameInput.java
index 09a7e7056383298ecddde2ccc2fdf890a9298dd1..2bf6e7d096ab17912d6794841661a212841c1988 100644 (file)
@@ -3,6 +3,7 @@ package ru.deadsoftware.cavedroid.game;
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Input;
 import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.utils.TimeUtils;
 import com.google.common.collect.Range;
 import ru.deadsoftware.cavedroid.MainConfig;
@@ -11,6 +12,7 @@ import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.mobs.Pig;
 import ru.deadsoftware.cavedroid.game.mobs.Player;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 
@@ -67,12 +69,12 @@ public class GameInput {
         if (checkSwim()) {
             mPlayer.swim = true;
         } else if (mPlayer.canJump()) {
-            mPlayer.getVelocity().add(0, -180);
+            mPlayer.jump();
         } else if (!mPlayer.isFlyMode() && mPlayer.gameMode == 1) {
             mPlayer.setFlyMode(true);
             mPlayer.getVelocity().y = 0;
         } else if (mPlayer.isFlyMode()) {
-            mPlayer.getVelocity().y = -GamePhysics.PL_SPEED;
+            mPlayer.getVelocity().y = -mPlayer.getSpeed();
         }
     }
 
@@ -89,14 +91,14 @@ public class GameInput {
         if (mControlMode == ControlMode.WALK || !mMainConfig.isTouch()) {
             switch (keycode) {
                 case Input.Keys.A:
-                    mPlayer.getVelocity().x = -GamePhysics.PL_SPEED;
+                    mPlayer.getVelocity().x = -mPlayer.getSpeed();
                     mPlayer.setDir(Mob.Direction.LEFT);
                     if (mMainConfig.isTouch() && checkSwim()) {
                         mPlayer.swim = true;
                     }
                     break;
                 case Input.Keys.D:
-                    mPlayer.getVelocity().x = GamePhysics.PL_SPEED;
+                    mPlayer.getVelocity().x = mPlayer.getSpeed();
                     mPlayer.setDir(Mob.Direction.RIGHT);
                     if (mMainConfig.isTouch() && checkSwim()) {
                         mPlayer.swim = true;
@@ -108,7 +110,7 @@ public class GameInput {
                     break;
                 case Input.Keys.S:
                 case Input.Keys.CONTROL_LEFT:
-                    mPlayer.getVelocity().y = GamePhysics.PL_SPEED;
+                    mPlayer.getVelocity().y = mPlayer.getSpeed();
                     break;
             }
         } else {
@@ -164,14 +166,22 @@ public class GameInput {
                 mCurX += mPlayer.looksLeft() ? 1 : -1;
             }
         } else if (!mMainConfig.isTouch()) {
-            mCurX = (int) (Gdx.input.getX() * (mMainConfig.getWidth() /
-                    Gdx.graphics.getWidth()) + gameRenderer.getCamX()) / 16;
+            final int tmpX = (int) (Gdx.input.getX() * (mMainConfig.getWidth() /
+                    Gdx.graphics.getWidth()) + gameRenderer.getCamX());
+            mCurX = tmpX / 16;
 
-            mCurY = (int) (Gdx.input.getY() * (mMainConfig.getHeight() /
-                    Gdx.graphics.getHeight()) + gameRenderer.getCamY()) / 16;
-            if (mCurX < 0) {
+            final int tmpY = (int) (Gdx.input.getY() * (mMainConfig.getHeight() /
+                    Gdx.graphics.getHeight()) + gameRenderer.getCamY());
+            mCurY = tmpY / 16;
+
+            if (tmpX < 0) {
                 mCurX--;
             }
+
+            final double a = tmpX - mPlayer.x;
+            final double b = tmpY - mPlayer.y;
+
+            mPlayer.headRotation = (float) Math.atan(b / a) * MathUtils.radDeg;
         }
 
         if (pastX != mCurX || pastY != mCurY) {
@@ -384,6 +394,10 @@ public class GameInput {
     }
 
     public void touchDragged(float screenX, float screenY) {
+        if (Math.abs(screenX - mTouchDownX) < 16 && Math.abs(screenY - mTouchDownY) < 16) {
+            return;
+        }
+
         mDragging = true;
         if (mMainConfig.checkGameUiWindow(GameUiWindow.CREATIVE_INVENTORY) && Math.abs(screenY - mTouchDownY) > 16) {
             if (insideCreativeInv(screenX, screenY)) {