summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d7f5950)
raw | patch | inline | side by side (parent: d7f5950)
author | fred-boy <fred-boy@protonmail.com> | |
Sat, 17 Nov 2018 18:34:36 +0000 (01:34 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Sat, 17 Nov 2018 18:34:36 +0000 (01:34 +0700) |
18 files changed:
diff --git a/android/src/ru/deadsoftware/cavecraft/AndroidLauncher.java b/android/src/ru/deadsoftware/cavecraft/AndroidLauncher.java
index aed5e8e09a6c0273100e64b11f4b37bfb6437b86..1a0a92977e992cc5740019034c5a18c9f4f2d7f6 100644 (file)
package ru.deadsoftware.cavecraft;
+import android.content.pm.PackageManager;
import android.os.Bundle;
-
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
-import ru.deadsoftware.cavecraft.CaveGame;
public class AndroidLauncher extends AndroidApplication {
- @Override
- protected void onCreate (Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- config.hideStatusBar = true;
- config.useImmersiveMode = true;
- initialize(new CaveGame(true), config);
- }
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
+ config.hideStatusBar = true;
+ config.useImmersiveMode = true;
+ String gameFolder = null;
+ try {
+ gameFolder = getPackageManager().getPackageInfo(getPackageName(), 0).applicationInfo.dataDir;
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ exit();
+ }
+ initialize(new CaveGame(gameFolder, true), config);
+ }
- @Override
- public void onBackPressed() {
- }
+ @Override
+ public void onBackPressed() {
+ }
}
diff --git a/core/src/ru/deadsoftware/cavecraft/CaveGame.java b/core/src/ru/deadsoftware/cavecraft/CaveGame.java
index 37fd2e109498b1ddddd218045e7e215feddf0f47..b70038b905e60e0ee3584ee535a8255c7baae6b1 100644 (file)
public static boolean TOUCH;
- public CaveGame() {
- this(false);
+ public CaveGame(String gameFolder) {
+ this(gameFolder, false);
}
- public CaveGame(boolean touch) {
+ public CaveGame(String gameFolder, boolean touch) {
+ GAME_FOLDER = gameFolder;
TOUCH = touch;
STATE = AppState.MENU_MAIN;
}
@Override
public void create() {
- switch (Gdx.app.getType()) {
- case Desktop:
- GAME_FOLDER = System.getProperty("user.home") + "/.cavecraft";
- break;
- case Android:
- GAME_FOLDER = "/sdcard/cavecraft";
- break;
- default:
- Gdx.app.exit();
- }
Gdx.app.log("CaveGame", GAME_FOLDER);
Gdx.files.absolute(GAME_FOLDER).mkdirs();
setScreen(new GameScreen());
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java
index 687c6a9e5e6d919f96ab41b7dc0ee5ffbfd1bd06..2b9e1ddb2486ba3c6743e1ff251a3ffb1e30fed7 100644 (file)
}
private boolean checkSwim() {
- 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)));
+ return GameItems.isFluid(gp.world.getForeMap(gp.player.getMapX(), gp.player.getMapY()));
}
private void wasdPressed(int keycode) {
if (gp.ctrlMode == 0 || !CaveGame.TOUCH) {
switch (keycode) {
case Input.Keys.A:
- gp.player.move.x = -GamePhysics.PL_SPEED;
- gp.player.dir = 0;
+ gp.player.mov.x = -GamePhysics.PL_SPEED;
+ gp.player.setDir(0);
if (CaveGame.TOUCH && checkSwim()) gp.swim = true;
break;
case Input.Keys.D:
- gp.player.move.x = GamePhysics.PL_SPEED;
- gp.player.dir = 1;
+ gp.player.mov.x = GamePhysics.PL_SPEED;
+ gp.player.setDir(1);
if (CaveGame.TOUCH && checkSwim()) gp.swim = true;
break;
}
- } else if (CaveGame.TOUCH) {
+ } else {
switch (keycode) {
case Input.Keys.A:
gp.curX--;
if (checkSwim()) {
gp.swim = true;
} else if (gp.player.canJump) {
- gp.player.move.add(0, -7);
+ gp.player.mov.add(0, -7);
} else if (!gp.player.flyMode && gp.player.gameMode == 1) {
gp.player.flyMode = true;
- gp.player.move.y = 0;
+ gp.player.mov.y = 0;
} else if (gp.player.flyMode) {
- gp.player.move.y = -GamePhysics.PL_SPEED;
+ gp.player.mov.y = -GamePhysics.PL_SPEED;
}
break;
case Input.Keys.CONTROL_LEFT:
- gp.player.move.y = GamePhysics.PL_SPEED;
+ gp.player.mov.y = GamePhysics.PL_SPEED;
break;
case Input.Keys.E:
switch (keycode) {
case Input.Keys.A:
case Input.Keys.D:
- gp.player.move.x = 0;
+ gp.player.mov.x = 0;
if (CaveGame.TOUCH && gp.swim) gp.swim = false;
break;
case Input.Keys.SPACE:
case Input.Keys.CONTROL_LEFT:
- if (gp.player.flyMode) gp.player.move.y = 0;
+ if (gp.player.flyMode) gp.player.mov.y = 0;
if (gp.swim) gp.swim = false;
break;
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index b5c5eab20a717acb6a00c1b7e1263b6026961078..8f3e8fe7309f8f679626b2fbf5665f12fb21a8a3 100644 (file)
import java.util.Iterator;
-public class GamePhysics {
+class GamePhysics {
- public static final int PL_SPEED = 2;
+ static final int PL_SPEED = 2;
private GameProc gp;
private Vector2 gravity;
- public GamePhysics(GameProc gp) {
+ GamePhysics(GameProc gp) {
this.gp = gp;
gravity = new Vector2(0, .9f);
}
for (int y = minY; y < maxY; y++) {
for (int x = minX; x < maxX; x++) {
bl = gp.world.getForeMap(x, y);
- if (bl > 0 && GameItems.getBlock(bl).coll) {
+ if (bl > 0 && GameItems.getBlock(bl).hasCollision()) {
if (Intersector.overlaps(rect, GameItems.getBlock(bl).getRect(x, y))) {
return true;
}
if (drop.move.y < 9) drop.move.y += gravity.y / 4;
}
drop.pos.add(drop.move);
- if (drop.pos.x + 8 > gp.world.getWidth() * 16) drop.pos.x -= gp.world.getWidth() * 16;
- else if (drop.pos.x < 0) drop.pos.x += gp.world.getWidth() * 16;
+ if (drop.pos.x + 8 > gp.world.getWidthPx()) drop.pos.x -= gp.world.getWidthPx();
+ else if (drop.pos.x < 0) drop.pos.x += gp.world.getWidthPx();
drop.pos.y = MathUtils.round(drop.pos.y);
while (checkColl(drop.getRect())) {
drop.pos.y--;
}
private void playerPhy(Player pl) {
- pl.pos.y += pl.move.y;
+ pl.pos.y += pl.mov.y;
if (checkColl(pl.getRect())) {
int d = -1;
- if (pl.move.y < 0) d = 1;
+ if (pl.mov.y < 0) d = 1;
if (d == -1) {
pl.flyMode = false;
pl.canJump = true;
}
pl.pos.y = MathUtils.round(pl.pos.y);
while (checkColl(pl.getRect())) pl.pos.y += d;
- pl.move.y = 0;
+ pl.mov.y = 0;
} else {
pl.canJump = false;
}
if (GameItems.isFluid(getBlock(pl.getRect()))) {
- if (CaveGame.TOUCH && pl.move.x != 0 && !gp.swim && !pl.flyMode) gp.swim = true;
+ if (CaveGame.TOUCH && pl.mov.x != 0 && !gp.swim && !pl.flyMode) gp.swim = true;
if (!gp.swim) {
- if (!pl.flyMode && pl.move.y < 4.5f) pl.move.add(gravity.x / 4, gravity.y / 4);
- if (!pl.flyMode && pl.move.y > 4.5f) pl.move.add(0, -1f);
+ if (!pl.flyMode && pl.mov.y < 4.5f) pl.mov.add(gravity.x / 4, gravity.y / 4);
+ if (!pl.flyMode && pl.mov.y > 4.5f) pl.mov.add(0, -1f);
} else {
- pl.move.add(0, -.5f);
- if (pl.move.y < -3) pl.move.y = -3;
+ pl.mov.add(0, -.5f);
+ if (pl.mov.y < -3) pl.mov.y = -3;
}
} else {
- if (!pl.flyMode && pl.move.y < 18) pl.move.add(gravity);
+ if (!pl.flyMode && pl.mov.y < 18) pl.mov.add(gravity);
}
- pl.pos.x += pl.move.x;
+ pl.pos.x += pl.mov.x;
if (checkColl(pl.getRect())) {
if (pl.canJump && !pl.flyMode) pl.pos.y -= 8;
if (checkColl(pl.getRect())) {
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;
+ if (pl.mov.x < 0) d = 1;
+ else if (pl.mov.x > 0) d = -1;
pl.pos.x = MathUtils.round(pl.pos.x);
while (checkColl(pl.getRect())) pl.pos.x += d;
}
}
- 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) {
+ if (pl.pos.x + pl.getWidth() / 2 < 0) pl.pos.x += gp.world.getWidthPx();
+ if (pl.pos.x + pl.getWidth() / 2 > gp.world.getWidthPx()) pl.pos.x -= gp.world.getWidthPx();
+ if (pl.pos.y > gp.world.getHeightPx()) {
pl.respawn(gp.world);
}
- if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && pl.move.x != 0) {
- pl.move.add(0, -8);
+ if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.getDir()) && !pl.flyMode && pl.canJump && pl.mov.x != 0) {
+ pl.mov.add(0, -8);
pl.canJump = false;
}
}
private void mobPhy(Mob mob) {
- mob.pos.y += mob.move.y;
+ mob.pos.y += mob.mov.y;
if (checkColl(mob.getRect())) {
int d = -1;
- if (mob.move.y < 0) d = 1;
+ if (mob.mov.y < 0) d = 1;
if (d == -1) mob.canJump = true;
mob.pos.y = MathUtils.round(mob.pos.y);
while (checkColl(mob.getRect())) mob.pos.y += d;
- mob.move.y = 0;
+ mob.mov.y = 0;
if (mob.getType() > 0) {
- gp.world.setForeMap((int) mob.pos.x / 16, (int) mob.pos.y / 16, mob.getType());
- mob.pos.y = -1;
- mob.dead = true;
+ gp.world.setForeMap(mob.getMapX(), mob.getMapY(), mob.getType());
+ mob.kill();
}
} else {
mob.canJump = false;
}
if (mob.getType() == 0 && GameItems.isFluid(getBlock(mob.getRect()))) {
- if (mob.move.y > 9) mob.move.add(0, -.9f);
- mob.move.add(0, -.5f);
- if (mob.move.y < -3) mob.move.y = -3;
- } else if (mob.move.y < 18) mob.move.add(gravity);
+ if (mob.mov.y > 9) mob.mov.add(0, -.9f);
+ mob.mov.add(0, -.5f);
+ if (mob.mov.y < -3) mob.mov.y = -3;
+ } else if (mob.mov.y < 18) mob.mov.add(gravity);
- mob.pos.x += mob.move.x;
+ mob.pos.x += mob.mov.x;
if (checkColl(mob.getRect())) {
if (mob.canJump) {
mob.pos.y -= 8;
if (checkColl(mob.getRect())) {
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;
+ if (mob.mov.x < 0) d = 1;
+ else if (mob.mov.x > 0) d = -1;
mob.pos.x = MathUtils.round(mob.pos.x);
while (checkColl(mob.getRect())) mob.pos.x += d;
if (mob.canJump) mob.changeDir();
}
}
- 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) {
+ if (mob.pos.x + mob.getWidth() / 2 < 0) mob.pos.x += gp.world.getWidthPx();
+ if (mob.pos.x + mob.getWidth() / 2 > gp.world.getWidthPx()) mob.pos.x -= gp.world.getWidthPx();
+ if (mob.pos.y > gp.world.getHeightPx()) {
mob.pos.y = 0;
}
- if (checkJump(mob.getRect(), mob.dir) && mob.canJump && mob.move.x != 0) {
- mob.move.add(0, -8);
+ if (checkJump(mob.getRect(), mob.getDir()) && mob.canJump && mob.mov.x != 0) {
+ mob.mov.add(0, -8);
mob.canJump = false;
}
}
- public void update(float delta) {
+ void update(float delta) {
for (Iterator<Drop> it = gp.drops.iterator(); it.hasNext(); ) {
Drop drop = it.next();
dropPhy(drop);
Mob mob = it.next();
mob.ai();
mobPhy(mob);
- if (mob.dead)
- it.remove();
+ if (mob.isDead()) it.remove();
}
playerPhy(gp.player);
gp.renderer.setCamPos(
- gp.player.pos.x + gp.player.texWidth / 2 - gp.renderer.getWidth() / 2,
- gp.player.pos.y + gp.player.height / 2 - gp.renderer.getHeight() / 2);
+ gp.player.pos.x + (float) gp.player.getWidth() / 2 - gp.renderer.getWidth() / 2,
+ gp.player.pos.y + (float) gp.player.getHeight() / 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 5b497a4ae17b846d794dabf8869940dd48f886d6..dd2c38732f361983f7a8f396b04ff1ada1fb57d3 100644 (file)
private boolean isAutoselectable(int x, int y) {
return (world.getForeMap(x, y) > 0 &&
- GameItems.getBlock(world.getForeMap(x, y)).coll);
+ GameItems.getBlock(world.getForeMap(x, y)).hasCollision());
}
private void moveCursor() {
int pastX = curX, pastY = curY;
if (ctrlMode == 0 && CaveGame.TOUCH) {
- curX = (int) (player.pos.x + player.texWidth / 2) / 16;
- if (player.dir == 0) curX--;
+ curX = player.getMapX();
+ if (player.getDir() == 0) curX--;
else curX++;
- curY = (int) (player.pos.y + player.texWidth) / 16;
+ curY = (int) (player.pos.y + player.getWidth()) / 16;
if (!isAutoselectable(curX, curY)) {
curY++;
}
curY++;
}
if (!isAutoselectable(curX, curY)) {
- if (player.dir == 0) curX++;
+ if (player.getDir() == 0) curX++;
else curX--;
}
} else if (!CaveGame.TOUCH) {
if (curY < 0) curY = 0;
if (curY >= world.getHeight()) curY = world.getHeight() - 1;
if (ctrlMode == 1) {
- if (curX * 16 + 8 < player.pos.x + player.texWidth / 2)
- player.dir = 0;
- if (curX * 16 + 8 > player.pos.x + player.texWidth / 2)
- player.dir = 1;
+ if (curX * 16 + 8 < player.pos.x + player.getWidth() / 2)
+ player.setDir(0);
+ if (curX * 16 + 8 > player.pos.x + player.getWidth() / 2)
+ player.setDir(1);
}
}
if (world.getForeMap(x, y) == 8 || world.getForeMap(x, y) == 60) {
if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 61 && world.getForeMap(x, y + 1) <= 63) ||
- (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
+ (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
world.setForeMap(x, y + 1, 60);
updateBlock(x, y + 2);
} else if (GameItems.isLava(world.getForeMap(x, y + 1))) {
if (world.getForeMap(x, y + 1) > 9) world.setForeMap(x, y + 1, 4);
else world.setForeMap(x, y + 1, 68);
- } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
if (world.getForeMap(x + 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y))) ||
+ (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y))) ||
(GameItems.isWater(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 61)) {
world.setForeMap(x + 1, y, 61);
updateBlock(x + 1, y + 1);
world.setForeMap(x + 1, y, 8);
if (world.getForeMap(x - 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y))) ||
+ (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y))) ||
(GameItems.isWater(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 61)) {
world.setForeMap(x - 1, y, 61);
updateBlock(x - 1, y + 1);
}
if (world.getForeMap(x, y) == 61) {
if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 61 && world.getForeMap(x, y + 1) <= 63) ||
- (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
+ (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
world.setForeMap(x, y + 1, 60);
updateBlock(x, y + 2);
} else if (GameItems.isLava(world.getForeMap(x, y + 1))) {
if (world.getForeMap(x, y + 1) > 9) world.setForeMap(x, y + 1, 4);
else world.setForeMap(x, y + 1, 68);
- } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
if (world.getForeMap(x + 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y))) ||
+ (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y))) ||
(GameItems.isWater(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 62)) {
world.setForeMap(x + 1, y, 62);
updateBlock(x + 1, y + 1);
}
if (world.getForeMap(x - 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y))) ||
+ (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y))) ||
(GameItems.isWater(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 62)) {
world.setForeMap(x - 1, y, 62);
updateBlock(x - 1, y + 1);
}
if (world.getForeMap(x, y) == 62) {
if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 61 && world.getForeMap(x, y + 1) <= 63) ||
- (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
+ (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
world.setForeMap(x, y + 1, 60);
updateBlock(x, y + 2);
} else if (GameItems.isLava(world.getForeMap(x, y + 1))) {
if (world.getForeMap(x, y + 1) > 9) world.setForeMap(x, y + 1, 4);
else world.setForeMap(x, y + 1, 68);
- } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
if (world.getForeMap(x + 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y)))) {
+ (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y)))) {
world.setForeMap(x + 1, y, 63);
updateBlock(x + 1, y + 1);
} else if (GameItems.isLava(world.getForeMap(x + 1, y))) {
}
if (world.getForeMap(x - 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y)))) {
+ (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y)))) {
world.setForeMap(x - 1, y, 63);
updateBlock(x - 1, y + 1);
} else if (GameItems.isLava(world.getForeMap(x - 1, y))) {
}
if (world.getForeMap(x, y) == 63) {
if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 61 && world.getForeMap(x, y + 1) <= 63) ||
- (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
+ (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
world.setForeMap(x, y + 1, 60);
updateBlock(x, y + 2);
} else if (GameItems.isLava(world.getForeMap(x, y + 1))) {
if (world.getForeMap(x, y) == 9 || world.getForeMap(x, y) == 64) {
if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 65 && world.getForeMap(x, y + 1) <= 67) ||
- (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
+ (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
world.setForeMap(x, y + 1, 64);
updateBlock(x, y + 2);
} else if (GameItems.isWater(world.getForeMap(x, y + 1))) {
world.setForeMap(x, y + 1, 1);
- } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
if (world.getForeMap(x + 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y))) ||
+ (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y))) ||
(GameItems.isLava(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 65)) {
world.setForeMap(x + 1, y, 65);
updateBlock(x + 1, y + 1);
}
if (world.getForeMap(x - 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y))) ||
+ (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y))) ||
(GameItems.isLava(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 65)) {
world.setForeMap(x - 1, y, 65);
updateBlock(x - 1, y + 1);
}
if (world.getForeMap(x, y) == 65) {
if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 65 && world.getForeMap(x, y + 1) <= 67) ||
- (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
+ (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
world.setForeMap(x, y + 1, 64);
updateBlock(x, y + 2);
} else if (GameItems.isWater(world.getForeMap(x, y + 1))) {
world.setForeMap(x, y + 1, 1);
- } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
if (world.getForeMap(x + 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y))) ||
+ (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y))) ||
(GameItems.isLava(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 66)) {
world.setForeMap(x + 1, y, 66);
updateBlock(x + 1, y + 1);
}
if (world.getForeMap(x - 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y))) ||
+ (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y))) ||
(GameItems.isLava(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 66)) {
world.setForeMap(x - 1, y, 66);
updateBlock(x - 1, y + 1);
}
if (world.getForeMap(x, y) == 66) {
if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 65 && world.getForeMap(x, y + 1) <= 67) ||
- (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
+ (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
world.setForeMap(x, y + 1, 64);
updateBlock(x, y + 2);
} else if (GameItems.isWater(world.getForeMap(x, y + 1))) {
world.setForeMap(x, y + 1, 1);
- } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
if (world.getForeMap(x + 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y)))) {
+ (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y)))) {
world.setForeMap(x + 1, y, 67);
updateBlock(x + 1, y + 1);
} else if (GameItems.isWater(world.getForeMap(x + 1, y))) {
}
if (world.getForeMap(x - 1, y) == 0 ||
- (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y)))) {
+ (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y)))) {
world.setForeMap(x - 1, y, 67);
updateBlock(x - 1, y + 1);
} else if (GameItems.isWater(world.getForeMap(x - 1, y))) {
}
if (world.getForeMap(x, y) == 67) {
if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 65 && world.getForeMap(x, y + 1) <= 67) ||
- (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
+ (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) {
world.setForeMap(x, y + 1, 64);
updateBlock(x, y + 2);
} else if (GameItems.isWater(world.getForeMap(x, y + 1))) {
private void updateBlock(int x, int y) {
if (world.getForeMap(x, y) == 10) {
- if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
world.setForeMap(x, y, 0);
mobs.add(new FallingSand(x * 16, y * 16));
updateBlock(x, y - 1);
}
if (world.getForeMap(x, y) == 11) {
- if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
world.setForeMap(x, y, 0);
mobs.add(new FallingGravel(x * 16, y * 16));
updateBlock(x, y - 1);
}
}
- if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).rb) {
- if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
+ if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).requiresBlock()) {
+ if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
world.destroyForeMap(x, y, this);
updateBlock(x, y - 1);
}
}
if (world.getForeMap(x, y) == 2) {
- if (world.getForeMap(x, y - 1) > 0 && (GameItems.getBlock(world.getForeMap(x, y - 1)).coll ||
+ if (world.getForeMap(x, y - 1) > 0 && (GameItems.getBlock(world.getForeMap(x, y - 1)).hasCollision() ||
GameItems.isFluid(world.getForeMap(x, y - 1)))) {
world.setForeMap(x, y, 3);
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index 5560bf6853b799b14af11656dcb0e57407507ef6..dc91d62bf419bb687faf40412d825ebb2757025e 100644 (file)
package ru.deadsoftware.cavecraft.game;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import ru.deadsoftware.cavecraft.CaveGame;
import ru.deadsoftware.cavecraft.GameScreen;
private GameProc gp;
- public GameRenderer(GameProc gp, float width, float heigth) {
+ GameRenderer(GameProc gp, float width, float heigth) {
super(width, heigth);
Gdx.gl.glClearColor(0f, .6f, .6f, 1f);
this.gp = gp;
if (maxY > gp.world.getHeight()) maxY = gp.world.getHeight();
for (int y = minY; y < maxY; y++) {
for (int x = minX; x < maxX; x++) {
- if ((gp.world.getForeMap(x, y) == 0 || GameItems.getBlock(gp.world.getForeMap(x, y)).tp)
+ if ((gp.world.getForeMap(x, y) == 0 || GameItems.getBlock(gp.world.getForeMap(x, y)).isTransparent())
&& gp.world.getBackMap(x, y) > 0) {
spriter.draw(
Assets.blockTex[GameItems.getBlock(gp.world.getBackMap(x, y)).getTex()],
Assets.shade.setPosition(drawX(x), drawY(y));
Assets.shade.draw(spriter);
}
- if (gp.world.getForeMap(x, y) > 0 && GameItems.getBlock(gp.world.getForeMap(x, y)).bg) {
+ if (gp.world.getForeMap(x, y) > 0 && GameItems.getBlock(gp.world.getForeMap(x, y)).isBackground()) {
spriter.draw(
Assets.blockTex[GameItems.getBlock(gp.world.getForeMap(x, y)).getTex()],
drawX(x), drawY(y));
if (maxY > gp.world.getHeight()) maxY = gp.world.getHeight();
for (int y = minY; y < maxY; y++) {
for (int x = minX; x < maxX; x++) {
- if (gp.world.getForeMap(x, y) > 0 && !GameItems.getBlock(gp.world.getForeMap(x, y)).bg) {
+ if (gp.world.getForeMap(x, y) > 0 && !GameItems.getBlock(gp.world.getForeMap(x, y)).isBackground()) {
spriter.draw(
Assets.blockTex[GameItems.getBlock(gp.world.getForeMap(x, y)).getTex()],
drawX(x), drawY(y));
}
private void drawMob(Mob mob) {
- mob.draw(spriter,
- mob.pos.x - getCamX() - gp.world.getWidth() * 16, mob.pos.y - getCamY());
- mob.draw(spriter,
- mob.pos.x - getCamX(), mob.pos.y - getCamY());
- mob.draw(spriter,
- mob.pos.x - getCamX() + gp.world.getWidth() * 16, mob.pos.y - getCamY());
+ float mobDrawX = mob.pos.x - getCamX();
+ float mobDrawY = mob.pos.y - getCamY();
+
+ if (mobDrawX + mob.getWidth() - gp.world.getWidthPx() >= 0 && mobDrawX - gp.world.getWidthPx() <= getWidth())
+ mob.draw(spriter, mobDrawX - gp.world.getWidthPx(), mobDrawY);
+
+ if (mobDrawX + mob.getWidth() >= 0 && mobDrawX <= getWidth())
+ mob.draw(spriter, mobDrawX, mobDrawY);
+
+ if (mobDrawX + mob.getWidth() + gp.world.getWidthPx() >= 0 && mobDrawX + gp.world.getWidthPx() <= getWidth())
+ mob.draw(spriter, mobDrawX + gp.world.getWidthPx(), mobDrawY);
}
private void drawDrop(Drop drop) {
switch (GameItems.getItem(drop.getId()).getType()) {
case 0:
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(
- drop.pos.x - getCamX() - gp.world.getWidth() * 16,
+ drop.pos.x - getCamX() - gp.world.getWidthPx(),
drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(
drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(
- drop.pos.x - getCamX() + gp.world.getWidth() * 16,
+ drop.pos.x - getCamX() + gp.world.getWidthPx(),
drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
}
}
private void drawPlayer(Player pl) {
- if (pl.move.x != 0 || Assets.plSprite[0][2].getRotation() != 0) {
+
+ float drawX = pl.pos.x - getCamX() - 2;
+ float drawY = pl.pos.y - getCamY();
+
+ if (pl.mov.x != 0 || Assets.plSprite[0][2].getRotation() != 0) {
Assets.plSprite[0][2].rotate(Player.ANIM_SPEED);
Assets.plSprite[1][2].rotate(-Player.ANIM_SPEED);
Assets.plSprite[0][3].rotate(-Player.ANIM_SPEED);
Player.ANIM_SPEED = -Player.ANIM_SPEED;
//back hand
- Assets.plSprite[1][2].setPosition(
- pl.pos.x - getCamX() - 6,
- pl.pos.y - getCamY());
+ Assets.plSprite[1][2].setPosition(drawX - 6, drawY);
Assets.plSprite[1][2].draw(spriter);
//back leg
- Assets.plSprite[1][3].setPosition(
- pl.pos.x - getCamX() - 6,
- pl.pos.y - getCamY() + 10);
+ Assets.plSprite[1][3].setPosition(drawX - 6, drawY + 10);
Assets.plSprite[1][3].draw(spriter);
//front leg
- Assets.plSprite[0][3].setPosition(
- pl.pos.x - getCamX() - 6,
- pl.pos.y - getCamY() + 10);
+ Assets.plSprite[0][3].setPosition(drawX - 6, drawY + 10);
Assets.plSprite[0][3].draw(spriter);
//head
- spriter.draw(Assets.plSprite[pl.dir][0],
- pl.pos.x - getCamX() - 2,
- pl.pos.y - getCamY() - 2);
+ spriter.draw(Assets.plSprite[pl.getDir()][0], drawX - 2, drawY - 2);
//body
- spriter.draw(Assets.plSprite[pl.dir][1],
- pl.pos.x - getCamX() - 2, pl.pos.y - getCamY() + 8);
+ spriter.draw(Assets.plSprite[pl.getDir()][1], drawX - 2, drawY + 8);
//item in hand
if (pl.inv[gp.slot] > 0) {
float handRotation = MathUtils.degRad * Assets.plSprite[0][2].getRotation();
switch (GameItems.getItem(pl.inv[gp.slot]).getType()) {
case 0:
Assets.blockTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setPosition(
- pl.pos.x - getCamX() - 8 * MathUtils.sin(handRotation),
- pl.pos.y - getCamY() + 6 + 8 * MathUtils.cos(handRotation));
+ drawX - 8 * MathUtils.sin(handRotation),
+ drawY + 6 + 8 * MathUtils.cos(handRotation));
Assets.blockTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].draw(spriter);
break;
default:
- Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].flip((pl.dir == 0), false);
+ Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].flip((pl.getDir() == 0), false);
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setRotation(
- -45 + pl.dir * 90 + Assets.plSprite[0][2].getRotation());
+ -45 + pl.getDir() * 90 + Assets.plSprite[0][2].getRotation());
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setPosition(
- pl.pos.x - getCamX() - 10 + (12 * pl.dir) - 8 * MathUtils.sin(handRotation),
- pl.pos.y - getCamY() + 2 + 8 * MathUtils.cos(handRotation));
+ drawX - 10 + (12 * pl.getDir()) - 8 * MathUtils.sin(handRotation),
+ drawY + 2 + 8 * MathUtils.cos(handRotation));
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);
+ Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].flip((pl.getDir() == 0), false);
break;
}
}
//front hand
- Assets.plSprite[0][2].setPosition(
- pl.pos.x - getCamX() - 6,
- pl.pos.y - getCamY());
+ Assets.plSprite[0][2].setPosition(drawX - 6, drawY);
Assets.plSprite[0][2].draw(spriter);
}
+ @SuppressWarnings("IntegerDivisionInFloatingPointContext")
private void drawCreative() {
- float x = getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2;
- float y = getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2;
+ float x = getWidth() / 2 - (float) Assets.creativeInv.getRegionWidth() / 2;
+ float y = getHeight() / 2 - (float) Assets.creativeInv.getRegionHeight() / 2;
spriter.draw(Assets.creativeInv, x, y);
spriter.draw(Assets.creativeScr, x + 156,
- y + 18 + (gp.creativeScroll * (72 / gp.maxCreativeScroll)));
+ y + 18 + (gp.creativeScroll * (72f / gp.maxCreativeScroll)));
for (int i = gp.creativeScroll * 8; i < gp.creativeScroll * 8 + 40; i++) {
if (i > 0 && i < GameItems.getItemsSize())
switch (GameItems.getItem(i).getType()) {
drawString("FPS: " + GameScreen.FPS, 0, 0);
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);
- drawString("Game mode: " + gp.player.gameMode, 0, 60);
+ drawString("CurX: " + gp.curX, 0, 30);
+ drawString("CurY: " + gp.curY, 0, 40);
+ drawString("Mobs: " + gp.mobs.size(), 0, 50);
+ drawString("Drops: " + gp.drops.size(), 0, 60);
+ drawString("Block: " + GameItems.getBlockKey(gp.world.getForeMap(gp.curX, gp.curY)), 0, 70);
+ drawString("Game mode: " + gp.player.gameMode, 0, 80);
}
spriter.end();
+
+ shaper.begin(ShapeRenderer.ShapeType.Line);
+ shaper.setColor(Color.BLACK);
+ shaper.rect(gp.player.pos.x - getCamX(), gp.player.pos.y - getCamY(), gp.player.getWidth(), gp.player.getHeight());
+ shaper.end();
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java
index a58a73bb1991fb4a485f806ff61c5df26d118de7..25d3660fc1cf29d9a01b25560e9a2b16baaa4a46 100644 (file)
return HEIGHT;
}
+ public float getWidthPx() {
+ return WIDTH * 16f;
+ }
+
+ public float getHeightPx() {
+ return HEIGHT * 16f;
+ }
+
public int[][] getFullForeMap() {
return foreMap;
}
}
public void placeToForeground(int x, int y, int value) {
- if (getForeMap(x, y) == 0 || value == 0 || !GameItems.getBlock(getForeMap(x, y)).coll) {
+ if (getForeMap(x, y) == 0 || value == 0 || !GameItems.getBlock(getForeMap(x, y)).hasCollision()) {
setForeMap(x, y, value);
} else if (GameItems.isSlab(value) && getForeMap(x, y) == value) {
placeSlab(x, y, value);
}
public void placeToBackground(int x, int y, int value) {
- if (value == 0 || (getBackMap(x, y) == 0 && GameItems.getBlock(value).coll) &&
- (!GameItems.getBlock(value).tp || value == 18)) {
+ if (value == 0 || (getBackMap(x, y) == 0 && GameItems.getBlock(value).hasCollision()) &&
+ (!GameItems.getBlock(value).isTransparent() || value == 18)) {
setBackMap(x, y, value);
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java
index cc3c389840854a30da9091ab1803524daf3188d9..23515f40a4079f5d311e666ee3a549f96d6154b0 100644 (file)
package ru.deadsoftware.cavecraft.game.mobs;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.game.GameItems;
import ru.deadsoftware.cavecraft.misc.Assets;
public class FallingGravel extends Mob {
- public FallingGravel(int x, int y) {
- dir = 0;
- pos = new Vector2(x, y);
- move = new Vector2(0, 1);
- width = 16;
- height = 16;
- canJump = false;
- dead = false;
+ public FallingGravel(float x, float y) {
+ super(x, y, 16, 16, 0);
+ mov = new Vector2(0, 1);
}
@Override
spriteBatch.draw(Assets.blockTex[GameItems.getBlock(11).getTex()], x, y);
}
- @Override
- public Rectangle getRect() {
- return new Rectangle(pos.x, pos.y, width, height);
- }
-
@Override
public int getType() {
return 11;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java
index b9108845122a13791d098539cf1d1b7f6dfe52ea..aa12a87561e2a08a25ab5ae184e069111213c97c 100644 (file)
package ru.deadsoftware.cavecraft.game.mobs;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.game.GameItems;
import ru.deadsoftware.cavecraft.misc.Assets;
public class FallingSand extends Mob {
- public FallingSand(int x, int y) {
- dir = 0;
- pos = new Vector2(x, y);
- move = new Vector2(0, 1);
- width = 16;
- height = 16;
- canJump = false;
- dead = false;
+ public FallingSand(float x, float y) {
+ super(x, y, 16, 16, 0);
+ mov = new Vector2(0, 1);
}
@Override
spriteBatch.draw(Assets.blockTex[GameItems.getBlock(10).getTex()], x, y);
}
- @Override
- public Rectangle getRect() {
- return new Rectangle(pos.x, pos.y, width, height);
- }
-
@Override
public int getType() {
return 10;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java
index 67df9f7198fac95681fef3b508f099f202c2e0f8..241f01889b18df12d97c8e91f2037fe307a61736 100644 (file)
public abstract class Mob implements Serializable {
- public int ANIM_SPEED = 6;
+ protected int anim, animSpeed = 6;
+ private float width, height;
+ private int dir;
+
public Vector2 pos;
- public Vector2 move;
- public int width, height, dir, anim;
+ public Vector2 mov;
+ private boolean dead;
+
public boolean canJump;
- public boolean dead;
+
+ protected Mob(float x, float y, float width, float height, int dir) {
+ pos = new Vector2(x, y);
+ this.width = width;
+ this.height = height;
+ canJump = false;
+ dead = false;
+ this.dir = dir;
+ }
+
+ public int getMapX() {
+ return (int) (pos.x + (getWidth() / 2)) / 16;
+ }
+
+ public int getMapY() {
+ return (int) (pos.y + (getHeight() / 2)) / 16;
+ }
+
+ public float getWidth() {
+ return width;
+ }
+
+ public float getHeight() {
+ return height;
+ }
+
+ public int getDir() {
+ return dir;
+ }
+
+ protected void switchDir() {
+ dir = -dir + 1;
+ }
+
+ public boolean isDead() {
+ return dead;
+ }
+
+ public void kill() {
+ dead = true;
+ }
+
+ public Rectangle getRect() {
+ return new Rectangle(pos.x, pos.y, getWidth(), getHeight());
+ }
public abstract void ai();
public abstract void draw(SpriteBatch spriteBatch, float x, float y);
- public abstract Rectangle getRect();
-
public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java
index 38eac46d69d9b70180df37400c86c70038bfbe34..aa3f79763f8791d87f3d90847317cdf6c1483827 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
-import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.misc.Assets;
public class Pig extends Mob {
- public Pig(int x, int y) {
- dir = MathUtils.random(1);
- pos = new Vector2(x, y);
- move = new Vector2(-1 + dir * 2, 0);
- width = 25;
- height = 18;
- canJump = false;
- dead = false;
+ public Pig(float x, float y) {
+ super(x, y, 25, 18, MathUtils.random(1));
+ mov = new Vector2(-1 + getDir() * 2, 0);
}
@Override
public void changeDir() {
- dir = -dir + 1;
- move.x = -1 + 2 * dir;
+ switchDir();
+ mov.x = -1 + 2 * getDir();
}
@Override
public void ai() {
if (MathUtils.randomBoolean(.0025f)) changeDir();
else if (MathUtils.randomBoolean(.0025f)) {
- if (move.x != 0f) move.x = 0;
- else move.x = -1 + 2 * dir;
+ if (mov.x != 0f) mov.x = 0;
+ else mov.x = -1 + 2 * getDir();
}
- if (move.x != 0f) anim += ANIM_SPEED;
+ if (mov.x != 0f) anim += animSpeed;
else anim = 0;
if (anim >= 60 || anim <= -60) {
- ANIM_SPEED = -ANIM_SPEED;
+ animSpeed = -animSpeed;
}
}
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].setPosition(x - 4 + (9 - getDir() * 9), y + 6);
Assets.pigSprite[1][1].draw(spriteBatch);
- Assets.pigSprite[1][1].setPosition(x + 17 - (9 * dir), y + 6);
+ Assets.pigSprite[1][1].setPosition(x + 17 - (9 * getDir()), y + 6);
Assets.pigSprite[1][1].draw(spriteBatch);
//front legs
- Assets.pigSprite[0][1].setPosition(x - 4 + (9 - dir * 9), y + 6);
+ Assets.pigSprite[0][1].setPosition(x - 4 + (9 - getDir() * 9), y + 6);
Assets.pigSprite[0][1].draw(spriteBatch);
- Assets.pigSprite[0][1].setPosition(x + 17 - (9 * dir), y + 6);
+ Assets.pigSprite[0][1].setPosition(x + 17 - (9 * getDir()), y + 6);
Assets.pigSprite[0][1].draw(spriteBatch);
//head & body
- spriteBatch.draw(Assets.pigSprite[dir][0], x, y);
- }
-
- @Override
- public Rectangle getRect() {
- return new Rectangle(pos.x, pos.y, width, height);
+ spriteBatch.draw(Assets.pigSprite[getDir()][0], x, y);
}
@Override
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java
index 8d27235a4fc941f87309855bf6c85e6e09538ed9..58714852ea514847d09c29bc68a7e913b2f99b55 100644 (file)
private int tex;
private int hp, drop;
- public boolean coll, bg, tp, rb;
+ //coll - collision, bg - background, tp - transparent, rb - requires block under it
+ private boolean coll, bg, tp, rb;
public Block(int tex, int hp, int drop) {
this(0, 0, 16, 16, tex, hp, drop, true, false, false, false);
this.rb = rb;
}
+ public boolean hasCollision() {
+ return coll;
+ }
+
+ public boolean isBackground() {
+ return bg;
+ }
+
+ public boolean isTransparent() {
+ return tp;
+ }
+
+ public boolean requiresBlock() {
+ return rb;
+ }
+
public int getTex() {
return tex;
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java
index 271be8c88389cc863eb8c897fc9c2696cc97660b..d2139c76bef1008a45b8bee9916099d77bf90fba 100644 (file)
import java.io.Serializable;
public class Drop implements Serializable {
+
private int id;
public boolean pickedUp = false;
public Vector2 move, pos;
}
public int closeToPlayer(GameProc gp) {
- boolean c1 = Intersector.overlaps(new Rectangle(gp.player.pos.x - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
- boolean c2 = Intersector.overlaps(new Rectangle((gp.player.pos.x + gp.world.getWidth() * 16) - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
- boolean c3 = Intersector.overlaps(new Rectangle((gp.player.pos.x - gp.world.getWidth() * 16) - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
+ boolean c1 = Intersector.overlaps(new Rectangle(gp.player.pos.x - 16, gp.player.pos.y - 16, gp.player.getWidth() + 32, gp.player.getHeight() + 32), getRect());
+ boolean c2 = Intersector.overlaps(new Rectangle((gp.player.pos.x + gp.world.getWidthPx()) - 16, gp.player.pos.y - 16, gp.player.getWidth() + 32, gp.player.getHeight() + 32), getRect());
+ boolean c3 = Intersector.overlaps(new Rectangle((gp.player.pos.x - gp.world.getWidthPx()) - 16, gp.player.pos.y - 16, gp.player.getWidth() + 32, gp.player.getHeight() + 32), getRect());
if (c1) return 1;
if (c2) return 2;
if (c3) return 3;
float py = gp.player.pos.y;
switch (ctp) {
case 2:
- px += gp.world.getWidth() * 16;
+ px += gp.world.getWidthPx();
break;
case 3:
- px -= gp.world.getWidth() * 16;
+ px -= gp.world.getWidthPx();
break;
}
float dx = 0, dy = 0;
- if (px + gp.player.texWidth < pos.x + 4) dx = -.5f;
+ if (px + gp.player.getWidth() < pos.x + 4) dx = -.5f;
else if (px > pos.x + 4) dx = .5f;
- if (py + gp.player.height < pos.y + 4) dy = -.5f;
+ if (py + gp.player.getHeight() < pos.y + 4) dy = -.5f;
else if (py > pos.y + 4) dy = .5f;
move.add(dx, dy);
if (move.x > 2) move.x = 1;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java
index 11838d16195e8a3bf5e4c7faad17126704afc85a..5672807cc1205182190ff939d84913adc81f8c55 100644 (file)
public static int ANIM_SPEED = 6;
public Vector2 pos;
- public Vector2 move;
- public int width, height, dir, texWidth, hp;
+ public Vector2 mov;
+ private int width, height, dir, hp;
public boolean canJump;
public int[] inv;
public boolean flyMode = false;
public Player(GameWorld world, int gameMode) {
this.gameMode = gameMode;
- pos = getSpawnPoint(world).cpy();
- move = new Vector2(0, 0);
+ mov = new Vector2(0, 0);
width = 4;
height = 30;
- texWidth = 8;
inv = new int[9];
hp = 20;
+ pos = getSpawnPoint(world).cpy();
}
public void respawn(GameWorld world) {
pos.set(getSpawnPoint(world));
- move.setZero();
+ mov.setZero();
hp = 20;
}
world.setForeMap(x, y, 1);
break;
}
- if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).coll) break;
+ if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).hasCollision()) break;
}
- x = x * 16 + texWidth / 2;
- y = y * 16 - height;
- return new Vector2(x, y);
+ return new Vector2(x * 16 + 8 - (float) getWidth() / 2, (float) y * 16 - getHeight());
+ }
+
+ public int getMapX() {
+ return (int) (pos.x + (getWidth() / 2)) / 16;
+ }
+
+ public int getMapY() {
+ return (int) (pos.y + (getHeight() / 2)) / 16;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public int getHp() {
+ return hp;
+ }
+
+ public void setHp(int hp) {
+ this.hp = hp;
+ }
+
+ public int getDir() {
+ return dir;
+ }
+
+ public void setDir(int dir) {
+ this.dir = dir;
}
public Rectangle getRect() {
- return new Rectangle(pos.x + 2, pos.y, width, height);
+ return new Rectangle(pos.x, pos.y, getWidth(), getHeight());
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java
index 8aaab64c9d97c8a32c2fcf487890495d03b3b0ff..7a660e768a3e995d7a136b8eb22024b3b054c61d 100644 (file)
(button.getY() + button.getHeight() / 2) - Assets.getStringHeight(button.getLabel()) / 2);
}
- private void drawMenuMain() {
- for (Button button : menuMainBtns) {
+ private void drawButtons(Array<Button> buttons) {
+ for (Button button : buttons) {
if (button.getType() > 0) {
if (button.getRect().contains(Gdx.input.getX() * getWidth() / GameScreen.getWidth(),
- Gdx.input.getY() * getHeight() / GameScreen.getHeight()))
+ Gdx.input.getY() * getHeight() / GameScreen.getHeight()) &&
+ (!CaveGame.TOUCH || Gdx.input.isTouched()))
button.setType(2);
else button.setType(1);
}
}
}
- private void drawMenuNewGame() {
- for (Button button : menuNGBtns) {
- if (button.getType() > 0) {
- if (button.getRect().contains(Gdx.input.getX() * getWidth() / GameScreen.getWidth(),
- Gdx.input.getY() * getHeight() / GameScreen.getHeight()))
- button.setType(2);
- else button.setType(1);
- }
- drawButton(button);
- }
- }
-
- public void drawLabel(String str) {
+ private void drawLabel(String str) {
drawString(str);
}
@Override
public void render() {
spriter.begin();
- for (int x = 0; x <= getWidth() / 16; x++)
+ for (int x = 0; x <= getWidth() / 16; x++) {
for (int y = 0; y <= getHeight() / 16; y++) {
spriter.draw(Assets.blockTex[GameItems.getBlock(3).getTex()], x * 16, y * 16);
spriter.draw(Assets.shade, x * 16, y * 16);
}
+ }
spriter.draw(Assets.gameLogo, getWidth() / 2 - Assets.gameLogo.getWidth() / 2, 0);
switch (CaveGame.STATE) {
case MENU_MAIN:
- drawMenuMain();
+ drawButtons(menuMainBtns);
break;
case MENU_NEW_GAME:
- drawMenuNewGame();
+ drawButtons(menuNGBtns);
break;
case GOTO_NEW_GAME:
case GOTO_LOAD_GAME:
diff --git a/core/src/ru/deadsoftware/cavecraft/misc/InputHandlerMenu.java b/core/src/ru/deadsoftware/cavecraft/misc/InputHandlerMenu.java
index 5b4d9ba333fbd7a028604bae57bb8568a47eabdd..108da51eb2628bbc0c7f567582f7f5ff41ebdf45 100644 (file)
switch (CaveGame.STATE) {
case MENU_MAIN:
for (Button button : menuRenderer.menuMainBtns) {
- if (button.getRect().contains(screenX, screenY) && button.getType() > 0)
+ if (button.getRect().contains(screenX, screenY) && button.getType() > 0) {
menuRenderer.buttonClicked(button);
+ break;
+ }
}
break;
case MENU_NEW_GAME:
for (Button button : menuRenderer.menuNGBtns) {
- if (button.getRect().contains(screenX, screenY) && button.getType() > 0)
+ if (button.getRect().contains(screenX, screenY) && button.getType() > 0) {
menuRenderer.buttonClicked(button);
+ break;
+ }
}
break;
}
diff --git a/core/src/ru/deadsoftware/cavecraft/misc/Renderer.java b/core/src/ru/deadsoftware/cavecraft/misc/Renderer.java
index c22ec4901f3c37328d70bf84fc594e2f164503cd..0d63d5a21b32945fe2191dc0ef6576941f4e6ba9 100644 (file)
private OrthographicCamera camera;
- public ShapeRenderer shaper;
- public SpriteBatch spriter;
+ protected ShapeRenderer shaper;
+ protected SpriteBatch spriter;
public Renderer() {
this(GameScreen.getWidth(), GameScreen.getHeight());
Assets.mcFont.getData().setScale(scale);
}
- public void setFontColor(int r, int g, int b) {
+ protected void setFontColor(int r, int g, int b) {
Assets.mcFont.setColor(r / 255f, g / 255f, b / 255f, 1f);
}
- public void drawString(String str, float x, float y) {
+ protected void drawString(String str, float x, float y) {
Assets.mcFont.draw(spriter, str, x, y);
}
- public void drawString(String str) {
+ protected void drawString(String str) {
Assets.mcFont.draw(spriter, str,
- getWidth() / 2 - Assets.getStringWidth(str) / 2,
- getHeight() / 2 - Assets.getStringHeight(str) / 2);
+ getWidth() / 2 - (float) Assets.getStringWidth(str) / 2,
+ getHeight() / 2 - (float) Assets.getStringHeight(str) / 2);
}
public abstract void render();
diff --git a/desktop/src/ru/deadsoftware/cavecraft/desktop/DesktopLauncher.java b/desktop/src/ru/deadsoftware/cavecraft/desktop/DesktopLauncher.java
index 470584b238ee39b21f7cb10faab628e97fb4c6e4..492adecc51f8e89f87865510592a904d82b426c6 100644 (file)
config.width = 960;
config.height = 540;
- boolean touch = false;
- for (int i=0; i<arg.length; i++) {
- if (arg[i].equals("--touch")) touch = true;
- }
- new LwjglApplication(new CaveGame(touch), config);
+ boolean touch = false;
+ for (String anArg : arg) {
+ if (anArg.equals("--touch")) touch = true;
+ }
+ new LwjglApplication(new CaveGame(System.getProperty("user.home") + "/.cavecraft", touch), config);
}
}