summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (from parent 1: d58d40e)
raw | patch | inline | side by side (from parent 1: d58d40e)
author | fred-boy <fredboy@protonmail.com> | |
Fri, 27 Sep 2019 16:50:14 +0000 (23:50 +0700) | ||
committer | fred-boy <fredboy@protonmail.com> | |
Sun, 29 Sep 2019 04:39:17 +0000 (11:39 +0700) |
23 files changed:
diff --git a/core/src/ru/deadsoftware/cavedroid/CaveGame.java b/core/src/ru/deadsoftware/cavedroid/CaveGame.java
index ca1118675451390d5d289f8469bc6d77d90514df..57704d98f94f56d186c6c2c845f0dfd2f699d8d6 100644 (file)
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
-import ru.deadsoftware.cavedroid.misc.AppState;
+import ru.deadsoftware.cavedroid.misc.states.AppState;
+import ru.deadsoftware.cavedroid.misc.states.GameState;
+import ru.deadsoftware.cavedroid.misc.states.MenuState;
public class CaveGame extends Game {
public static final String VERSION = "alpha 0.4";
public class CaveGame extends Game {
public static final String VERSION = "alpha 0.4";
- public static String GAME_FOLDER;
- public static AppState STATE;
+ public static AppState APP_STATE;
+ public static GameState GAME_STATE;
+ public static MenuState MENU_STATE;
+ public static String GAME_FOLDER;
public static boolean TOUCH;
public CaveGame(String gameFolder) {
public static boolean TOUCH;
public CaveGame(String gameFolder) {
public CaveGame(String gameFolder, boolean touch) {
GAME_FOLDER = gameFolder;
TOUCH = touch;
public CaveGame(String gameFolder, boolean touch) {
GAME_FOLDER = gameFolder;
TOUCH = touch;
- STATE = AppState.MENU_MAIN;
+ APP_STATE = AppState.MENU;
+ MENU_STATE = MenuState.MAIN;
+ GAME_STATE = GameState.PLAY;
}
@Override
}
@Override
diff --git a/core/src/ru/deadsoftware/cavedroid/GameScreen.java b/core/src/ru/deadsoftware/cavedroid/GameScreen.java
index 4717818a46d3f008f2c8383f20350bcce9ac34b4..f741dbd62e06c8511c430043bc3eaa9b5bf61090 100644 (file)
import ru.deadsoftware.cavedroid.game.GameSaver;
import ru.deadsoftware.cavedroid.menu.MenuRenderer;
import ru.deadsoftware.cavedroid.misc.*;
import ru.deadsoftware.cavedroid.game.GameSaver;
import ru.deadsoftware.cavedroid.menu.MenuRenderer;
import ru.deadsoftware.cavedroid.misc.*;
+import ru.deadsoftware.cavedroid.misc.states.AppState;
+import ru.deadsoftware.cavedroid.misc.states.GameState;
+import ru.deadsoftware.cavedroid.misc.states.MenuState;
public class GameScreen implements Screen {
public class GameScreen implements Screen {
+ public static GameProc GP;
+ public static Renderer RENDERER;
+
public static int FPS;
public static boolean SHOW_DEBUG = true;
public static boolean SHOW_MAP = false;
public static int NEW_GAME_MODE = 0;
public static int FPS;
public static boolean SHOW_DEBUG = true;
public static boolean SHOW_MAP = false;
public static int NEW_GAME_MODE = 0;
- public static GameProc GP;
-
- private Renderer renderer;
private MenuRenderer menuRenderer;
public GameScreen() {
Assets.load();
GameItems.load();
menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
private MenuRenderer menuRenderer;
public GameScreen() {
Assets.load();
GameItems.load();
menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
- renderer = menuRenderer;
+ RENDERER = menuRenderer;
Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
}
Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
}
return Gdx.graphics.getHeight();
}
return Gdx.graphics.getHeight();
}
- private void game(float delta) {
- GP.update(delta);
+ private void game() {
+ GP.update();
}
private void menu() {
}
private void menu() {
@Override
public void render(float delta) {
FPS = (int) (1 / delta);
@Override
public void render(float delta) {
FPS = (int) (1 / delta);
- switch (CaveGame.STATE) {
- case GAME_PLAY:
- case GAME_CREATIVE_INV:
- game(delta);
+ switch (CaveGame.APP_STATE) {
+ case GAME:
+ game();
break;
break;
- case MENU_MAIN:
+ case MENU:
menu();
break;
menu();
break;
- case NEW_GAME:
- GP = new GameProc();
- GP.initGame(NEW_GAME_MODE);
- renderer = GP.renderer;
- Gdx.input.setInputProcessor(new InputHandlerGame());
- CaveGame.STATE = AppState.GAME_PLAY;
- break;
-
- case LOAD_GAME:
+ case LOAD:
GP = GameSaver.load();
GP = GameSaver.load();
- renderer = GP.renderer;
+ GP.resetRenderer();
+ RENDERER = GP.renderer;
Gdx.input.setInputProcessor(new InputHandlerGame());
Gdx.input.setInputProcessor(new InputHandlerGame());
- CaveGame.STATE = AppState.GAME_PLAY;
+ CaveGame.APP_STATE = AppState.GAME;
+ CaveGame.GAME_STATE = GameState.PLAY;
break;
break;
- case SAVE_GAME:
+ case SAVE:
GameSaver.save(GP);
GameSaver.save(GP);
- CaveGame.STATE = AppState.MENU_MAIN;
- break;
-
- case GOTO_MENU:
+ CaveGame.APP_STATE = AppState.MENU;
+ CaveGame.MENU_STATE = MenuState.MAIN;
GP.dispose();
menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
GP.dispose();
menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
- renderer = menuRenderer;
+ RENDERER = menuRenderer;
Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
break;
}
Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
break;
}
- renderer.render();
+ RENDERER.render();
}
@Override
public void resize(int width, int height) {
}
@Override
public void resize(int width, int height) {
- switch (CaveGame.STATE) {
- case MENU_MAIN:
+ switch (CaveGame.APP_STATE) {
+ case MENU:
menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
- renderer = menuRenderer;
+ RENDERER = menuRenderer;
break;
break;
- case GAME_PLAY:
- case GAME_CREATIVE_INV:
+ case GAME:
GP.resetRenderer();
GP.resetRenderer();
- renderer = GP.renderer;
+ RENDERER = GP.renderer;
break;
}
}
break;
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java b/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java
index 8f4a891930bc570ce868899a99e965da9329d492..57c74700ee0d894c388f62b549a92ef96360cff2 100644 (file)
package ru.deadsoftware.cavedroid.game;
package ru.deadsoftware.cavedroid.game;
+import com.badlogic.gdx.utils.TimeUtils;
+
import java.util.Arrays;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
import java.util.Arrays;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
}
private boolean timeToUpdate() {
}
private boolean timeToUpdate() {
- if (System.currentTimeMillis() - fluidLastUpdateTimestamp >= FLUID_UPDATE_INTERVAL_MS) {
- fluidLastUpdateTimestamp = System.currentTimeMillis();
+ if (TimeUtils.timeSinceMillis(fluidLastUpdateTimestamp) >= FLUID_UPDATE_INTERVAL_MS) {
+ fluidLastUpdateTimestamp = TimeUtils.millis();
return true;
}
return false;
return true;
}
return false;
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java
index 85d736dd4cd99c1e21d8b3cf7fa0231b6066aa6c..13b2fbf4638b4dbbdbfacd0204b3de39144e974d 100644 (file)
import ru.deadsoftware.cavedroid.CaveGame;
import ru.deadsoftware.cavedroid.GameScreen;
import ru.deadsoftware.cavedroid.game.mobs.Pig;
import ru.deadsoftware.cavedroid.CaveGame;
import ru.deadsoftware.cavedroid.GameScreen;
import ru.deadsoftware.cavedroid.game.mobs.Pig;
-import ru.deadsoftware.cavedroid.misc.AppState;
+import ru.deadsoftware.cavedroid.misc.ControlMode;
+import ru.deadsoftware.cavedroid.misc.states.AppState;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.misc.states.GameState;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
public class GameInput {
private boolean checkSwim() {
import static ru.deadsoftware.cavedroid.GameScreen.GP;
public class GameInput {
private boolean checkSwim() {
- return GameItems.isFluid(GP.world.getForeMap(GP.player.getMapX(), GP.player.getMapY()));
+ return GameItems.isFluid(GP.world.getForeMap(GP.player.getMapX(), GP.player.getLowerMapY()));
}
private boolean insideCreativeInv(int screenX, int screenY) {
}
private boolean insideCreativeInv(int screenX, int screenY) {
}
private void wasdPressed(int keycode) {
}
private void wasdPressed(int keycode) {
- if (GP.ctrlMode == 0 || !CaveGame.TOUCH) {
+ if (GP.controlMode == ControlMode.WALK || !CaveGame.TOUCH) {
switch (keycode) {
case Input.Keys.A:
GP.player.mov.x = -GamePhysics.PL_SPEED;
switch (keycode) {
case Input.Keys.A:
GP.player.mov.x = -GamePhysics.PL_SPEED;
} else switch (keycode) {
case Input.Keys.ALT_LEFT:
if (CaveGame.TOUCH) {
} else switch (keycode) {
case Input.Keys.ALT_LEFT:
if (CaveGame.TOUCH) {
- GP.ctrlMode++;
- if (GP.ctrlMode > 1) GP.ctrlMode = 0;
+ GP.controlMode = GP.controlMode == ControlMode.WALK ? ControlMode.CURSOR : ControlMode.WALK;
}
break;
}
break;
break;
case Input.Keys.E:
break;
case Input.Keys.E:
- if (CaveGame.STATE == AppState.GAME_PLAY) switch (GP.player.gameMode) {
- case 0:
- //TODO survival inv
- break;
- case 1:
- CaveGame.STATE = AppState.GAME_CREATIVE_INV;
- break;
+ if (CaveGame.GAME_STATE == GameState.PLAY){
+ switch (GP.player.gameMode) {
+ case 0:
+ //TODO survival inv
+ break;
+ case 1:
+ CaveGame.GAME_STATE = GameState.CREATIVE_INV;
+ break;
+ }
+ } else {
+ CaveGame.GAME_STATE = GameState.PLAY;
}
}
- else CaveGame.STATE = AppState.GAME_PLAY;
break;
case Input.Keys.G:
break;
case Input.Keys.G:
case Input.Keys.ESCAPE:
case Input.Keys.BACK:
case Input.Keys.ESCAPE:
case Input.Keys.BACK:
- CaveGame.STATE = AppState.GOTO_MENU;
+ CaveGame.APP_STATE = AppState.SAVE;
+ CaveGame.GAME_STATE = GameState.PAUSE;
break;
case Input.Keys.F1:
break;
case Input.Keys.F1:
GP.isKeyDown = false;
}
if (GP.isTouchDown) {
GP.isKeyDown = false;
}
if (GP.isTouchDown) {
- if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && insideCreativeInv(screenX, screenY)) {
+ if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && insideCreativeInv(screenX, screenY)) {
int ix = (int) (screenX - (GP.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18;
int iy = (int) (screenY - (GP.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18;
int item = GP.creativeScroll * 8 + (ix + iy * 8);
if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) item = -1;
if (item >= 0 && item < GameItems.getItemsSize()) {
int ix = (int) (screenX - (GP.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18;
int iy = (int) (screenY - (GP.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18;
int item = GP.creativeScroll * 8 + (ix + iy * 8);
if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) item = -1;
if (item >= 0 && item < GameItems.getItemsSize()) {
- for (int i = 8; i > 0; i--) {
- GP.player.inv[i] = GP.player.inv[i - 1];
- }
- GP.player.inv[0] = item;
+ System.arraycopy(GP.player.inventory, 0, GP.player.inventory, 1, 8);
+ GP.player.inventory[0] = item;
}
}
- } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) {
- CaveGame.STATE = AppState.GAME_PLAY;
+ } else if (CaveGame.GAME_STATE == GameState.CREATIVE_INV) {
+ CaveGame.GAME_STATE = GameState.PLAY;
} else if (screenY < Assets.invBar.getRegionHeight() &&
} else if (screenY < Assets.invBar.getRegionHeight() &&
- screenX > GP.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 &&
- screenX < GP.renderer.getWidth() / 2 + Assets.invBar.getRegionWidth() / 2) {
- GP.player.invSlot = (int) ((screenX - (GP.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2)) / 20);
+ screenX > GP.renderer.getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 &&
+ screenX < GP.renderer.getWidth() / 2 + (float) Assets.invBar.getRegionWidth() / 2) {
+ GP.player.slot = (int) ((screenX - (GP.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2)) / 20);
} else if (button == Input.Buttons.RIGHT) {
GP.useItem(GP.curX, GP.curY,
} else if (button == Input.Buttons.RIGHT) {
GP.useItem(GP.curX, GP.curY,
- GP.player.inv[GP.player.invSlot], false);
+ GP.player.inventory[GP.player.slot], false);
} else if (button == Input.Buttons.LEFT) {
GP.blockDmg = 0;
}
} else if (button == Input.Buttons.LEFT) {
GP.blockDmg = 0;
}
}
public void touchDragged(int screenX, int screenY) {
}
public void touchDragged(int screenX, int screenY) {
- if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && Math.abs(screenY - GP.touchDownY) > 16) {
+ if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && Math.abs(screenY - GP.touchDownY) > 16) {
if (insideCreativeInv(screenX, screenY)) {
GP.creativeScroll -= (screenY - GP.touchDownY) / 16;
GP.touchDownX = screenX;
GP.touchDownY = screenY;
if (GP.creativeScroll < 0) GP.creativeScroll = 0;
if (insideCreativeInv(screenX, screenY)) {
GP.creativeScroll -= (screenY - GP.touchDownY) / 16;
GP.touchDownX = screenX;
GP.touchDownY = screenY;
if (GP.creativeScroll < 0) GP.creativeScroll = 0;
- if (GP.creativeScroll > GP.maxCreativeScroll)
- GP.creativeScroll = GP.maxCreativeScroll;
+ if (GP.creativeScroll > GameProc.MAX_CREATIVE_SCROLL)
+ GP.creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
}
}
}
public void scrolled(int amount) {
}
}
}
public void scrolled(int amount) {
- switch (CaveGame.STATE) {
- case GAME_PLAY:
- GP.player.invSlot += amount;
- if (GP.player.invSlot < 0) GP.player.invSlot = 8;
- if (GP.player.invSlot > 8) GP.player.invSlot = 0;
+ switch (CaveGame.GAME_STATE) {
+ case PLAY:
+ GP.player.slot += amount;
+ if (GP.player.slot < 0) GP.player.slot = 8;
+ if (GP.player.slot > 8) GP.player.slot = 0;
break;
break;
- case GAME_CREATIVE_INV:
+ case CREATIVE_INV:
GP.creativeScroll += amount;
if (GP.creativeScroll < 0) GP.creativeScroll = 0;
GP.creativeScroll += amount;
if (GP.creativeScroll < 0) GP.creativeScroll = 0;
- if (GP.creativeScroll > GP.maxCreativeScroll)
- GP.creativeScroll = GP.maxCreativeScroll;
+ if (GP.creativeScroll > GameProc.MAX_CREATIVE_SCROLL)
+ GP.creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
break;
}
}
break;
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index 86784046014616b1c0d7b1cbbbb4189a9ad343a8..25709bd718aba08ae1a5291c9d16ebddc647aa92 100644 (file)
static final int PL_SPEED = 2;
static final int PL_SPEED = 2;
- private Vector2 gravity = new Vector2(0, .9f);;
+ private Vector2 gravity = new Vector2(0, .9f);
private boolean checkJump(Rectangle rect, int dir) {
int bl;
private boolean checkJump(Rectangle rect, int dir) {
int bl;
while (checkColl(mob.getRect())) mob.pos.y += d;
mob.mov.y = 0;
if (mob.getType() > 0) {
while (checkColl(mob.getRect())) mob.pos.y += d;
mob.mov.y = 0;
if (mob.getType() > 0) {
- GP.world.setForeMap(mob.getMapX(), mob.getMapY(), mob.getType());
+ GP.world.setForeMap(mob.getMapX(), mob.getMiddleMapY(), mob.getType());
mob.kill();
}
} else {
mob.kill();
}
} else {
pl.pos.x += pl.mov.x * (pl.flyMode ? 1.5f : 1) * (GameItems.isFluid(getBlock(pl.getRect())) && !pl.flyMode ? .8f : 1);
mobXColl(pl);
pl.pos.x += pl.mov.x * (pl.flyMode ? 1.5f : 1) * (GameItems.isFluid(getBlock(pl.getRect())) && !pl.flyMode ? .8f : 1);
mobXColl(pl);
- if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.getDir()) && !pl.flyMode && pl.canJump && pl.mov.x != 0) {
+ if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.getDirection()) && !pl.flyMode && pl.canJump && pl.mov.x != 0) {
pl.mov.add(0, -8);
pl.canJump = false;
}
pl.mov.add(0, -8);
pl.canJump = false;
}
mob.pos.x += mob.mov.x;
mobXColl(mob);
mob.pos.x += mob.mov.x;
mobXColl(mob);
- if (checkJump(mob.getRect(), mob.getDir()) && mob.canJump && mob.mov.x != 0) {
+ if (checkJump(mob.getRect(), mob.getDirection()) && mob.canJump && mob.mov.x != 0) {
mob.mov.add(0, -8);
mob.canJump = false;
}
}
mob.mov.add(0, -8);
mob.canJump = false;
}
}
- void update(float delta) {
- //TODO use delta time
+ void update() {
for (Iterator<Drop> it = GP.drops.iterator(); it.hasNext(); ) {
Drop drop = it.next();
dropPhy(drop);
for (Iterator<Drop> it = GP.drops.iterator(); it.hasNext(); ) {
Drop drop = it.next();
dropPhy(drop);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java
index 8ceb7cf80acaa2f65602d6b71bf8c17b184cbe35..b3b0d3f51a186197c5fb5c1b26185f1388b7984e 100644 (file)
import ru.deadsoftware.cavedroid.game.mobs.FallingGravel;
import ru.deadsoftware.cavedroid.game.mobs.FallingSand;
import ru.deadsoftware.cavedroid.game.mobs.Mob;
import ru.deadsoftware.cavedroid.game.mobs.FallingGravel;
import ru.deadsoftware.cavedroid.game.mobs.FallingSand;
import ru.deadsoftware.cavedroid.game.mobs.Mob;
-import ru.deadsoftware.cavedroid.game.mobs.Pig;
import ru.deadsoftware.cavedroid.game.objects.Drop;
import ru.deadsoftware.cavedroid.game.objects.Player;
import ru.deadsoftware.cavedroid.game.objects.Drop;
import ru.deadsoftware.cavedroid.game.objects.Player;
-import ru.deadsoftware.cavedroid.misc.AppState;
+import ru.deadsoftware.cavedroid.misc.ControlMode;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.misc.states.GameState;
import java.io.Serializable;
import java.util.ArrayList;
import java.io.Serializable;
import java.util.ArrayList;
+import static ru.deadsoftware.cavedroid.game.GameItems.*;
+
public class GameProc implements Serializable, Disposable {
public class GameProc implements Serializable, Disposable {
+
+ static final int MAX_CREATIVE_SCROLL = getItemsSize() / 8;
+
+ private static final int WORLD_WIDTH = 1024;
+ private static final int WORLD_HEIGHT = 256;
+ private static final int UPD_RANGE = 16;
+
static boolean DO_UPD = false;
static int UPD_X = -1, UPD_Y = -1;
private transient GameFluidsThread fluidThread;
static boolean DO_UPD = false;
static int UPD_X = -1, UPD_Y = -1;
private transient GameFluidsThread fluidThread;
-
public transient GameWorld world;
public transient GameRenderer renderer;
public transient GameWorld world;
public transient GameRenderer renderer;
- public transient GamePhysics physics;
+ transient GamePhysics physics;
+ public ControlMode controlMode;
public Player player;
public ArrayList<Mob> mobs;
public Player player;
public ArrayList<Mob> mobs;
- public ArrayList<Drop> drops;
+ ArrayList<Drop> drops;
public boolean isTouchDown, isKeyDown;
public boolean isTouchDown, isKeyDown;
- public int ctrlMode, touchDownX, touchDownY, touchDownBtn, keyDownCode;
- public long touchDownTime;
+ public int touchDownX, touchDownY, touchDownBtn, keyDownCode;
+ long touchDownTime;
int curX, curY;
int curX, curY;
- int creativeScroll, maxCreativeScroll;
+ int creativeScroll;
int blockDmg = 0;
int blockDmg = 0;
- public void initGame(int gameMode) {
- world = new GameWorld();
- world.generate(1024, 256);
+ public GameProc(int gameMode) {
+ world = new GameWorld(WORLD_WIDTH, WORLD_HEIGHT);
player = new Player(gameMode);
drops = new ArrayList<>();
mobs = new ArrayList<>();
player = new Player(gameMode);
drops = new ArrayList<>();
mobs = new ArrayList<>();
- for (int i = 0; i < 16; i++) {
- mobs.add(new Pig(i * 256, 196 * 16));
- }
physics = new GamePhysics();
physics = new GamePhysics();
+ controlMode = CaveGame.TOUCH ? ControlMode.WALK : ControlMode.CURSOR;
+ resetRenderer();
+ startFluidThread();
+ }
+ public void resetRenderer() {
int scale = CaveGame.TOUCH ? 320 : 480;
int scale = CaveGame.TOUCH ? 320 : 480;
- if (CaveGame.TOUCH) ctrlMode = 1;
renderer = new GameRenderer(scale, scale * GameScreen.getHeight() / GameScreen.getWidth());
renderer = new GameRenderer(scale, scale * GameScreen.getHeight() / GameScreen.getWidth());
+ }
- maxCreativeScroll = GameItems.getItemsSize() / 8;
-
- createFluidThread();
+ private void startFluidThread() {
+ fluidThread = new GameFluidsThread();
fluidThread.start();
fluidThread.start();
-
- GameSaver.save(this);
}
}
- private void createFluidThread() {
- fluidThread = new GameFluidsThread();
+ private boolean isNotAutoselectable(int x, int y) {
+ return (!world.hasForeAt(x, y) || !world.getForeMapBlock(x, y).hasCollision());
}
}
- public void resetRenderer() {
- if (CaveGame.TOUCH) {
- renderer = new GameRenderer(320,
- 320 * ((float) GameScreen.getHeight() / GameScreen.getWidth()));
- } else {
- renderer = new GameRenderer(480,
- 480 * ((float) GameScreen.getHeight() / GameScreen.getWidth()));
+ private void checkCursorBounds() {
+ if (curY < 0) {
+ curY = 0;
+ } else if (curY >= world.getHeight()) {
+ curY = world.getHeight() - 1;
}
}
- }
- private boolean isAutoselectable(int x, int y) {
- return (world.getForeMap(x, y) > 0 &&
- GameItems.getBlock(world.getForeMap(x, y)).hasCollision());
+ if (controlMode == ControlMode.CURSOR) {
+ if (curX * 16 + 8 < player.pos.x + player.getWidth() / 2) {
+ player.setDir(0);
+ } else {
+ player.setDir(1);
+ }
+ }
}
private void moveCursor() {
}
private void moveCursor() {
- int pastX = curX, pastY = curY;
- if (ctrlMode == 0 && CaveGame.TOUCH) {
+ int pastX = curX;
+ int pastY = curY;
+
+ if (controlMode == ControlMode.WALK && CaveGame.TOUCH) {
curX = player.getMapX();
curX = player.getMapX();
- if (player.getDir() == 0) curX--;
- else curX++;
- curY = (int) (player.pos.y + player.getWidth()) / 16;
- if (!isAutoselectable(curX, curY)) {
+ curY = (int) (player.pos.y + player.getWidth() / 16);
+ while (curY - pastY < 2 && isNotAutoselectable(curX, curY)) {
curY++;
}
curY++;
}
- if (!isAutoselectable(curX, curY)) {
- curY++;
- }
- if (!isAutoselectable(curX, curY)) {
- if (player.getDir() == 0) curX++;
- else curX--;
+ if (!isNotAutoselectable(curX, curY)) {
+ curX += player.looksLeft() ? 1 : -1;
}
} else if (!CaveGame.TOUCH) {
}
} else if (!CaveGame.TOUCH) {
- curX = (int) (Gdx.input.getX() *
- (renderer.getWidth() / GameScreen.getWidth()) + renderer.getCamX()) / 16;
- curY = (int) (Gdx.input.getY() *
- (renderer.getHeight() / GameScreen.getHeight()) + renderer.getCamY()) / 16;
- if ((Gdx.input.getX() *
- (renderer.getWidth() / GameScreen.getWidth()) + renderer.getCamX()) < 0)
- curX--;
+ curX = (int) (Gdx.input.getX() * (renderer.getWidth() / GameScreen.getWidth()) + renderer.getCamX()) / 16;
+ curY = (int) (Gdx.input.getY() * (renderer.getHeight() / GameScreen.getHeight()) + renderer.getCamY()) / 16;
+ if (curX < 0) curX--;
}
}
- if (pastX != curX || pastY != curY) blockDmg = 0;
- }
- private void checkCursorBounds() {
- if (curY < 0) curY = 0;
- if (curY >= world.getHeight()) curY = world.getHeight() - 1;
- if (ctrlMode == 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 (pastX != curX || pastY != curY) {
+ blockDmg = 0;
}
}
+
+ checkCursorBounds();
}
private void updateBlock(int x, int y) {
if (world.getForeMap(x, y) == 10) {
}
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)).hasCollision()) {
+ if (!world.hasForeAt(x, y + 1) || !world.getForeMapBlock(x, y + 1).hasCollision()) {
world.setForeMap(x, y, 0);
mobs.add(new FallingSand(x * 16, y * 16));
updateBlock(x, y - 1);
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) == 11) {
- if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
+ if (!world.hasForeAt(x, y + 1) || !world.getForeMapBlock(x, y + 1).hasCollision()) {
world.setForeMap(x, y, 0);
mobs.add(new FallingGravel(x * 16, y * 16));
updateBlock(x, y - 1);
}
}
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)).requiresBlock()) {
- if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
+ if (world.hasForeAt(x, y) && world.getForeMapBlock(x, y).requiresBlock()) {
+ if (!world.hasForeAt(x, y + 1) || !world.getForeMapBlock(x, y + 1).hasCollision()) {
world.destroyForeMap(x, y);
updateBlock(x, y - 1);
}
}
if (world.getForeMap(x, y) == 2) {
world.destroyForeMap(x, y);
updateBlock(x, y - 1);
}
}
if (world.getForeMap(x, y) == 2) {
- if (world.getForeMap(x, y - 1) > 0 && (GameItems.getBlock(world.getForeMap(x, y - 1)).hasCollision() ||
- GameItems.isFluid(world.getForeMap(x, y - 1)))) {
+ if (world.hasForeAt(x, y - 1) && (world.getForeMapBlock(x, y - 1).hasCollision() ||
+ isFluid(world.getForeMap(x, y - 1)))) {
world.setForeMap(x, y, 3);
}
}
}
world.setForeMap(x, y, 3);
}
}
}
+ private void blockUpdater() {
+ if (DO_UPD) {
+ for (int y = UPD_Y; y < UPD_Y + UPD_RANGE; y++) {
+ for (int x = UPD_X; x < UPD_X + UPD_RANGE; x++) {
+ updateBlock(x, y);
+ }
+ }
+ DO_UPD = false;
+ }
+ }
+
void useItem(int x, int y, int id, boolean bg) {
void useItem(int x, int y, int id, boolean bg) {
+ String key = getItem(id).isBlock() ? getBlockKey(id) : getItemKey(id);
if (id > 0) {
if (id > 0) {
- if (GameItems.getItem(id).isBlock()) {
- if (!bg) world.placeToForeground(x, y, GameItems.getBlockIdByItemId(id));
- else world.placeToBackground(x, y, GameItems.getBlockIdByItemId(id));
+ if (getItem(id).isBlock()) {
+ if (!bg) {
+ world.placeToForeground(x, y, getBlockIdByItemId(id));
+ } else {
+ world.placeToBackground(x, y, getBlockIdByItemId(id));
+ }
} else {
} else {
- switch (id) {
- case 65:
- world.placeToForeground(x, y, 8);
- player.inv[player.invSlot] = 64;
+ switch (key) {
+ case "bucket_water":
+ world.placeToForeground(x, y, getBlockId("water"));
+ player.inventory[player.slot] = getItemId("bucket_empty");
break;
break;
- case 66:
- world.placeToForeground(x, y, 9);
- player.inv[player.invSlot] = 64;
+ case "bucket_lava":
+ world.placeToForeground(x, y, getBlockId("lava"));
+ player.inventory[player.slot] = getItemId("bucket_empty");
break;
}
}
}
}
break;
}
}
}
}
- public void update(float delta) {
- if (DO_UPD) {
- for (int y = UPD_Y; y < UPD_Y + 16; y++)
- for (int x = UPD_X; x < UPD_X + 16; x++) {
- updateBlock(x, y);
- }
- DO_UPD = false;
- }
-
- physics.update(delta);
- moveCursor();
- checkCursorBounds();
-
- if (isTouchDown && touchDownBtn == Input.Buttons.LEFT) {
- if ((world.getForeMap(curX, curY) > 0 && GameItems.getBlock(world.getForeMap(curX, curY)).getHp() >= 0) ||
- (world.getForeMap(curX, curY) == 0 &&
- world.getBackMap(curX, curY) > 0 &&
- GameItems.getBlock(world.getBackMap(curX, curY)).getHp() >= 0)) {
- if (player.gameMode == 0) {
- blockDmg++;
- if (world.getForeMap(curX, curY) > 0) {
- if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
- world.destroyForeMap(curX, curY);
- blockDmg = 0;
- }
- } else if (world.getBackMap(curX, curY) > 0) {
- if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
- world.destroyBackMap(curX, curY);
- blockDmg = 0;
- }
+ private void pressLMB() {
+ if ((world.hasForeAt(curX, curY) && world.getForeMapBlock(curX, curY).getHp() >= 0) ||
+ (!world.hasForeAt(curX, curY) && world.hasBackAt(curX, curY) &&
+ world.getBackMapBlock(curX, curY).getHp() >= 0)) {
+ if (player.gameMode == 0) {
+ blockDmg++;
+ if (world.hasForeAt(curX, curY)) {
+ if (blockDmg >= world.getForeMapBlock(curX, curY).getHp()) {
+ world.destroyForeMap(curX, curY);
+ blockDmg = 0;
}
}
- } else {
- if (world.getForeMap(curX, curY) > 0) world.placeToForeground(curX, curY, 0);
- else if (world.getBackMap(curX, curY) > 0) world.placeToBackground(curX, curY, 0);
- isTouchDown = false;
+ } else if (world.hasBackAt(curX, curY)) {
+ if (blockDmg >= world.getBackMapBlock(curX, curY).getHp()) {
+ world.destroyBackMap(curX, curY);
+ blockDmg = 0;
+ }
+ }
+ } else {
+ if (world.hasForeAt(curX, curY)) {
+ world.placeToForeground(curX, curY, 0);
+ } else if (world.hasBackAt(curX, curY)) {
+ world.placeToBackground(curX, curY, 0);
}
}
+ isTouchDown = false;
}
}
}
}
+ }
- if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) {
- if (touchDownBtn == Input.Buttons.RIGHT) {
- useItem(curX, curY, player.inv[player.invSlot], true);
- isTouchDown = false;
- } else if (touchDownY < Assets.invBar.getRegionHeight() &&
+ private void holdMB() {
+ if (touchDownBtn == Input.Buttons.RIGHT) {
+ useItem(curX, curY, player.inventory[player.slot], true);
+ isTouchDown = false;
+ } else if (touchDownBtn == Input.Buttons.LEFT) {
+ if (touchDownY < Assets.invBar.getRegionHeight() &&
touchDownX > renderer.getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 &&
touchDownX < renderer.getWidth() / 2 + (float) Assets.invBar.getRegionWidth() / 2) {
touchDownX > renderer.getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 &&
touchDownX < renderer.getWidth() / 2 + (float) Assets.invBar.getRegionWidth() / 2) {
- CaveGame.STATE = AppState.GAME_CREATIVE_INV;
+ CaveGame.GAME_STATE= GameState.CREATIVE_INV;
isTouchDown = false;
}
}
isTouchDown = false;
}
}
+ }
- if (fluidThread == null || !fluidThread.isAlive()) {
- createFluidThread();
- fluidThread.start();
- }
+ public void update() {
+ physics.update();
+ moveCursor();
+
+ if (isTouchDown && touchDownBtn == Input.Buttons.LEFT) pressLMB();
+ if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) holdMB();
+ if (fluidThread == null || !fluidThread.isAlive()) startFluidThread();
}
@Override
}
@Override
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
index 252e77fe144ae79670dd014e9d1b217755692214..c128d85da1c91a1f6dd545fe7c61b1d468cbf408 100644 (file)
import ru.deadsoftware.cavedroid.game.mobs.Mob;
import ru.deadsoftware.cavedroid.game.objects.Drop;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.game.mobs.Mob;
import ru.deadsoftware.cavedroid.game.objects.Drop;
import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.misc.ControlMode;
import ru.deadsoftware.cavedroid.misc.Renderer;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
import ru.deadsoftware.cavedroid.misc.Renderer;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
private void drawBlock(int x, int y, boolean drawBG) {
if (drawBG) {
private void drawBlock(int x, int y, boolean drawBG) {
if (drawBG) {
- if ((GP.world.getForeMap(x, y) == 0 || GameItems.getBlock(GP.world.getForeMap(x, y)).isTransparent())
- && GP.world.getBackMap(x, y) > 0) {
- spriter.draw(GameItems.getBlock(GP.world.getBackMap(x, y)).getTex(), drawX(x), drawY(y));
- if (GP.world.getForeMap(x, y) == 0 && x == GP.curX && y == GP.curY)
+ if ((!GP.world.hasForeAt(x, y) || GP.world.getForeMapBlock(x, y).isTransparent())
+ && GP.world.hasBackAt(x, y)) {
+ spriter.draw(GP.world.getBackMapBlock(x, y).getTex(), drawX(x), drawY(y));
+ if (!GP.world.hasForeAt(x, y) && x == GP.curX && y == GP.curY)
drawWreck(GP.world.getBackMap(GP.curX, GP.curY));
}
}
drawWreck(GP.world.getBackMap(GP.curX, GP.curY));
}
}
- if (GP.world.getForeMap(x, y) > 0 && GameItems.getBlock(GP.world.getForeMap(x, y)).isBackground() == drawBG) {
- spriter.draw(GameItems.getBlock(GP.world.getForeMap(x, y)).getTex(), drawX(x), drawY(y));
+ if (GP.world.hasForeAt(x, y) && GP.world.getForeMapBlock(x, y).isBackground() == drawBG) {
+ spriter.draw(GP.world.getForeMapBlock(x, y).getTex(), drawX(x), drawY(y));
if (x == GP.curX && y == GP.curY)
drawWreck(GP.world.getForeMap(GP.curX, GP.curY));
}
if (x == GP.curX && y == GP.curY)
drawWreck(GP.world.getForeMap(GP.curX, GP.curY));
}
shaper.setColor(0f, 0f, 0f, .5f);
for (int y = minY; y < maxY; y++) {
for (int x = minX; x < maxX; x++) {
shaper.setColor(0f, 0f, 0f, .5f);
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)).isTransparent())
- && GP.world.getBackMap(x, y) > 0)
+ if ((!GP.world.hasForeAt(x, y) || GP.world.getForeMapBlock(x, y).isTransparent())
+ && GP.world.hasBackAt(x, y))
shaper.rect(drawX(x), drawY(y), 16, 16);
}
}
shaper.rect(drawX(x), drawY(y), 16, 16);
}
}
float y = getHeight() / 2 - (float) Assets.creativeInv.getRegionHeight() / 2;
spriter.draw(Assets.creativeInv, x, y);
spriter.draw(Assets.creativeScr, x + 156,
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 * (72f / GP.maxCreativeScroll)));
+ y + 18 + (GP.creativeScroll * (72f / GameProc.MAX_CREATIVE_SCROLL)));
for (int i = GP.creativeScroll * 8; i < GP.creativeScroll * 8 + 40; i++) {
if (i > 0 && i < GameItems.getItemsSize())
if (GameItems.getItem(i).isBlock()) {
for (int i = GP.creativeScroll * 8; i < GP.creativeScroll * 8 + 40; i++) {
if (i > 0 && i < GameItems.getItemsSize())
if (GameItems.getItem(i).isBlock()) {
}
}
for (int i = 0; i < 9; i++) {
}
}
for (int i = 0; i < 9; i++) {
- if (GP.player.inv[i] > 0)
- if (GameItems.getItem(GP.player.inv[i]).isBlock()) {
- spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(GP.player.inv[i])).getTex(),
+ if (GP.player.inventory[i] > 0)
+ if (GameItems.getItem(GP.player.inventory[i]).isBlock()) {
+ spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(GP.player.inventory[i])).getTex(),
x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24);
} else {
x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24);
} else {
- spriter.draw(GameItems.getItem(GP.player.inv[i]).getTex(),
+ spriter.draw(GameItems.getItem(GP.player.inventory[i]).getTex(),
x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24);
}
}
x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24);
}
}
}
private void drawGUI() {
}
private void drawGUI() {
- if (GP.world.getForeMap(GP.curX, GP.curY) > 0 ||
- GP.world.getBackMap(GP.curX, GP.curY) > 0 ||
- GP.ctrlMode == 1 ||
+ if (GP.world.hasForeAt(GP.curX, GP.curY) ||
+ GP.world.hasBackAt(GP.curX, GP.curY) ||
+ GP.controlMode == ControlMode.CURSOR ||
!CaveGame.TOUCH)
spriter.draw(Assets.guiCur,
GP.curX * 16 - getCamX(),
GP.curY * 16 - getCamY());
spriter.draw(Assets.invBar, getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2, 0);
for (int i = 0; i < 9; i++) {
!CaveGame.TOUCH)
spriter.draw(Assets.guiCur,
GP.curX * 16 - getCamX(),
GP.curY * 16 - getCamY());
spriter.draw(Assets.invBar, getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2, 0);
for (int i = 0; i < 9; i++) {
- if (GP.player.inv[i] > 0) {
- if (GameItems.getItem(GP.player.inv[i]).isBlock()) {
- spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(GP.player.inv[i])).getTex(),
+ if (GP.player.inventory[i] > 0) {
+ if (GameItems.getItem(GP.player.inventory[i]).isBlock()) {
+ spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(GP.player.inventory[i])).getTex(),
getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
3);
} else {
getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
3);
} else {
- spriter.draw(GameItems.getItem(GP.player.inv[i]).getTex(),
+ spriter.draw(GameItems.getItem(GP.player.inventory[i]).getTex(),
getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
3);
}
}
}
spriter.draw(Assets.invBarCur,
getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
3);
}
}
}
spriter.draw(Assets.invBarCur,
- getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 - 1 + 20 * GP.player.invSlot,
+ getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 - 1 + 20 * GP.player.slot,
-1);
}
-1);
}
spriter.draw(Assets.touchLMB, getWidth() - 52, getHeight() - 26);
spriter.draw(Assets.touchRMB, getWidth() - 26, getHeight() - 26);
spriter.draw(Assets.touchMode, 78, getHeight() - 26);
spriter.draw(Assets.touchLMB, getWidth() - 52, getHeight() - 26);
spriter.draw(Assets.touchRMB, getWidth() - 26, getHeight() - 26);
spriter.draw(Assets.touchMode, 78, getHeight() - 26);
- if (GP.ctrlMode == 1) {
+ if (GP.controlMode == ControlMode.CURSOR) {
spriter.draw(Assets.shade, 83, getHeight() - 21);
}
}
spriter.draw(Assets.shade, 83, getHeight() - 21);
}
}
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
spriter.begin();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
spriter.begin();
- switch (CaveGame.STATE) {
- case GAME_PLAY:
+ switch (CaveGame.GAME_STATE) {
+ case PLAY:
drawGamePlay();
break;
drawGamePlay();
break;
- case GAME_CREATIVE_INV:
+ case CREATIVE_INV:
drawGamePlay();
drawCreative();
break;
drawGamePlay();
drawCreative();
break;
spriter.end();
spriter.end();
- if(GameScreen.SHOW_MAP) {
+ if (GameScreen.SHOW_MAP) {
//DRAW MAP
shaper.begin(ShapeRenderer.ShapeType.Filled);
shaper.setColor(Color.LIGHT_GRAY);
shaper.rect(0, 0, GP.world.getWidth(), 128);
for (int y = 128; y < 256; y++) {
for (int x = 0; x < getWidth(); x++) {
//DRAW MAP
shaper.begin(ShapeRenderer.ShapeType.Filled);
shaper.setColor(Color.LIGHT_GRAY);
shaper.rect(0, 0, GP.world.getWidth(), 128);
for (int y = 128; y < 256; y++) {
for (int x = 0; x < getWidth(); x++) {
- if (GP.world.getForeMap(x, y) > 0 || GP.world.getBackMap(x, y) > 0) {
+ if (GP.world.hasForeAt(x, y) || GP.world.hasBackAt(x, y)) {
if (GameItems.isWater(GP.world.getForeMap(x, y))) {
shaper.setColor(Color.BLUE);
} else if (GameItems.isLava(GP.world.getForeMap(x, y))) {
shaper.setColor(Color.RED);
} else {
if (GameItems.isWater(GP.world.getForeMap(x, y))) {
shaper.setColor(Color.BLUE);
} else if (GameItems.isLava(GP.world.getForeMap(x, y))) {
shaper.setColor(Color.RED);
} else {
- if (GP.world.getForeMap(x, y) > 0) {
+ if (GP.world.hasForeAt(x, y)) {
shaper.setColor(Color.BLACK);
} else {
shaper.setColor(Color.DARK_GRAY);
shaper.setColor(Color.BLACK);
} else {
shaper.setColor(Color.DARK_GRAY);
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("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("Hand: " + GameItems.getItemKey(GP.player.inv[GP.player.invSlot]), 0, 80);
+ drawString("Hand: " + GameItems.getItemKey(GP.player.inventory[GP.player.slot]), 0, 80);
drawString("Game mode: " + GP.player.gameMode, 0, 90);
}
spriter.end();
drawString("Game mode: " + GP.player.gameMode, 0, 90);
}
spriter.end();
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java b/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java
index edc29e3f01c2ff97b16c60fade7ab31b1fb5921f..0d796b8b3a22583ed5e7e540bcb3b0ebe5bfe6a0 100644 (file)
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
+import org.jetbrains.annotations.NotNull;
import ru.deadsoftware.cavedroid.CaveGame;
import java.io.*;
import ru.deadsoftware.cavedroid.CaveGame;
import java.io.*;
private static final int VERSION = 0;
private static final int VERSION = 0;
+ @NotNull
private static byte[] intToBytes(int i) {
return ByteBuffer.allocate(4).putInt(i).array();
}
private static byte[] intToBytes(int i) {
return ByteBuffer.allocate(4).putInt(i).array();
}
- private static void saveMap(FileHandle file, int[][] map) throws IOException {
+ private static void saveMap(@NotNull FileHandle file, @NotNull int[][] map) throws IOException {
int rl, bl;
int width = map.length;
int height = map[0].length;
int rl, bl;
int width = map.length;
int height = map[0].length;
for (int y = 0; y < height; y++) {
bl = map[0][y];
rl = 0;
for (int y = 0; y < height; y++) {
bl = map[0][y];
rl = 0;
- for (int x = 0; x < width; x++) {
- if (map[x][y] != bl) {
+ for (int[] ints : map) {
+ if (ints[y] != bl) {
out.write(intToBytes(rl));
out.write(intToBytes(bl));
rl = 0;
out.write(intToBytes(rl));
out.write(intToBytes(bl));
rl = 0;
- bl = map[x][y];
+ bl = ints[y];
}
rl++;
}
}
rl++;
}
out.close();
}
out.close();
}
- private static int[][] loadMap(FileHandle file) throws Exception {
+ @NotNull
+ private static int[][] loadMap(@NotNull FileHandle file) throws Exception {
int[][] map;
int ver, width, height;
int rl, bl;
int[][] map;
int ver, width, height;
int rl, bl;
if (VERSION == ver) gameProc = (GameProc) in.readObject();
else throw new Exception("version mismatch");
in.close();
if (VERSION == ver) gameProc = (GameProc) in.readObject();
else throw new Exception("version mismatch");
in.close();
- gameProc.world = new GameWorld();
- gameProc.world.setMaps(
+ gameProc.world = new GameWorld(
loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav")),
loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"))
);
loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav")),
loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"))
);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java
index 9c71cfc306a32ff9aa92dd3b8d318dd3096f9803..e921b98138ceaabcab6db3d9dff559e4aa9113a0 100644 (file)
package ru.deadsoftware.cavedroid.game;
package ru.deadsoftware.cavedroid.game;
+import org.jetbrains.annotations.NotNull;
import ru.deadsoftware.cavedroid.game.objects.Block;
import ru.deadsoftware.cavedroid.game.objects.Drop;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
import ru.deadsoftware.cavedroid.game.objects.Block;
import ru.deadsoftware.cavedroid.game.objects.Drop;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
+@SuppressWarnings("WeakerAccess")
public class GameWorld {
private int WIDTH, HEIGHT;
private int[][] foreMap;
private int[][] backMap;
public class GameWorld {
private int WIDTH, HEIGHT;
private int[][] foreMap;
private int[][] backMap;
+ GameWorld(int width, int height) {
+ WIDTH = width;
+ HEIGHT = height;
+ WorldGen.genWorld(WIDTH, HEIGHT);
+ foreMap = WorldGen.getForeMap();
+ backMap = WorldGen.getBackMap();
+ WorldGen.clear();
+ }
+
+ GameWorld(@NotNull int[][] foreMap, @NotNull int[][] backMap) {
+ this.foreMap = foreMap.clone();
+ this.backMap = backMap.clone();
+ WIDTH = foreMap.length;
+ HEIGHT = foreMap[0].length;
+ }
+
public int getWidth() {
return WIDTH;
}
public int getWidth() {
return WIDTH;
}
placeToBackground(x, y, 0);
}
placeToBackground(x, y, 0);
}
- public void generate(int w, int h) {
- WIDTH = w;
- HEIGHT = h;
- WorldGen.genWorld(WIDTH, HEIGHT);
- foreMap = WorldGen.getForeMap();
- backMap = WorldGen.getBackMap();
- WorldGen.clear();
- }
-
- void setMaps(int[][] foreMap, int[][] backMap) {
- this.foreMap = foreMap.clone();
- this.backMap = backMap.clone();
- WIDTH = foreMap.length;
- HEIGHT = foreMap[0].length;
- }
-
}
\ No newline at end of file
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
index b47b600aa517c470d1a7e9a286e76c78627c59b5..f6149ea855ba7ace63aa3f58f4013de8250df0e1 100644 (file)
import ru.deadsoftware.cavedroid.game.GameItems;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.game.GameItems;
import ru.deadsoftware.cavedroid.misc.Assets;
+/**
+ * Falling gravel is actually a mob, that spawns in place of gravel when there is no block under it,
+ * falls down to the next block and becomes a block of gravel again.
+ */
public class FallingGravel extends Mob {
public class FallingGravel extends Mob {
- ^
+ /**
+ * Creates a FallingGravel mob at coordinates
+ * @param x X in pixels
+ * @param y Y in pixels
+ */
public FallingGravel(float x, float y) {
super(x, y, 16, 16, 0);
mov = new Vector2(0, 1);
public FallingGravel(float x, float y) {
super(x, y, 16, 16, 0);
mov = new Vector2(0, 1);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
index cfd5f9b9cfecafdb7868e5ddbe7f8883612d7c7a..b1777c485c7ecffb1bd553bc5c7115a57c53d33a 100644 (file)
import ru.deadsoftware.cavedroid.game.GameItems;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.game.GameItems;
import ru.deadsoftware.cavedroid.misc.Assets;
+/**
+ * Falling sand is actually a mob, that spawns in place of gravel when there is no block under it,
+ * falls down to the next block and becomes a block of sand again.
+ */
public class FallingSand extends Mob {
public class FallingSand extends Mob {
+ /**
+ * Creates a FallingSand mob at coordinates
+ * @param x X in pixels
+ * @param y Y in pixels
+ */
public FallingSand(float x, float y) {
super(x, y, 16, 16, 0);
mov = new Vector2(0, 1);
public FallingSand(float x, float y) {
super(x, y, 16, 16, 0);
mov = new Vector2(0, 1);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
index 3b7edae21ed1748870f7b0d663407a11f33e4cd6..bcab5867bc4e8ee9186543eebd206e4733437b86 100644 (file)
import java.io.Serializable;
import java.io.Serializable;
+/**
+ * Mob class.
+ */
public abstract class Mob implements Serializable {
public abstract class Mob implements Serializable {
- public boolean flyMode;
+ public static final int LEFT = 0;
+ public static final int RIGHT = 1;
+
private float width, height;
private int dir;
private float width, height;
private int dir;
+ public boolean flyMode;
public Vector2 pos;
public Vector2 mov;
private boolean dead;
public Vector2 pos;
public Vector2 mov;
private boolean dead;
+ protected int animDelta = 6;
public boolean canJump;
public boolean canJump;
- protected int anim, animDelta = 6;
-
- protected Mob(float x, float y, float width, float height, int dir, boolean player) {
+ int anim;
+
+ /**
+ *
+ * @param x in pixels
+ * @param y in pixels
+ * @param width in pixels
+ * @param height in pixels
+ * @param dir integer representing a direction where 0 is left and 1 is right.
+ * You should use {@link #LEFT} and {@link #RIGHT} constants
+ */
+ public Mob(float x, float y, float width, float height, int dir) {
pos = new Vector2(x, y);
mov = new Vector2(0, 0);
this.width = width;
pos = new Vector2(x, y);
mov = new Vector2(0, 0);
this.width = width;
this.dir = dir;
}
this.dir = dir;
}
- protected Mob(float x, float y, float width, float height, int dir) {
- this(x, y, width, height, dir, false);
- }
-
+ /**
+ *
+ * @return The X coordinate of a mob in blocks
+ */
public int getMapX() {
return (int) (pos.x + (getWidth() / 2)) / 16;
}
public int getMapX() {
return (int) (pos.x + (getWidth() / 2)) / 16;
}
- public int getMapY() {
+ /**
+ *
+ * @return The Y coordinate of mob's upper edge in blocks
+ */
+ public int getUpperMapY() {
+ return (int) (pos.y / 16);
+ }
+
+ /**
+ *
+ * @return The Y coordinate if mob's vertical center in blocks
+ */
+ public int getMiddleMapY() {
return (int) (pos.y + (getHeight() / 2)) / 16;
}
return (int) (pos.y + (getHeight() / 2)) / 16;
}
+ /**
+ *
+ * @return The Y coordinate of mob's legs in blocks
+ */
+ public int getLowerMapY() {
+ return (int) (pos.y + getHeight()) / 16;
+ }
+
public float getWidth() {
return width;
}
public float getWidth() {
return width;
}
return height;
}
return height;
}
- public int getDir() {
+ /**
+ *
+ * @return Integer representing a direction in which mob is looking, where 0 is left and 1 is right
+ */
+ public int getDirection() {
return dir;
}
return dir;
}
+ public boolean looksLeft() {
+ return getDirection() == LEFT;
+ }
+
+ public boolean looksRight() {
+ return getDirection() == RIGHT;
+ }
+
+ /**
+ * Switches direction in which mob is looking
+ */
protected void switchDir() {
protected void switchDir() {
- dir = -dir + 1;
+ dir = looksLeft() ? RIGHT : LEFT;
}
public boolean isDead() {
return dead;
}
}
public boolean isDead() {
return dead;
}
+ /**
+ * Set's mob's dead variable to true and nothing else. It doesn't delete the mob.
+ */
public void kill() {
dead = true;
}
public void kill() {
dead = true;
}
+ /**
+ *
+ * @return A {@link Rectangle} with mob's coordinates and size
+ */
public Rectangle getRect() {
return new Rectangle(pos.x, pos.y, getWidth(), getHeight());
}
public Rectangle getRect() {
return new Rectangle(pos.x, pos.y, getWidth(), getHeight());
}
public abstract void draw(SpriteBatch spriteBatch, float x, float y);
public abstract void draw(SpriteBatch spriteBatch, float x, float y);
+ /**
+ *
+ * @return 0 - if regular mob. <br>
+ * 10 - if instance of {@link FallingSand} <br> 11 - if instance of {@link FallingGravel}
+ */
public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel
}
public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java
index 5bc0426eaac7c86e28edce896cd5d69a3124a4fb..e36da71cdb37d855235287fe8c00a9ac6a4799d7 100644 (file)
public Pig(float x, float y) {
super(x, y, 25, 18, MathUtils.random(1));
public Pig(float x, float y) {
super(x, y, 25, 18, MathUtils.random(1));
- mov = new Vector2(-1 + getDir() * 2, 0);
+ mov = new Vector2(looksLeft() ? -1 : 1, 0);
}
@Override
public void changeDir() {
switchDir();
}
@Override
public void changeDir() {
switchDir();
- mov.x = -1 + 2 * getDir();
+ mov.x = -1 + 2 * getDirection();
}
@Override
}
@Override
if (MathUtils.randomBoolean(.0025f)) changeDir();
else if (MathUtils.randomBoolean(.0025f)) {
if (mov.x != 0f) mov.x = 0;
if (MathUtils.randomBoolean(.0025f)) changeDir();
else if (MathUtils.randomBoolean(.0025f)) {
if (mov.x != 0f) mov.x = 0;
- else mov.x = -1 + 2 * getDir();
+ else mov.x = -1 + 2 * getDirection();
}
if (mov.x != 0f) anim += animDelta;
else anim = 0;
}
if (mov.x != 0f) anim += animDelta;
else anim = 0;
Assets.pigSprite[0][1].setRotation(anim);
Assets.pigSprite[1][1].setRotation(-anim);
//back legs
Assets.pigSprite[0][1].setRotation(anim);
Assets.pigSprite[1][1].setRotation(-anim);
//back legs
- Assets.pigSprite[1][1].setPosition(x - 4 + (9 - getDir() * 9), y + 6);
+ Assets.pigSprite[1][1].setPosition(x - 4 + (9 - getDirection() * 9), y + 6);
Assets.pigSprite[1][1].draw(spriteBatch);
Assets.pigSprite[1][1].draw(spriteBatch);
- Assets.pigSprite[1][1].setPosition(x + 17 - (9 * getDir()), y + 6);
+ Assets.pigSprite[1][1].setPosition(x + 17 - (9 * getDirection()), y + 6);
Assets.pigSprite[1][1].draw(spriteBatch);
//front legs
Assets.pigSprite[1][1].draw(spriteBatch);
//front legs
- Assets.pigSprite[0][1].setPosition(x - 4 + (9 - getDir() * 9), y + 6);
+ Assets.pigSprite[0][1].setPosition(x - 4 + (9 - getDirection() * 9), y + 6);
Assets.pigSprite[0][1].draw(spriteBatch);
Assets.pigSprite[0][1].draw(spriteBatch);
- Assets.pigSprite[0][1].setPosition(x + 17 - (9 * getDir()), y + 6);
+ Assets.pigSprite[0][1].setPosition(x + 17 - (9 * getDirection()), y + 6);
Assets.pigSprite[0][1].draw(spriteBatch);
//head & body
Assets.pigSprite[0][1].draw(spriteBatch);
//head & body
- spriteBatch.draw(Assets.pigSprite[getDir()][0], x, y);
+ spriteBatch.draw(Assets.pigSprite[getDirection()][0], x, y);
}
@Override
}
@Override
diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java
index 2a4491610caae37ea8207e1e46e2205c3fd49740..8cda832e540a9e307f1ae4d8343cac181b6ee9c5 100644 (file)
private String drop, meta;
private Sprite tex;
private String drop, meta;
private Sprite tex;
- //coll - collision, bg - background, tp - transparent, rb - requires block under it
private boolean coll, bg, tp, rb, fluid;
private boolean coll, bg, tp, rb, fluid;
+ /**
+ *
+ * @param left margin from left edge
+ * @param top margin from top edge
+ * @param right margin from right edge
+ * @param bottom margin from bottom edge
+ * @param hp hit points
+ * @param drop id of an item the block will drop when destroyed
+ * @param coll true if block has collision
+ * @param bg true if block should be drawn behind player
+ * @param tp true if block is transparent and renderer should draw a block behind it
+ * @param rb true if block should break when there is no block with collision under it
+ * @param fluid true if fluid
+ * @param meta extra info for storing
+ * @param tex block's texture
+ */
public Block(int left, int top, int right, int bottom, int hp,
String drop, boolean coll, boolean bg, boolean tp, boolean rb, boolean fluid, String meta, Sprite tex) {
this.x = left;
public Block(int left, int top, int right, int bottom, int hp,
String drop, boolean coll, boolean bg, boolean tp, boolean rb, boolean fluid, String meta, Sprite tex) {
this.x = left;
diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java
index ed8d4ac08259515d887af14499296a9921b28a99..00bc31788784c04135add9840f92336867c82c5d 100644 (file)
}
public void pickUpDrop(Player pl) {
}
public void pickUpDrop(Player pl) {
- for (int i = 0; i < pl.inv.length; i++) {
- if (pl.inv[i] == 0 || pl.inv[i] == id) {
- pl.inv[i] = id;
+ for (int i = 0; i < pl.inventory.length; i++) {
+ if (pl.inventory[i] == 0 || pl.inventory[i] == id) {
+ pl.inventory[i] = id;
pickedUp = true;
break;
}
pickedUp = true;
break;
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Player.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Player.java
index 14595062ebfee1618bcbcebdb5cd35dc6ce13b2d..0f12f18f5548f7de52903d7c58893df76ecb92fe 100644 (file)
package ru.deadsoftware.cavedroid.game.objects;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
package ru.deadsoftware.cavedroid.game.objects;
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.cavedroid.game.GameItems;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavedroid.game.GameItems;
+import ru.deadsoftware.cavedroid.game.GameWorld;
import ru.deadsoftware.cavedroid.game.mobs.Mob;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.game.mobs.Mob;
import ru.deadsoftware.cavedroid.misc.Assets;
public class Player extends Mob implements Serializable {
public class Player extends Mob implements Serializable {
- public int[] inv;
- public int invSlot;
+ public int[] inventory;
+ public int slot;
public int gameMode;
public boolean swim;
public Player(int gameMode) {
public int gameMode;
public boolean swim;
public Player(int gameMode) {
- super(0, 0, 4, 30, 1, true);
+ super(0, 0, 4, 30, 1);
this.gameMode = gameMode;
this.gameMode = gameMode;
- inv = new int[9];
- pos = getSpawnPoint().cpy();
+ inventory = new int[9];
swim = false;
}
swim = false;
}
GP.world.setForeMap(x, y, 1);
break;
}
GP.world.setForeMap(x, y, 1);
break;
}
- if (GP.world.getForeMap(x, y) > 0 && GameItems.getBlock(GP.world.getForeMap(x, y)).hasCollision()) break;
+ if (GP.world.hasForeAt(x, y) && GP.world.getForeMapBlock(x, y).hasCollision()) break;
}
}
- return new Vector2(x * 16 + 8 - (float) getWidth() / 2, (float) y * 16 - getHeight());
+ return new Vector2(x * 16 + 8 - getWidth() / 2, (float) y * 16 - getHeight());
}
public void setDir(int dir) {
}
public void setDir(int dir) {
- if (dir != getDir()) switchDir();
+ if (dir != getDirection()) switchDir();
}
@Override
}
@Override
Assets.plSprite[0][3].setPosition(x - 6, y + 10);
Assets.plSprite[0][3].draw(spriteBatch);
//head
Assets.plSprite[0][3].setPosition(x - 6, y + 10);
Assets.plSprite[0][3].draw(spriteBatch);
//head
- spriteBatch.draw(Assets.plSprite[getDir()][0], x - 2, y - 2);
+ spriteBatch.draw(Assets.plSprite[getDirection()][0], x - 2, y - 2);
//body
//body
- spriteBatch.draw(Assets.plSprite[getDir()][1], x - 2, y + 8);
+ spriteBatch.draw(Assets.plSprite[getDirection()][1], x - 2, y + 8);
//front hand
Assets.plSprite[0][2].setPosition(x - 6, y);
Assets.plSprite[0][2].draw(spriteBatch);
//front hand
Assets.plSprite[0][2].setPosition(x - 6, y);
Assets.plSprite[0][2].draw(spriteBatch);
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavedroid/menu/MenuRenderer.java
index 28da58e783551f08a5f9d00461685252b01a4fa2..ee626202a851f48839c3e7250883a9b1e17f9716 100644 (file)
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
+import org.jetbrains.annotations.NotNull;
import ru.deadsoftware.cavedroid.CaveGame;
import ru.deadsoftware.cavedroid.GameScreen;
import ru.deadsoftware.cavedroid.game.GameItems;
import ru.deadsoftware.cavedroid.CaveGame;
import ru.deadsoftware.cavedroid.GameScreen;
import ru.deadsoftware.cavedroid.game.GameItems;
+import ru.deadsoftware.cavedroid.game.GameProc;
import ru.deadsoftware.cavedroid.game.GameSaver;
import ru.deadsoftware.cavedroid.menu.objects.Button;
import ru.deadsoftware.cavedroid.game.GameSaver;
import ru.deadsoftware.cavedroid.menu.objects.Button;
-import ru.deadsoftware.cavedroid.misc.AppState;
+import ru.deadsoftware.cavedroid.misc.InputHandlerGame;
+import ru.deadsoftware.cavedroid.misc.states.AppState;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.misc.Renderer;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.misc.Renderer;
+import ru.deadsoftware.cavedroid.misc.states.GameState;
+import ru.deadsoftware.cavedroid.misc.states.MenuState;
+
+import static ru.deadsoftware.cavedroid.GameScreen.GP;
+import static ru.deadsoftware.cavedroid.GameScreen.RENDERER;
public class MenuRenderer extends Renderer {
public class MenuRenderer extends Renderer {
}
}
- public void buttonClicked(Button button) {
- if (button.getLabel().toLowerCase().equals("new game")) {
- CaveGame.STATE = AppState.MENU_NEW_GAME;
- } else if (button.getLabel().toLowerCase().equals("load game")) {
- CaveGame.STATE = AppState.GOTO_LOAD_GAME;
- } else if (button.getLabel().toLowerCase().equals("quit")) {
- Gdx.app.exit();
- } else if (button.getLabel().toLowerCase().equals("survival")) {
- GameScreen.NEW_GAME_MODE = 0;
- CaveGame.STATE = AppState.GOTO_NEW_GAME;
- } else if (button.getLabel().toLowerCase().equals("creative")) {
- GameScreen.NEW_GAME_MODE = 1;
- CaveGame.STATE = AppState.GOTO_NEW_GAME;
- } else if (button.getLabel().toLowerCase().equals("back")) {
- CaveGame.STATE = AppState.MENU_MAIN;
+ private void newGame(int gameMode) {
+ GP = new GameProc(gameMode);
+ GP.player.respawn();
+ GameSaver.save(GP);
+ RENDERER = GP.renderer;
+ Gdx.input.setInputProcessor(new InputHandlerGame());
+ CaveGame.APP_STATE = AppState.GAME;
+ CaveGame.GAME_STATE = GameState.PLAY;
+ }
+
+ public void buttonClicked(@NotNull Button button) {
+ switch (button.getLabel().toLowerCase()) {
+ case "new game":
+ CaveGame.MENU_STATE = MenuState.NEW_GAME;
+ break;
+ case "load game":
+ CaveGame.APP_STATE = AppState.LOAD;
+ break;
+ case "quit":
+ Gdx.app.exit();
+ break;
+ case "survival":
+ newGame(0);
+ break;
+ case "creative":
+ newGame(1);
+ break;
+ case "back":
+ CaveGame.MENU_STATE = MenuState.MAIN;
+ break;
}
}
}
}
}
spriter.draw(Assets.gameLogo, getWidth() / 2 - (float) Assets.gameLogo.getWidth() / 2, 8);
}
spriter.draw(Assets.gameLogo, getWidth() / 2 - (float) Assets.gameLogo.getWidth() / 2, 8);
- switch (CaveGame.STATE) {
- case MENU_MAIN:
+ switch (CaveGame.MENU_STATE) {
+ case MAIN:
drawButtons(menuMainBtns);
break;
drawButtons(menuMainBtns);
break;
- case MENU_NEW_GAME:
+ case NEW_GAME:
drawButtons(menuNGBtns);
break;
drawButtons(menuNGBtns);
break;
- case GOTO_NEW_GAME:
- case GOTO_LOAD_GAME:
+ case LOADING:
drawLabel("Generating World...");
drawLabel("Generating World...");
+ CaveGame.APP_STATE = AppState.GAME;
+ CaveGame.GAME_STATE = GameState.PLAY;
break;
break;
- case GOTO_MENU:
+ case SAVING:
drawLabel("Saving Game...");
drawLabel("Saving Game...");
+ CaveGame.APP_STATE = AppState.MENU;
+ CaveGame.MENU_STATE = MenuState.MAIN;
break;
}
drawString("CaveDroid " + CaveGame.VERSION, 0,
getHeight() - Assets.getStringHeight("CaveDroid " + CaveGame.VERSION) * 1.5f);
spriter.end();
break;
}
drawString("CaveDroid " + CaveGame.VERSION, 0,
getHeight() - Assets.getStringHeight("CaveDroid " + CaveGame.VERSION) * 1.5f);
spriter.end();
-
- switch (CaveGame.STATE) {
- case GOTO_NEW_GAME:
- CaveGame.STATE = AppState.NEW_GAME;
- break;
- case GOTO_LOAD_GAME:
- CaveGame.STATE = AppState.LOAD_GAME;
- break;
- case GOTO_MENU:
- CaveGame.STATE = AppState.SAVE_GAME;
- break;
- }
-
}
}
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/ControlMode.java b/core/src/ru/deadsoftware/cavedroid/misc/ControlMode.java
index ddb0c1e8cb8fcda9cd6b85c2384714374d7eb90a..dab3ac32e7183124904decff66c1cd55749311b7 100644 (file)
-package ru.deadsoftware.cavedroid.game;
+package ru.deadsoftware.cavedroid.misc;
-public class ControlMode {
+public enum ControlMode {
+ WALK,
+ CURSOR
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java b/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java
index 3eeb6f9f68368ec2b1ba3bf2d9cfaced828e3b40..a84e22af7a72c1afae78fb199e9baa098fcfca60 100644 (file)
if (CaveGame.TOUCH) {
if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 52 &&
screenY < GP.renderer.getHeight() - 26) {
if (CaveGame.TOUCH) {
if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 52 &&
screenY < GP.renderer.getHeight() - 26) {
- if (GP.ctrlMode == 1) gameInput.keyDown(Input.Keys.W);
- else gameInput.keyDown(Input.Keys.SPACE);
+ if (GP.controlMode == ControlMode.WALK) {
+ gameInput.keyDown(Input.Keys.W);
+ } else {
+ gameInput.keyDown(Input.Keys.SPACE);
+ }
} else if (screenX > 0 && screenX < 26 && screenY > GP.renderer.getHeight() - 26) {
gameInput.keyDown(Input.Keys.A);
} else if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 26) {
} else if (screenX > 0 && screenX < 26 && screenY > GP.renderer.getHeight() - 26) {
gameInput.keyDown(Input.Keys.A);
} else if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 26) {
- if (GP.ctrlMode == 1) gameInput.keyDown(Input.Keys.S);
+ if (GP.controlMode == ControlMode.CURSOR) gameInput.keyDown(Input.Keys.S);
else gameInput.keyDown(Input.Keys.CONTROL_LEFT);
} else if (screenX > 52 && screenX < 78 && screenY > GP.renderer.getHeight() - 26) {
gameInput.keyDown(Input.Keys.D);
else gameInput.keyDown(Input.Keys.CONTROL_LEFT);
} else if (screenX > 52 && screenX < 78 && screenY > GP.renderer.getHeight() - 26) {
gameInput.keyDown(Input.Keys.D);
if (CaveGame.TOUCH) {
if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 52 &&
screenY < GP.renderer.getHeight() - 26) {
if (CaveGame.TOUCH) {
if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 52 &&
screenY < GP.renderer.getHeight() - 26) {
- if (GP.ctrlMode == 1) gameInput.keyUp(Input.Keys.W);
+ if (GP.controlMode == ControlMode.CURSOR) gameInput.keyUp(Input.Keys.W);
else gameInput.keyUp(Input.Keys.SPACE);
} else if (screenX > 0 && screenX < 26 && screenY > GP.renderer.getHeight() - 26) {
gameInput.keyUp(Input.Keys.A);
} else if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 26) {
else gameInput.keyUp(Input.Keys.SPACE);
} else if (screenX > 0 && screenX < 26 && screenY > GP.renderer.getHeight() - 26) {
gameInput.keyUp(Input.Keys.A);
} else if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 26) {
- if (GP.ctrlMode == 1) gameInput.keyUp(Input.Keys.S);
+ if (GP.controlMode == ControlMode.CURSOR) gameInput.keyUp(Input.Keys.S);
else gameInput.keyUp(Input.Keys.CONTROL_LEFT);
} else if (screenX > 52 && screenX < 78 && screenY > GP.renderer.getHeight() - 26) {
gameInput.keyUp(Input.Keys.D);
else gameInput.keyUp(Input.Keys.CONTROL_LEFT);
} else if (screenX > 52 && screenX < 78 && screenY > GP.renderer.getHeight() - 26) {
gameInput.keyUp(Input.Keys.D);
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerMenu.java b/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerMenu.java
index 8f9108df597c5c7b1470b6971fd6d90286c521b8..5616d7bf4b14dda7771f5f807c6ba65295a24660 100644 (file)
public boolean touchUp(int screenX, int screenY, int pointer, int mb) {
screenX *= menuRenderer.getWidth() / GameScreen.getWidth();
screenY *= menuRenderer.getHeight() / GameScreen.getHeight();
public boolean touchUp(int screenX, int screenY, int pointer, int mb) {
screenX *= menuRenderer.getWidth() / GameScreen.getWidth();
screenY *= menuRenderer.getHeight() / GameScreen.getHeight();
- switch (CaveGame.STATE) {
- case MENU_MAIN:
+ switch (CaveGame.MENU_STATE) {
+ case MAIN:
for (Button button : menuRenderer.menuMainBtns) {
if (button.getRect().contains(screenX, screenY) && button.getType() > 0) {
menuRenderer.buttonClicked(button);
for (Button button : menuRenderer.menuMainBtns) {
if (button.getRect().contains(screenX, screenY) && button.getType() > 0) {
menuRenderer.buttonClicked(button);
}
}
break;
}
}
break;
- case MENU_NEW_GAME:
+ case NEW_GAME:
for (Button button : menuRenderer.menuNGBtns) {
if (button.getRect().contains(screenX, screenY) && button.getType() > 0) {
menuRenderer.buttonClicked(button);
for (Button button : menuRenderer.menuNGBtns) {
if (button.getRect().contains(screenX, screenY) && button.getType() > 0) {
menuRenderer.buttonClicked(button);
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/states/AppState.java b/core/src/ru/deadsoftware/cavedroid/misc/states/AppState.java
index 8af512773ef4fcb6bd2f85b8dac50c9392c4afed..e706403803d6d3fa3237b9b51f546eb714537514 100644 (file)
-package ru.deadsoftware.cavedroid.misc;
+package ru.deadsoftware.cavedroid.misc.states;
public enum AppState {
public enum AppState {
- GOTO_NEW_GAME,
- GOTO_LOAD_GAME,
- GOTO_MENU,
-
- NEW_GAME,
- LOAD_GAME,
- SAVE_GAME,
-
- MENU_MAIN,
- MENU_NEW_GAME,
-
- GAME_PLAY,
- GAME_CREATIVE_INV
+ MENU,
+ GAME,
+ SAVE,
+ LOAD
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/states/GameState.java b/core/src/ru/deadsoftware/cavedroid/misc/states/GameState.java
index 7ed4115308924eb17a423763e4b4b12ff33c5003..f2ceb447c8066a7e5e9189ebfeedde2d4c3ec1b7 100644 (file)
-package ru.deadsoftware.cavedroid.misc;
+package ru.deadsoftware.cavedroid.misc.states;
public enum GameState {
public enum GameState {
+ PLAY,
+ CREATIVE_INV,
+ PAUSE
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/states/MenuState.java b/core/src/ru/deadsoftware/cavedroid/misc/states/MenuState.java
index db3c5864ab9737c973eabcb159209ef2c659462b..69c39c422c664b6764eb9711742c389edb8ca2fb 100644 (file)
package ru.deadsoftware.cavedroid.misc.states;
public enum MenuState {
package ru.deadsoftware.cavedroid.misc.states;
public enum MenuState {
+ MAIN,
+ NEW_GAME,
+ LOADING,
+ SAVING
}
}