DEADSOFTWARE

Add items count and tools duration
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / mobs / FallingSand.java
index ee310e44179f1c557c512a0cd720a8dc4d41f384..f41da96872c12aa7fc32ce6dffc885822d13935d 100644 (file)
@@ -1,10 +1,15 @@
 package ru.deadsoftware.cavedroid.game.mobs;
 
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavedroid.game.GameItemsHolder;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.misc.Assets;
 
-import static ru.deadsoftware.cavedroid.GameScreen.GP;
+import javax.annotation.CheckForNull;
+
 
 /**
  * Falling sand is actually a mob, that spawns in place of gravel when there is no block under it,
@@ -12,20 +17,33 @@ import static ru.deadsoftware.cavedroid.GameScreen.GP;
  */
 public class FallingSand extends Mob {
 
+    private static final String TAG = "FallingSand";
+
     /**
      * Creates a FallingSand mob at coordinates
+     *
      * @param x X in pixels
      * @param y Y in pixels
      */
     public FallingSand(float x, float y) {
-        super(x, y, 16, 16, Direction.LEFT, Type.SAND);
-        move = new Vector2(0, 1);
+        super(x, y, 16, 16, Direction.LEFT, Type.SAND, Integer.MAX_VALUE);
+        mVelocity = new Vector2(0, 1);
+    }
+
+    @Override
+    public float getSpeed() {
+        return 0;
+    }
+
+    @Override
+    public void jump() {
+        // no-op
     }
 
     @Override
-    public void ai() {
-        if (move.isZero()) {
-            GP.world.setForeMap(getMapX(), getMiddleMapY(), 10);
+    public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
+        if (mVelocity.isZero()) {
+            gameWorld.setForeMap(getMapX(), getUpperMapY(), gameItemsHolder.getBlock("sand"));
             kill();
         }
     }
@@ -35,8 +53,16 @@ public class FallingSand extends Mob {
     }
 
     @Override
-    public void draw(SpriteBatch spriteBatch, float x, float y) {
-        spriteBatch.draw(Assets.sandSprite, x, y);
+    public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
+        @CheckForNull final Texture texture = Assets.blockTextures.get("sand");
+
+        if (texture == null) {
+            Gdx.app.error(TAG, "Couldn't draw: texture not found");
+            kill();
+            return;
+        }
+
+        spriteBatch.draw(texture, x, y);
     }
 
 }