if (checkSwim()) {
mPlayer.swim = true;
} else if (mPlayer.canJump()) {
- mPlayer.getMove().add(0, -7);
+ mPlayer.getVelocity().add(0, -7);
} else if (!mPlayer.isFlyMode() && mPlayer.gameMode == 1) {
mPlayer.setFlyMode(true);
- mPlayer.getMove().y = 0;
+ mPlayer.getVelocity().y = 0;
} else if (mPlayer.isFlyMode()) {
- mPlayer.getMove().y = -GamePhysics.PL_SPEED;
+ mPlayer.getVelocity().y = -GamePhysics.PL_SPEED;
}
}
if (mControlMode == ControlMode.WALK || !mMainConfig.isTouch()) {
switch (keycode) {
case Input.Keys.A:
- mPlayer.getMove().x = -GamePhysics.PL_SPEED;
+ mPlayer.getVelocity().x = -GamePhysics.PL_SPEED;
mPlayer.setDir(Mob.Direction.LEFT);
if (mMainConfig.isTouch() && checkSwim()) {
mPlayer.swim = true;
}
break;
case Input.Keys.D:
- mPlayer.getMove().x = GamePhysics.PL_SPEED;
+ mPlayer.getVelocity().x = GamePhysics.PL_SPEED;
mPlayer.setDir(Mob.Direction.RIGHT);
if (mMainConfig.isTouch() && checkSwim()) {
mPlayer.swim = true;
break;
case Input.Keys.S:
case Input.Keys.CONTROL_LEFT:
- mPlayer.getMove().y = GamePhysics.PL_SPEED;
+ mPlayer.getVelocity().y = GamePhysics.PL_SPEED;
break;
}
} else {
switch (keycode) {
case Input.Keys.A:
case Input.Keys.D:
- mPlayer.getMove().x = 0;
+ mPlayer.getVelocity().x = 0;
if (mMainConfig.isTouch() && mPlayer.swim) {
mPlayer.swim = false;
}
case Input.Keys.SPACE:
case Input.Keys.CONTROL_LEFT:
if (mPlayer.isFlyMode()) {
- mPlayer.getMove().y = 0;
+ mPlayer.getVelocity().y = 0;
}
if (mPlayer.swim) {
mPlayer.swim = false;
if (dropToPlayer > 0) {
drop.moveToPlayer(mGameWorld, mMobsController.getPlayer(), dropToPlayer);
} else {
- if (drop.getMove().x >= .5f) {
- drop.getMove().x -= .5f;
- } else if (drop.getMove().x <= -.5f) {
- drop.getMove().x += .5f;
+ if (drop.getVelocity().x >= .5f) {
+ drop.getVelocity().x -= .5f;
+ } else if (drop.getVelocity().x <= -.5f) {
+ drop.getVelocity().x += .5f;
} else {
- drop.getMove().x = 0;
+ drop.getVelocity().x = 0;
}
- if (drop.getMove().y < 9) {
- drop.getMove().y += gravity.y / 4;
+ if (drop.getVelocity().y < 9) {
+ drop.getVelocity().y += gravity.y / 4;
}
}
drop.move();
if (checkColl(drop)) {
- drop.getMove().set(0, -1);
+ drop.getVelocity().set(0, -1);
do {
drop.move();
} while (checkColl(drop));
- drop.getMove().setZero();
+ drop.getVelocity().setZero();
}
}
int d = 0;
- if (mob.getMove().x < 0) {
+ if (mob.getVelocity().x < 0) {
d = 1;
- } else if (mob.getMove().x > 0) {
+ } else if (mob.getVelocity().x > 0) {
d = -1;
}
if (checkColl(mob)) {
int d = -1;
- if (mob.getMove().y < 0) {
+ if (mob.getVelocity().y < 0) {
d = 1;
}
mob.y += d;
}
- mob.getMove().y = 0;
+ mob.getVelocity().y = 0;
} else {
mob.setCanJump(false);
}
private void playerPhy(Player player) {
- player.y += player.getMove().y;
+ player.y += player.getVelocity().y;
mobYColl(player);
if (player.isDead()) {
}
if (GameItems.isFluid(getBlock(player))) {
- if (mMainConfig.isTouch() && player.getMove().x != 0 && !player.swim && !player.isFlyMode()) {
+ if (mMainConfig.isTouch() && player.getVelocity().x != 0 && !player.swim && !player.isFlyMode()) {
player.swim = true;
}
if (!player.swim) {
- if (!player.isFlyMode() && player.getMove().y < 4.5f) {
- player.getMove().add(gravity.x / 4, gravity.y / 4);
+ if (!player.isFlyMode() && player.getVelocity().y < 4.5f) {
+ player.getVelocity().add(gravity.x / 4, gravity.y / 4);
}
- if (!player.isFlyMode() && player.getMove().y > 4.5f) {
- player.getMove().add(0, -1f);
+ if (!player.isFlyMode() && player.getVelocity().y > 4.5f) {
+ player.getVelocity().add(0, -1f);
}
} else {
- player.getMove().add(0, -.5f);
- if (player.getMove().y < -3) {
- player.getMove().y = -3;
+ player.getVelocity().add(0, -.5f);
+ if (player.getVelocity().y < -3) {
+ player.getVelocity().y = -3;
}
}
} else {
- if (!player.isFlyMode() && player.getMove().y < 18) {
- player.getMove().add(gravity);
+ if (!player.isFlyMode() && player.getVelocity().y < 18) {
+ player.getVelocity().add(gravity);
}
}
- player.x += player.getMove().x * (player.isFlyMode() ? 1.5f : 1) *
+ player.x += player.getVelocity().x * (player.isFlyMode() ? 1.5f : 1) *
(GameItems.isFluid(getBlock(player)) && !player.isFlyMode() ? .8f : 1);
mobXColl(player);
- if (mMainConfig.isTouch() && !player.isFlyMode() && player.canJump() && player.getMove().x != 0 && checkJump(player)) {
- player.getMove().add(0, -8);
+ if (mMainConfig.isTouch() && !player.isFlyMode() && player.canJump() && player.getVelocity().x != 0 && checkJump(player)) {
+ player.getVelocity().add(0, -8);
player.setCanJump(false);
}
}
private void mobPhy(Mob mob) {
if (mob.getType() == Mob.Type.MOB && GameItems.isFluid(getBlock(mob))) {
- if (mob.getMove().y > 9) {
- mob.getMove().add(0, -.9f);
+ if (mob.getVelocity().y > 9) {
+ mob.getVelocity().add(0, -.9f);
}
- mob.getMove().add(0, -.5f);
+ mob.getVelocity().add(0, -.5f);
- if (mob.getMove().y < -3) {
- mob.getMove().y = -3;
+ if (mob.getVelocity().y < -3) {
+ mob.getVelocity().y = -3;
}
- } else if (!mob.isFlyMode() && mob.getMove().y < 18) {
- mob.getMove().add(gravity);
+ } else if (!mob.isFlyMode() && mob.getVelocity().y < 18) {
+ mob.getVelocity().add(gravity);
}
- mob.y += mob.getMove().y;
+ mob.y += mob.getVelocity().y;
mobYColl(mob);
if (mob.isDead()) {
return;
}
- mob.x += mob.getMove().x;
+ mob.x += mob.getVelocity().x;
mobXColl(mob);
- if (mob.canJump() && mob.getMove().x != 0 && checkJump(mob)) {
- mob.getMove().add(0, -8);
+ if (mob.canJump() && mob.getVelocity().x != 0 && checkJump(mob)) {
+ mob.getVelocity().add(0, -8);
mob.setCanJump(false);
}
}
- void update() {
+ void update(float delta) {
Player player = mMobsController.getPlayer();
for (Iterator<Drop> it = mDropController.getIterator(); it.hasNext(); ) {
}
public void update(float delta) {
- mGamePhysics.update();
+ mGamePhysics.update(delta);
mGameInput.update();
mGameWorld.update();
mGameRenderer.render(delta);
*/
public FallingGravel(float x, float y) {
super(x, y, 16, 16, Direction.LEFT, Type.GRAVEL);
- mMove = new Vector2(0, 1);
+ mVelocity = new Vector2(0, 1);
}
@Override
public void ai(GameWorld gameWorld) {
- if (mMove.isZero()) {
+ if (mVelocity.isZero()) {
gameWorld.setForeMap(getMapX(), getMiddleMapY(), 11);
kill();
}
*/
public FallingSand(float x, float y) {
super(x, y, 16, 16, Direction.LEFT, Type.SAND);
- mMove = new Vector2(0, 1);
+ mVelocity = new Vector2(0, 1);
}
@Override
public void ai(GameWorld gameWorld) {
- if (mMove.isZero()) {
+ if (mVelocity.isZero()) {
gameWorld.setForeMap(getMapX(), getMiddleMapY(), 10);
kill();
}
RIGHT
}
- protected Vector2 mMove;
+ protected Vector2 mVelocity;
protected Type mType;
protected int mAnimDelta = 6;
protected int mAnim;
*/
protected Mob(float x, float y, float width, float height, Direction mDirection, Type type) {
super(x, y, width, height);
- mMove = new Vector2(0, 0);
+ mVelocity = new Vector2(0, 0);
mCanJump = false;
mDead = false;
this.mDirection = mDirection;
mDead = true;
}
- public final void move() {
- x += mMove.x;
- y += mMove.y;
+ public final void move(float delta) {
+ x += mVelocity.x * delta;
+ y += mVelocity.y * delta;
}
- public final Vector2 getMove() {
- return mMove;
+ public final Vector2 getVelocity() {
+ return mVelocity;
}
public final boolean canJump() {
public Pig(float x, float y) {
super(x, y, 25, 18, randomDir(), Type.MOB);
- mMove = new Vector2(looksLeft() ? -1 : 1, 0);
+ mVelocity = new Vector2(looksLeft() ? -1 : 1, 0);
}
@Override
public void changeDir() {
switchDir();
- mMove.x = -1 + 2 * dirMultiplier();
+ mVelocity.x = -1 + 2 * dirMultiplier();
}
@Override
public void ai(GameWorld gameWorld) {
if (MathUtils.randomBoolean(.0025f)) {
- if (mMove.x != 0f) {
- mMove.x = 0;
+ if (mVelocity.x != 0f) {
+ mVelocity.x = 0;
} else {
changeDir();
}
}
- if (mMove.x != 0f) {
+ if (mVelocity.x != 0f) {
mAnim += mAnimDelta;
} else {
mAnim = 0;
Vector2 pos = getSpawnPoint(gameWorld);
this.x = pos.x;
this.y = pos.y;
- mMove.setZero();
+ mVelocity.setZero();
}
private Vector2 getSpawnPoint(GameWorld gameWorld) {
@Override
public void draw(SpriteBatch spriteBatch, float x, float y) {
- if (mMove.x != 0 || Assets.playerSprite[0][2].getRotation() != 0) {
+ if (mVelocity.x != 0 || Assets.playerSprite[0][2].getRotation() != 0) {
Assets.playerSprite[0][2].rotate(mAnimDelta);
Assets.playerSprite[1][2].rotate(-mAnimDelta);
Assets.playerSprite[0][3].rotate(-mAnimDelta);
public class Drop extends Rectangle implements Serializable {
private final int id;
- private final Vector2 move;
+ private final Vector2 velocity;
private boolean pickedUp = false;
Drop(float x, float y, int id) {
super(x, y, 8, 8);
this.id = id;
- this.move = new Vector2(0, -1);
+ this.velocity = new Vector2(0, -1);
}
- public Vector2 getMove() {
- return move;
+ public Vector2 getVelocity() {
+ return velocity;
}
public int closeToPlayer(GameWorld gameWorld, Player player) {
dy = .5f;
}
- move.add(dx, dy);
+ velocity.add(dx, dy);
- if (move.x > 2) {
- move.x = 1;
- } else if (move.x < -2) {
- move.x = -1;
+ if (velocity.x > 2) {
+ velocity.x = 1;
+ } else if (velocity.x < -2) {
+ velocity.x = -1;
}
- if (move.y > 2) {
- move.y = 1;
- } else if (move.y < -2) {
- move.y = -1;
+ if (velocity.y > 2) {
+ velocity.y = 1;
+ } else if (velocity.y < -2) {
+ velocity.y = -1;
}
}
}
}
public void move() {
- x += move.x;
- y += move.y;
+ x += velocity.x;
+ y += velocity.y;
checkWorldBounds();
y = MathUtils.round(y);
}