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
;
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.
18 public class FallingSand
extends Mob
{
20 private static final String TAG
= "FallingSand";
23 * Creates a FallingSand mob at coordinates
25 * @param x X in pixels
26 * @param y Y in pixels
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);
34 public float getSpeed() {
44 public void ai(GameWorld gameWorld
, GameItemsHolder gameItemsHolder
, float delta
) {
45 if (mVelocity
.isZero()) {
46 gameWorld
.setForeMap(getMapX(), getMiddleMapY(), gameItemsHolder
.getBlock("sand"));
52 public void changeDir() {
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");
65 spriteBatch
.draw(texture
, x
, y
);