summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 18f9e2e)
raw | patch | inline | side by side (parent: 18f9e2e)
author | fred-boy <fred-boy@protonmail.com> | |
Sun, 30 Sep 2018 14:38:19 +0000 (21:38 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Sun, 30 Sep 2018 14:38:19 +0000 (21:38 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java
index 5f7dfea6e2714ee3306ef5666585b5e6b9997642..48388ac465995e8a9b618234a7729b08110f1e57 100644 (file)
}
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) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index d78d319efaeff1875fa38c6b22c02829e36aeec1..d314b82cda6929bd1581d373294e52e08bfdcca3 100644 (file)
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);
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java
index 3117cde54273bfac17de2cbf6dee429629c42b90..08f44251f6ed20bdca7fa9d38cbcab54c799a647 100644 (file)
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;
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index a0ac68a2c4ae6b73041a42d7c055bf0650465191..96f8c786d9a0cb21ce98ef72659545a4f3c96063 100644 (file)
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);
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java
index 21b8dd84f6aa63a58e2ad23de84d0b94389d6f2f..cc3c389840854a30da9091ab1803524daf3188d9 100644 (file)
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
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java
index b491af5dc7dace59f61af69a0a53ab9b4d5986f4..b9108845122a13791d098539cf1d1b7f6dfe52ea 100644 (file)
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
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java
index 137e7cad913516e1cced168e7a9328986b0065e9..67df9f7198fac95681fef3b508f099f202c2e0f8 100644 (file)
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;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java
index c615fcb0191c2828c58877b03454770d192e9dea..38eac46d69d9b70180df37400c86c70038bfbe34 100644 (file)
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
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java
index d92b846250571521dfd33f3f85cd826a35f3f312..fa60f6b60d67f9eec9385988f66da77537c7eed2 100644 (file)
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);
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java
index ad5faafeba30e00907637a1fc1e4ed9aef77b6cd..74f7249c751030d1778e03b55b2c11acec8d1337 100644 (file)
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);
}
}