DEADSOFTWARE

Delete old GameItems
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / mobs / FallingGravel.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;
13 /**
14 * Falling gravel is actually a mob, that spawns in place of gravel when there is no block under it,
15 * falls down to the next block and becomes a block of gravel again.
16 */
17 public class FallingGravel extends Mob {
19 private static final String TAG = "FallingGravel";
21 /**
22 * Creates a FallingGravel mob at coordinates
23 *
24 * @param x X in pixels
25 * @param y Y in pixels
26 */
27 public FallingGravel(float x, float y) {
28 super(x, y, 16, 16, Direction.LEFT, Type.GRAVEL, Integer.MAX_VALUE);
29 mVelocity = new Vector2(0, 1);
30 }
32 @Override
33 public float getSpeed() {
34 return 0;
35 }
37 @Override
38 public void jump() {
39 // no-op
40 }
42 @Override
43 public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
44 if (mVelocity.isZero()) {
45 gameWorld.setForeMap(getMapX(), getMiddleMapY(), gameItemsHolder.getBlock("gravel"));
46 kill();
47 }
48 }
50 @Override
51 public void changeDir() {
52 }
54 @Override
55 public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
56 @CheckForNull final Texture texture = Assets.blockTextures.get("gravel");
58 if (texture == null) {
59 Gdx.app.error(TAG, "Couldn't draw: texture not found");
60 kill();
61 return;
62 }
64 spriteBatch.draw(texture, x, y);
65 }
67 }