DEADSOFTWARE

Delete old GameItems
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / mobs / FallingSand.java
index a8d9ce27b0ccac5bdd6bf437582f5c1b5e6e29ca..bce918e34fb811024815022970dd00ffa834e316 100644 (file)
@@ -1,9 +1,14 @@
 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.GameItems;
-import ru.deadsoftware.cavedroid.game.GameWorld;
+import ru.deadsoftware.cavedroid.game.GameItemsHolder;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
+import ru.deadsoftware.cavedroid.misc.Assets;
+
+import javax.annotation.CheckForNull;
 
 
 /**
@@ -12,6 +17,8 @@ import ru.deadsoftware.cavedroid.game.GameWorld;
  */
 public class FallingSand extends Mob {
 
+    private static final String TAG = "FallingSand";
+
     /**
      * Creates a FallingSand mob at coordinates
      *
@@ -19,14 +26,24 @@ public class FallingSand extends Mob {
      * @param y Y in pixels
      */
     public FallingSand(float x, float y) {
-        super(x, y, 16, 16, Direction.LEFT, Type.SAND);
+        super(x, y, 16, 16, Direction.LEFT, Type.SAND, Integer.MAX_VALUE);
         mVelocity = new Vector2(0, 1);
     }
 
     @Override
-    public void ai(GameWorld gameWorld) {
+    public float getSpeed() {
+        return 0;
+    }
+
+    @Override
+    public void jump() {
+        // no-op
+    }
+
+    @Override
+    public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
         if (mVelocity.isZero()) {
-            gameWorld.setForeMap(getMapX(), getMiddleMapY(), 10);
+            gameWorld.setForeMap(getMapX(), getMiddleMapY(), gameItemsHolder.getBlock("sand"));
             kill();
         }
     }
@@ -36,8 +53,16 @@ public class FallingSand extends Mob {
     }
 
     @Override
-    public void draw(SpriteBatch spriteBatch, float x, float y) {
-        spriteBatch.draw(GameItems.getBlockTex(10), 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);
     }
 
 }