DEADSOFTWARE

Store block references intead of ids
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / mobs / FallingSand.java
1 package ru.deadsoftware.cavedroid.game.mobs;
3 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
4 import com.badlogic.gdx.math.Vector2;
5 import ru.deadsoftware.cavedroid.game.GameItems;
6 import ru.deadsoftware.cavedroid.game.GameItemsHolder;
7 import ru.deadsoftware.cavedroid.game.world.GameWorld;
10 /**
11 * Falling sand is actually a mob, that spawns in place of gravel when there is no block under it,
12 * falls down to the next block and becomes a block of sand again.
13 */
14 public class FallingSand extends Mob {
16 /**
17 * Creates a FallingSand mob at coordinates
18 *
19 * @param x X in pixels
20 * @param y Y in pixels
21 */
22 public FallingSand(float x, float y) {
23 super(x, y, 16, 16, Direction.LEFT, Type.SAND, Integer.MAX_VALUE);
24 mVelocity = new Vector2(0, 1);
25 }
27 @Override
28 public float getSpeed() {
29 return 0;
30 }
32 @Override
33 public void jump() {
34 // no-op
35 }
37 @Override
38 public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
39 if (mVelocity.isZero()) {
40 gameWorld.setForeMap(getMapX(), getMiddleMapY(), gameItemsHolder.getBlock("sand"));
41 kill();
42 }
43 }
45 @Override
46 public void changeDir() {
47 }
49 @Override
50 public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
51 spriteBatch.draw(GameItems.getBlockTex(10), x, y);
52 }
54 }