DEADSOFTWARE

Store block references intead of ids
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / mobs / FallingSand.java
index b1777c485c7ecffb1bd553bc5c7115a57c53d33a..14ec825d5735d37f7000ca84df0e4851b582c9e1 100644 (file)
@@ -3,7 +3,9 @@ package ru.deadsoftware.cavedroid.game.mobs;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
 import ru.deadsoftware.cavedroid.game.GameItems;
-import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.game.GameItemsHolder;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
+
 
 /**
  * Falling sand is actually a mob, that spawns in place of gravel when there is no block under it,
@@ -13,30 +15,40 @@ public class FallingSand extends Mob {
 
     /**
      * 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, 0);
-        mov = new Vector2(0, 1);
+        super(x, y, 16, 16, Direction.LEFT, Type.SAND, Integer.MAX_VALUE);
+        mVelocity = new Vector2(0, 1);
     }
 
     @Override
-    public void ai() {
+    public float getSpeed() {
+        return 0;
     }
 
     @Override
-    public void changeDir() {
+    public void jump() {
+        // no-op
+    }
+
+    @Override
+    public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
+        if (mVelocity.isZero()) {
+            gameWorld.setForeMap(getMapX(), getMiddleMapY(), gameItemsHolder.getBlock("sand"));
+            kill();
+        }
     }
 
     @Override
-    public void draw(SpriteBatch spriteBatch, float x, float y) {
-        spriteBatch.draw(GameItems.getBlock("sand").getTex(), x, y);
+    public void changeDir() {
     }
 
     @Override
-    public int getType() {
-        return 10;
+    public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
+        spriteBatch.draw(GameItems.getBlockTex(10), x, y);
     }
 
 }