summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 423154e)
raw | patch | inline | side by side (parent: 423154e)
author | fred-boy <fred-boy@protonmail.com> | |
Tue, 24 Apr 2018 15:43:12 +0000 (22:43 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Tue, 24 Apr 2018 15:43:12 +0000 (22:43 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/AppState.java b/core/src/ru/deadsoftware/cavecraft/AppState.java
index 233bbb6da85522744ac53226aad5d71dfaebf18a..be651384954e2e252dc9a0f6eabda09108c5f6a5 100644 (file)
GOTO_LOAD_GAME,
GOTO_MENU,
+ NEW_GAME,
+ LOAD_GAME,
+ SAVE_GAME,
+
MENU_MAIN,
GAME_PLAY,
diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java
index 682319d184b3e7cbf1a562f8350ff4dead48e7bd..6d4f4d985cb5acc8d735a0283dd1d9edffcb5805 100644 (file)
menu();
break;
- case GOTO_NEW_GAME:
+ case NEW_GAME:
gameProc = new GameProc();
renderer = gameProc.renderer;
Gdx.input.setInputProcessor(new InputHandlerGame(gameProc));
CaveGame.STATE = AppState.GAME_PLAY;
break;
- case GOTO_LOAD_GAME:_GAME:
+ case LOAD_GAME:
gameProc = GameSaver.load();
renderer = gameProc.renderer;
Gdx.input.setInputProcessor(new InputHandlerGame(gameProc));
CaveGame.STATE = AppState.GAME_PLAY;
break;
+ case SAVE_GAME:
+ GameSaver.save(gameProc);
+ CaveGame.STATE = AppState.MENU_MAIN;
+ break;
+
case GOTO_MENU:
renderer = menuRenderer;
Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
- CaveGame.STATE = AppState.MENU_MAIN;
break;
}
renderer.render();
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java
index cddeb4d27158d95eb635e896ecc09ff1db0d14db..2ff2fa3d933e0d2093fd0bfcb24d215c351279d6 100644 (file)
else CaveGame.STATE = AppState.GAME_PLAY;
break;
- case Input.Keys.N:
- CaveGame.STATE = AppState.GOTO_NEW_GAME;
- break;
-
case Input.Keys.ESCAPE: case Input.Keys.BACK:
- GameSaver.save(gameProc);
CaveGame.STATE = AppState.GOTO_MENU;
break;
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java
index 070b5c24009524548980c60dee82cb0a86328930..fccc7bc8a889378d7e1ef89fb9a6cfef53b7d68a 100644 (file)
byte[] bytes = ByteBuffer.allocate(4).putInt(i).array();
file.writeBytes(bytes, append);
}
-
+
private static void saveMap(FileHandle file, int[][] map) {
int rl,bl;
int width = map.length;
if (x==map.length-1) rl++;
writeInt(file, rl, true);
writeInt(file, bl, true);
- System.out.printf("%d. Run:%d; Block:%s\n",y, rl, Items.BLOCKS.getKeyAt(bl));
rl=0;
bl=map[x][y];
}
for (int x=0; x<width; x+=rl) {
rl = bytesInt(data);
bl = bytesInt(data);
- System.out.printf("%d. Run:%d; Block:%s\n",y, rl, Items.BLOCKS.getKeyAt(bl));
for (int i=x; i<x+rl; i++) map[i][y] = bl;
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java
index 4f3e3b16e3fd605e61fe0f1e9f274e3b008b61c2..faf1eb3f15ec3d36b11a45a4ff7ed1ec897b4f6c 100644 (file)
public void buttonClicked(Button button) {
if (button.getLabel().toLowerCase().equals("new game")) {
- spriteBatch.begin();
- drawGenWorld();
- spriteBatch.end();
CaveGame.STATE = AppState.GOTO_NEW_GAME;
} else if (button.getLabel().toLowerCase().equals("load game")) {
- spriteBatch.begin();
- drawGenWorld();
- spriteBatch.end();
CaveGame.STATE = AppState.GOTO_LOAD_GAME;
} else if (button.getLabel().toLowerCase().equals("quit")) {
Gdx.app.exit();
(button.getX()+button.getWidth()/2)-Assets.getStringWidth(button.getLabel())/2,
(button.getY()+button.getHeight()/2)-Assets.getStringHeight(button.getLabel())/2);
}
-
+
private void drawMenuMain() {
for (Button button : menuMainButtons) {
if (button.getType()>0) {
}
}
- private void drawGenWorld() {
- for (int x=0; x<=getWidth()/16; x++)
- for (int y=0; y<=getHeight()/16; y++) {
- spriteBatch.draw(Items.BLOCKS.get("dirt").getTexture(), x * 16, y * 16);
- spriteBatch.draw(Assets.shade,x*16,y*16);
- }
- spriteBatch.draw(Assets.gameLogo, getWidth()/2-Assets.gameLogo.getWidth()/2, 0);
- drawString("Generating World...");
- spriteBatch.flush();
+ public void drawLabel(String str) {
+ drawString(str);
}
@Override
switch (CaveGame.STATE) {
case MENU_MAIN: drawMenuMain(); break;
+ case GOTO_NEW_GAME: case GOTO_LOAD_GAME: drawLabel("Generating World..."); break;
+ case GOTO_MENU: drawLabel("Saving Game..."); break;
}
drawString("CaveCraft "+CaveGame.VERSION,0,
getHeight()-Assets.getStringHeight("CaveCraft "+CaveGame.VERSION)*1.5f);
spriteBatch.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;
+ }
+
}
}