}
private boolean checkSwim() {
- return (GameItems.isFluid(gp.world.getForeMap((int) (gp.player.position.x + gp.player.width / 2) / 16,
- (int) (gp.player.position.y + gp.player.height / 4 * 3) / 16)));
+ return (GameItems.isFluid(gp.world.getForeMap((int) (gp.player.pos.x + gp.player.width / 2) / 16,
+ (int) (gp.player.pos.y + gp.player.height / 4 * 3) / 16)));
}
private void wasdPressed(int keycode) {
private void dropPhy(Drop drop) {
if (drop.move.y < 9) drop.move.y += gravity.y / 4;
- drop.position.add(drop.move);
- drop.position.y = MathUtils.round(drop.position.y);
+ drop.pos.add(drop.move);
+ drop.pos.y = MathUtils.round(drop.pos.y);
while (checkColl(drop.getRect())) {
- drop.position.y--;
+ drop.pos.y--;
drop.move.y = 0;
}
}
private void playerPhy(Player pl) {
- pl.position.y += pl.move.y;
+ pl.pos.y += pl.move.y;
if (checkColl(pl.getRect())) {
int d = -1;
if (pl.move.y < 0) d = 1;
pl.flyMode = false;
pl.canJump = true;
}
- pl.position.y = MathUtils.round(pl.position.y);
- while (checkColl(pl.getRect())) pl.position.y += d;
+ pl.pos.y = MathUtils.round(pl.pos.y);
+ while (checkColl(pl.getRect())) pl.pos.y += d;
pl.move.y = 0;
} else {
pl.canJump = false;
if (!pl.flyMode && pl.move.y < 18) pl.move.add(gravity);
}
- pl.position.x += pl.move.x;
+ pl.pos.x += pl.move.x;
if (checkColl(pl.getRect())) {
- if (pl.canJump && !pl.flyMode) pl.position.y -= 8;
+ if (pl.canJump && !pl.flyMode) pl.pos.y -= 8;
if (checkColl(pl.getRect())) {
- if (pl.canJump && !pl.flyMode) pl.position.y += 8;
+ if (pl.canJump && !pl.flyMode) pl.pos.y += 8;
int d = 0;
if (pl.move.x < 0) d = 1;
else if (pl.move.x > 0) d = -1;
- pl.position.x = MathUtils.round(pl.position.x);
- while (checkColl(pl.getRect())) pl.position.x += d;
+ pl.pos.x = MathUtils.round(pl.pos.x);
+ while (checkColl(pl.getRect())) pl.pos.x += d;
}
}
- if (pl.position.x + pl.texWidth / 2 < 0) pl.position.x += gp.world.getWidth() * 16;
- if (pl.position.x + pl.texWidth / 2 > gp.world.getWidth() * 16)
- pl.position.x -= gp.world.getWidth() * 16;
- if (pl.position.y > gp.world.getHeight() * 16) {
- pl.position = gp.world.getSpawnPoint().cpy();
+ if (pl.pos.x + pl.texWidth / 2 < 0) pl.pos.x += gp.world.getWidth() * 16;
+ if (pl.pos.x + pl.texWidth / 2 > gp.world.getWidth() * 16)
+ pl.pos.x -= gp.world.getWidth() * 16;
+ if (pl.pos.y > gp.world.getHeight() * 16) {
+ pl.pos = gp.world.getSpawnPoint().cpy();
}
if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && pl.move.x != 0) {
pl.move.add(0, -8);
}
private void mobPhy(Mob mob) {
- mob.position.y += mob.move.y;
+ mob.pos.y += mob.move.y;
if (checkColl(mob.getRect())) {
int d = -1;
if (mob.move.y < 0) d = 1;
if (d == -1) mob.canJump = true;
- mob.position.y = MathUtils.round(mob.position.y);
- while (checkColl(mob.getRect())) mob.position.y += d;
+ mob.pos.y = MathUtils.round(mob.pos.y);
+ while (checkColl(mob.getRect())) mob.pos.y += d;
mob.move.y = 0;
if (mob.getType() > 0) {
- gp.world.setForeMap((int) mob.position.x / 16, (int) mob.position.y / 16, mob.getType());
- mob.position.y = -1;
+ gp.world.setForeMap((int) mob.pos.x / 16, (int) mob.pos.y / 16, mob.getType());
+ mob.pos.y = -1;
mob.dead = true;
}
} else {
if (mob.move.y < -3) mob.move.y = -3;
} else if (mob.move.y < 18) mob.move.add(gravity);
- mob.position.x += mob.move.x;
+ mob.pos.x += mob.move.x;
if (checkColl(mob.getRect())) {
if (mob.canJump) {
- mob.position.y -= 8;
+ mob.pos.y -= 8;
}
if (checkColl(mob.getRect())) {
- if (mob.canJump) mob.position.y += 8;
+ if (mob.canJump) mob.pos.y += 8;
int d = 0;
if (mob.move.x < 0) d = 1;
else if (mob.move.x > 0) d = -1;
- mob.position.x = MathUtils.round(mob.position.x);
- while (checkColl(mob.getRect())) mob.position.x += d;
+ mob.pos.x = MathUtils.round(mob.pos.x);
+ while (checkColl(mob.getRect())) mob.pos.x += d;
if (mob.canJump) mob.changeDir();
}
}
- if (mob.position.x + mob.width / 2 < 0) mob.position.x += gp.world.getWidth() * 16;
- if (mob.position.x + mob.width / 2 > gp.world.getWidth() * 16)
- mob.position.x -= gp.world.getWidth() * 16;
- if (mob.position.y > gp.world.getHeight() * 16) {
- mob.position.y = 0;
+ if (mob.pos.x + mob.width / 2 < 0) mob.pos.x += gp.world.getWidth() * 16;
+ if (mob.pos.x + mob.width / 2 > gp.world.getWidth() * 16)
+ mob.pos.x -= gp.world.getWidth() * 16;
+ if (mob.pos.y > gp.world.getHeight() * 16) {
+ mob.pos.y = 0;
}
if (checkJump(mob.getRect(), mob.dir) && mob.canJump && mob.move.x != 0) {
mob.move.add(0, -8);
playerPhy(gp.player);
gp.renderer.setCamPos(
- gp.player.position.x + gp.player.texWidth / 2 - gp.renderer.getWidth() / 2,
- gp.player.position.y + gp.player.height / 2 - gp.renderer.getHeight() / 2);
+ gp.player.pos.x + gp.player.texWidth / 2 - gp.renderer.getWidth() / 2,
+ gp.player.pos.y + gp.player.height / 2 - gp.renderer.getHeight() / 2);
}
}
private void moveCursor() {
int pastX = curX, pastY = curY;
if (ctrlMode == 0 && CaveGame.TOUCH) {
- curX = (int) (player.position.x + player.texWidth / 2) / 16;
+ curX = (int) (player.pos.x + player.texWidth / 2) / 16;
if (player.dir == 0) curX--;
else curX++;
- curY = (int) (player.position.y + player.texWidth) / 16;
+ curY = (int) (player.pos.y + player.texWidth) / 16;
if (!isAutoselectable(curX, curY)) {
curY++;
}
if (curY < 0) curY = 0;
if (curY >= world.getHeight()) curY = world.getHeight() - 1;
if (ctrlMode == 1) {
- if (curX * 16 + 8 < player.position.x + player.texWidth / 2)
+ if (curX * 16 + 8 < player.pos.x + player.texWidth / 2)
player.dir = 0;
- if (curX * 16 + 8 > player.position.x + player.texWidth / 2)
+ if (curX * 16 + 8 > player.pos.x + player.texWidth / 2)
player.dir = 1;
}
}
private void drawMob(Mob mob) {
mob.draw(spriter,
- mob.position.x - getCamX() - gp.world.getWidth() * 16, mob.position.y - getCamY());
+ mob.pos.x - getCamX() - gp.world.getWidth() * 16, mob.pos.y - getCamY());
mob.draw(spriter,
- mob.position.x - getCamX(), mob.position.y - getCamY());
+ mob.pos.x - getCamX(), mob.pos.y - getCamY());
mob.draw(spriter,
- mob.position.x - getCamX() + gp.world.getWidth() * 16, mob.position.y - getCamY());
+ mob.pos.x - getCamX() + gp.world.getWidth() * 16, mob.pos.y - getCamY());
}
private void drawDrop(Drop drop) {
switch (GameItems.getItem(drop.getId()).getType()) {
case 0:
- Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.position.x - getCamX() - gp.world.getWidth() * 16, drop.position.y - getCamY());
+ Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX() - gp.world.getWidth() * 16, drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
- Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.position.x - getCamX(), drop.position.y - getCamY());
+ Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX(), drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
- Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.position.x - getCamX() + gp.world.getWidth() * 16, drop.position.y - getCamY());
+ Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX() + gp.world.getWidth() * 16, drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
}
}
//back hand
Assets.plSprite[1][2].setPosition(
- pl.position.x - getCamX() - 6,
- pl.position.y - getCamY());
+ pl.pos.x - getCamX() - 6,
+ pl.pos.y - getCamY());
Assets.plSprite[1][2].draw(spriter);
//back leg
Assets.plSprite[1][3].setPosition(
- pl.position.x - getCamX() - 6,
- pl.position.y - getCamY() + 10);
+ pl.pos.x - getCamX() - 6,
+ pl.pos.y - getCamY() + 10);
Assets.plSprite[1][3].draw(spriter);
//front leg
Assets.plSprite[0][3].setPosition(
- pl.position.x - getCamX() - 6,
- pl.position.y - getCamY() + 10);
+ pl.pos.x - getCamX() - 6,
+ pl.pos.y - getCamY() + 10);
Assets.plSprite[0][3].draw(spriter);
//head
spriter.draw(Assets.plSprite[pl.dir][0],
- pl.position.x - getCamX() - 2,
- pl.position.y - getCamY() - 2);
+ pl.pos.x - getCamX() - 2,
+ pl.pos.y - getCamY() - 2);
//body
spriter.draw(Assets.plSprite[pl.dir][1],
- pl.position.x - getCamX() - 2, pl.position.y - getCamY() + 8);
+ pl.pos.x - getCamX() - 2, pl.pos.y - getCamY() + 8);
//item in hand
if (pl.inv[gp.slot] > 0)
switch (GameItems.getItem(pl.inv[gp.slot]).getType()) {
case 0:
Assets.blockTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setPosition(
- pl.position.x - getCamX() - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()),
- pl.position.y - getCamY() + 6 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation()));
+ pl.pos.x - getCamX() - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()),
+ pl.pos.y - getCamY() + 6 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation()));
Assets.blockTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].draw(spriter);
break;
default:
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setRotation(
-45 + pl.dir * 90 + Assets.plSprite[0][2].getRotation());
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setPosition(
- pl.position.x - getCamX() - 10 + (12 * pl.dir) - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()),
- pl.position.y - getCamY() + 2 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation()));
+ pl.pos.x - getCamX() - 10 + (12 * pl.dir) - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()),
+ pl.pos.y - getCamY() + 2 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation()));
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].draw(spriter);
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].flip((pl.dir == 0), false);
break;
}
//front hand
Assets.plSprite[0][2].setPosition(
- pl.position.x - getCamX() - 6,
- pl.position.y - getCamY());
+ pl.pos.x - getCamX() - 6,
+ pl.pos.y - getCamY());
Assets.plSprite[0][2].draw(spriter);
}
if (GameScreen.SHOW_DEBUG) {
drawString("FPS: " + GameScreen.FPS, 0, 0);
- drawString("X: " + (int) (gp.player.position.x / 16), 0, 10);
- drawString("Y: " + (int) (gp.player.position.y / 16), 0, 20);
+ drawString("X: " + (int) (gp.player.pos.x / 16), 0, 10);
+ drawString("Y: " + (int) (gp.player.pos.y / 16), 0, 20);
drawString("Mobs: " + gp.mobs.size(), 0, 30);
drawString("Drops: " + gp.drops.size(), 0, 40);
drawString("Block: " + GameItems.getBlockKey(gp.world.getForeMap(gp.curX, gp.curY)), 0, 50);
public FallingGravel(int x, int y) {
dir = 0;
- position = new Vector2(x, y);
+ pos = new Vector2(x, y);
move = new Vector2(0, 1);
width = 16;
height = 16;
@Override
public Rectangle getRect() {
- return new Rectangle(position.x, position.y, width, height);
+ return new Rectangle(pos.x, pos.y, width, height);
}
@Override
public FallingSand(int x, int y) {
dir = 0;
- position = new Vector2(x, y);
+ pos = new Vector2(x, y);
move = new Vector2(0, 1);
width = 16;
height = 16;
@Override
public Rectangle getRect() {
- return new Rectangle(position.x, position.y, width, height);
+ return new Rectangle(pos.x, pos.y, width, height);
}
@Override
public abstract class Mob implements Serializable {
public int ANIM_SPEED = 6;
- public Vector2 position;
+ public Vector2 pos;
public Vector2 move;
- public int width, height, dir, animation;
+ public int width, height, dir, anim;
public boolean canJump;
public boolean dead;
public Pig(int x, int y) {
dir = MathUtils.random(1);
- position = new Vector2(x, y);
+ pos = new Vector2(x, y);
move = new Vector2(-1 + dir * 2, 0);
width = 25;
height = 18;
if (move.x != 0f) move.x = 0;
else move.x = -1 + 2 * dir;
}
- if (move.x != 0f) animation += ANIM_SPEED;
- else animation = 0;
- if (animation >= 60 || animation <= -60) {
+ if (move.x != 0f) anim += ANIM_SPEED;
+ else anim = 0;
+ if (anim >= 60 || anim <= -60) {
ANIM_SPEED = -ANIM_SPEED;
}
}
@Override
public void draw(SpriteBatch spriteBatch, float x, float y) {
- Assets.pigSprite[0][1].setRotation(animation);
- Assets.pigSprite[1][1].setRotation(-animation);
+ Assets.pigSprite[0][1].setRotation(anim);
+ Assets.pigSprite[1][1].setRotation(-anim);
//back legs
Assets.pigSprite[1][1].setPosition(x - 4 + (9 - dir * 9), y + 6);
Assets.pigSprite[1][1].draw(spriteBatch);
@Override
public Rectangle getRect() {
- return new Rectangle(position.x, position.y, width, height);
+ return new Rectangle(pos.x, pos.y, width, height);
}
@Override
public class Drop implements Serializable {
private int id;
public boolean pickedUp = false;
- public Vector2 move, position;
+ public Vector2 move, pos;
public Drop(float x, float y, int id) {
this.id = id;
- position = new Vector2(x, y);
+ pos = new Vector2(x, y);
move = new Vector2(0, -1);
}
}
public Rectangle getRect() {
- return new Rectangle(position.x, position.y, 8, 8);
+ return new Rectangle(pos.x, pos.y, 8, 8);
}
}
public static int ANIM_SPEED = 6;
- public Vector2 position;
+ public Vector2 pos;
public Vector2 move;
public int width, height, dir, texWidth;
public boolean canJump;
public boolean flyMode = false;
public Player(Vector2 spawnPoint) {
- position = spawnPoint.cpy();
+ pos = spawnPoint.cpy();
move = new Vector2(0, 0);
width = 4;
height = 30;
}
public Rectangle getRect() {
- return new Rectangle(position.x + 2, position.y, width, height);
+ return new Rectangle(pos.x + 2, pos.y, width, height);
}
}