summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8c0966b)
raw | patch | inline | side by side (parent: 8c0966b)
author | fred-boy <fred-boy@protonmail.com> | |
Sun, 30 Sep 2018 16:51:44 +0000 (23:51 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Sun, 30 Sep 2018 16:51:44 +0000 (23:51 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java
index 545ee3f74f0f500f13481286b2f6a5f284be8006..c77c9e08032e6efe725cb6be42d07f248873464d 100644 (file)
public static int FPS;
public static boolean SHOW_DEBUG = false;
+ public static int NEW_GAME_MODE = 0;
private GameProc gp;
private Renderer renderer;
break;
case NEW_GAME:
- gp = new GameProc();
+ gp = new GameProc(NEW_GAME_MODE);
renderer = gp.renderer;
Gdx.input.setInputProcessor(new InputHandlerGame(gp));
CaveGame.STATE = AppState.GAME_PLAY;
public void resize(int width, int height) {
switch (CaveGame.STATE) {
case MENU_MAIN:
+
menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
renderer = menuRenderer;
break;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java
index 48388ac465995e8a9b618234a7729b08110f1e57..687c6a9e5e6d919f96ab41b7dc0ee5ffbfd1bd06 100644 (file)
gp.swim = true;
} else if (gp.player.canJump) {
gp.player.move.add(0, -7);
- } else if (!gp.player.flyMode) {
+ } else if (!gp.player.flyMode && gp.player.gameMode == 1) {
gp.player.flyMode = true;
gp.player.move.y = 0;
- } else {
+ } else if (gp.player.flyMode) {
gp.player.move.y = -GamePhysics.PL_SPEED;
}
break;
break;
case Input.Keys.E:
- if (CaveGame.STATE == AppState.GAME_PLAY) CaveGame.STATE = AppState.GAME_CREATIVE_INV;
+ 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;
+ }
else CaveGame.STATE = AppState.GAME_PLAY;
break;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java
index 14b7015c4d0ba5eb4878cbc937be35044e4685b7..da028621decbfd3cd09fde9ec7549744993944f6 100644 (file)
public int touchDownBtn;
public long touchDownTime;
- public GameProc() {
+ public GameProc(int gameMode) {
world = new GameWorld();
world.generate(1024, 256);
- player = new Player(world.getSpawnPoint());
+ player = new Player(world.getSpawnPoint(), gameMode);
drops = new ArrayList<Drop>();
mobs = new ArrayList<Mob>();
for (int i = 0; i < 16; i++) {
if (isTouchDown && touchDownBtn == Input.Buttons.LEFT) {
if ((world.getForeMap(curX, curY) > 0 && GameItems.getBlock(world.getForeMap(curX, curY)).getHp() >= 0) ||
world.getBackMap(curX, curY) > 0 && GameItems.getBlock(world.getBackMap(curX, curY)).getHp() >= 0) {
- blockDmg++;
- if (world.getForeMap(curX, curY) > 0) {
- if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
- world.destroyForeMap(curX, curY, this);
- blockDmg = 0;
- }
- } else if (world.getBackMap(curX, curY) > 0) {
- if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
- world.destroyBackMap(curX, curY, this);
- blockDmg = 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, this);
+ blockDmg = 0;
+ }
+ } else if (world.getBackMap(curX, curY) > 0) {
+ if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
+ world.destroyBackMap(curX, curY, this);
+ blockDmg = 0;
+ }
}
+ } else {
+ if (world.getForeMap(curX, curY) > 0) world.setForeMap(curX, curY, 0);
+ else if (world.getBackMap(curX, curY) > 0) world.setBackMap(curX, curY, 0);
+ isTouchDown = false;
}
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index 162c77b885eb4747dd893530f71fceb8b41e059b..5560bf6853b799b14af11656dcb0e57407507ef6 100644 (file)
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);
}
spriter.end();
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java
index 74f7249c751030d1778e03b55b2c11acec8d1337..4c7d962ca37c86d2dae698016bd45b83aa350bdc 100644 (file)
public boolean canJump;
public int[] inv;
public boolean flyMode = false;
+ public int gameMode;
- public Player(Vector2 spawnPoint) {
+ public Player(Vector2 spawnPoint, int gameMode) {
+ this.gameMode = gameMode;
pos = spawnPoint.cpy();
move = new Vector2(0, 0);
width = 4;
diff --git a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java
index aab04d9b76dde0f683c87a89e202859a523c92ba..8aaab64c9d97c8a32c2fcf487890495d03b3b0ff 100644 (file)
public class MenuRenderer extends Renderer {
public Array<Button> menuMainBtns;
+ public Array<Button> menuNGBtns;
public MenuRenderer(int width) {
super(width, width * ((float) GameScreen.getHeight() / GameScreen.getWidth()));
+ //main menu
menuMainBtns = new Array<Button>();
menuMainBtns.add(new Button("New game", getWidth() / 2 - 100, getHeight() / 4));
menuMainBtns.add(new Button("Load game", getWidth() / 2 - 100, getHeight() / 4 + 30, GameSaver.exists() ? 1 : 0));
menuMainBtns.add(new Button("Quit", getWidth() / 2 - 100, getHeight() / 4 + 60));
+ //new game menu
+ menuNGBtns = new Array<Button>();
+ menuNGBtns.add(new Button("Survival", getWidth() / 2 - 100, getHeight() / 4, 1));
+ menuNGBtns.add(new Button("Creative", getWidth() / 2 - 100, getHeight() / 4 + 30));
+ menuNGBtns.add(new Button("Back", getWidth() / 2 - 100, getHeight() / 4 + 60));
+
}
public void buttonClicked(Button button) {
if (button.getLabel().toLowerCase().equals("new game")) {
- CaveGame.STATE = AppState.GOTO_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 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) {
drawString(str);
}
case MENU_MAIN:
drawMenuMain();
break;
+ case MENU_NEW_GAME:
+ drawMenuNewGame();
+ break;
case GOTO_NEW_GAME:
case GOTO_LOAD_GAME:
drawLabel("Generating World...");
diff --git a/core/src/ru/deadsoftware/cavecraft/misc/AppState.java b/core/src/ru/deadsoftware/cavecraft/misc/AppState.java
index 7a86332c074babdf0f7add72f8673b8de7160637..f80e7f6a8a99fd1426b5ce12d534b86c2344e910 100644 (file)
SAVE_GAME,
MENU_MAIN,
+ MENU_NEW_GAME,
GAME_PLAY,
GAME_CREATIVE_INV
diff --git a/core/src/ru/deadsoftware/cavecraft/misc/InputHandlerMenu.java b/core/src/ru/deadsoftware/cavecraft/misc/InputHandlerMenu.java
index bb6044412570fc3d7b86eb3ce0d769b271df30ef..5b4d9ba333fbd7a028604bae57bb8568a47eabdd 100644 (file)
package ru.deadsoftware.cavecraft.misc;
import com.badlogic.gdx.InputProcessor;
+import ru.deadsoftware.cavecraft.CaveGame;
import ru.deadsoftware.cavecraft.GameScreen;
import ru.deadsoftware.cavecraft.menu.MenuRenderer;
import ru.deadsoftware.cavecraft.menu.objects.Button;
public boolean touchUp(int screenX, int screenY, int pointer, int mb) {
screenX *= menuRenderer.getWidth() / GameScreen.getWidth();
screenY *= menuRenderer.getHeight() / GameScreen.getHeight();
- for (Button button : menuRenderer.menuMainBtns) {
- if (button.getRect().contains(screenX, screenY) && button.getType() > 0) menuRenderer.buttonClicked(button);
+ switch (CaveGame.STATE) {
+ case MENU_MAIN:
+ for (Button button : menuRenderer.menuMainBtns) {
+ if (button.getRect().contains(screenX, screenY) && button.getType() > 0)
+ menuRenderer.buttonClicked(button);
+ }
+ break;
+ case MENU_NEW_GAME:
+ for (Button button : menuRenderer.menuNGBtns) {
+ if (button.getRect().contains(screenX, screenY) && button.getType() > 0)
+ menuRenderer.buttonClicked(button);
+ }
+ break;
}
return false;
}