mGamePhysics = gamePhysics;
mGameInput = gameInput;
mGameRenderer = gameRenderer;
-
- mGameWorld.startFluidsThread();
}
public void update(float delta) {
public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
final float correctedAnimationDelta = mAnimDelta * delta;
- if (mVelocity.x != 0 || Math.abs(Assets.playerSprite[0][2].getRotation()) > Math.abs(correctedAnimationDelta)) {
+ if (mVelocity.x != 0f || Math.abs(Assets.playerSprite[0][2].getRotation()) > Math.abs(correctedAnimationDelta)) {
Assets.playerSprite[0][2].rotate(correctedAnimationDelta);
Assets.playerSprite[1][2].rotate(-correctedAnimationDelta);
Assets.playerSprite[0][3].rotate(-correctedAnimationDelta);
import ru.deadsoftware.cavedroid.game.mobs.MobsController;
import java.util.Arrays;
+import java.util.TimerTask;
import static ru.deadsoftware.cavedroid.game.GameItems.*;
-class GameFluidsThread extends Thread {
+class GameFluidsThread extends TimerTask {
- private static final int FLUID_UPDATE_INTERVAL_MS = 100;
+ public static final int FLUID_UPDATE_INTERVAL_MS = 100;
private static final int FLUID_STATES = 5;
private static final int[] WATER_IDS = {8, 60, 61, 62, 63};
@Override
public void run() {
- while (!this.isInterrupted() && mMainThread.isAlive()) {
- if (timeToUpdate()) {
- fluidUpdater();
- }
- }
+ fluidUpdater();
}
}
import javax.annotation.CheckForNull;
import javax.inject.Inject;
+import java.sql.Time;
+import java.util.Timer;
@GameScope
public class GameWorld implements Disposable {
private final DropController mDropController;
private final MobsController mMobsController;
+
+ private final Timer mGameFluidsTimer;
private final GameFluidsThread mGameFluidsThread;
private final int mWidth;
}
mGameFluidsThread = new GameFluidsThread(this, mMobsController, Thread.currentThread());
+
+ mGameFluidsTimer = new Timer();
+ mGameFluidsTimer.scheduleAtFixedRate(mGameFluidsThread, 0, GameFluidsThread.FLUID_UPDATE_INTERVAL_MS);
}
public int getWidth() {
}
mShouldUpdate = false;
}
-
- if (!mGameFluidsThread.isAlive()) {
- mGameFluidsThread.start();
- }
- }
-
- public void startFluidsThread() {
- mGameFluidsThread.start();
}
@Override
public void dispose() {
- mGameFluidsThread.interrupt();
+ mGameFluidsTimer.cancel();
}
}
\ No newline at end of file