DEADSOFTWARE

Fix warnings
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / mobs / FallingSand.java
1 package ru.deadsoftware.cavedroid.game.mobs;
3 import com.badlogic.gdx.Gdx;
4 import com.badlogic.gdx.graphics.Texture;
5 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
6 import com.badlogic.gdx.math.Vector2;
7 import ru.deadsoftware.cavedroid.game.GameItemsHolder;
8 import ru.deadsoftware.cavedroid.game.world.GameWorld;
9 import ru.deadsoftware.cavedroid.misc.Assets;
11 import javax.annotation.CheckForNull;
14 /**
15 * Falling sand is actually a mob, that spawns in place of gravel when there is no block under it,
16 * falls down to the next block and becomes a block of sand again.
17 */
18 public class FallingSand extends Mob {
20 private static final String TAG = "FallingSand";
22 /**
23 * Creates a FallingSand mob at coordinates
24 *
25 * @param x X in pixels
26 * @param y Y in pixels
27 */
28 public FallingSand(float x, float y) {
29 super(x, y, 16, 16, Direction.LEFT, Type.SAND, Integer.MAX_VALUE);
30 mVelocity = new Vector2(0, 1);
31 }
33 @Override
34 public float getSpeed() {
35 return 0;
36 }
38 @Override
39 public void jump() {
40 // no-op
41 }
43 @Override
44 public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
45 if (mVelocity.isZero()) {
46 gameWorld.setForeMap(getMapX(), getUpperMapY(), gameItemsHolder.getBlock("sand"));
47 kill();
48 }
49 }
51 @Override
52 public void changeDir() {
53 }
55 @Override
56 public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
57 @CheckForNull final Texture texture = Assets.blockTextures.get("sand");
59 if (texture == null) {
60 Gdx.app.error(TAG, "Couldn't draw: texture not found");
61 kill();
62 return;
63 }
65 spriteBatch.draw(texture, x, y);
66 }
68 }