1 package ru
.deadsoftware
.cavecraft
.menu
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.utils
.Array
;
5 import ru
.deadsoftware
.cavecraft
.CaveGame
;
6 import ru
.deadsoftware
.cavecraft
.GameScreen
;
7 import ru
.deadsoftware
.cavecraft
.game
.GameSaver
;
8 import ru
.deadsoftware
.cavecraft
.game
.Items
;
9 import ru
.deadsoftware
.cavecraft
.menu
.objects
.Button
;
10 import ru
.deadsoftware
.cavecraft
.misc
.AppState
;
11 import ru
.deadsoftware
.cavecraft
.misc
.Assets
;
12 import ru
.deadsoftware
.cavecraft
.misc
.Renderer
;
14 public class MenuRenderer
extends Renderer
{
16 public Array
<Button
> menuMainButtons
;
18 public MenuRenderer(int width
) {
19 super(width
, width
* ((float) GameScreen
.getHeight() / GameScreen
.getWidth()));
20 menuMainButtons
= new Array
<Button
>();
21 menuMainButtons
.add(new Button("New game", getWidth() / 2 - 100, getHeight() / 4));
22 menuMainButtons
.add(new Button("Load game", getWidth() / 2 - 100, getHeight() / 4 + 30, GameSaver
.exists() ?
1 : 0));
23 menuMainButtons
.add(new Button("Quit", getWidth() / 2 - 100, getHeight() / 4 + 60));
26 public void buttonClicked(Button button
) {
27 if (button
.getLabel().toLowerCase().equals("new game")) {
28 CaveGame
.STATE
= AppState
.GOTO_NEW_GAME
;
29 } else if (button
.getLabel().toLowerCase().equals("load game")) {
30 CaveGame
.STATE
= AppState
.GOTO_LOAD_GAME
;
31 } else if (button
.getLabel().toLowerCase().equals("quit")) {
36 private void drawButton(Button button
) {
37 spriteBatch
.draw(Assets
.menuButton
[button
.getType()], button
.getX(), button
.getY());
38 setFontColor(255, 255, 255);
39 drawString(button
.getLabel(),
40 (button
.getX() + button
.getWidth() / 2) - Assets
.getStringWidth(button
.getLabel()) / 2,
41 (button
.getY() + button
.getHeight() / 2) - Assets
.getStringHeight(button
.getLabel()) / 2);
44 private void drawMenuMain() {
45 for (Button button
: menuMainButtons
) {
46 if (button
.getType() > 0) {
47 if (button
.getRect().contains(Gdx
.input
.getX() * getWidth() / GameScreen
.getWidth(),
48 Gdx
.input
.getY() * getHeight() / GameScreen
.getHeight()))
50 else button
.setType(1);
56 public void drawLabel(String str
) {
61 public void render() {
63 for (int x
= 0; x
<= getWidth() / 16; x
++)
64 for (int y
= 0; y
<= getHeight() / 16; y
++) {
65 spriteBatch
.draw(Assets
.blockTextures
[Items
.BLOCKS
.get("dirt").getTexture()], x
* 16, y
* 16);
66 spriteBatch
.draw(Assets
.shade
, x
* 16, y
* 16);
68 spriteBatch
.draw(Assets
.gameLogo
, getWidth() / 2 - Assets
.gameLogo
.getWidth() / 2, 0);
70 switch (CaveGame
.STATE
) {
76 drawLabel("Generating World...");
79 drawLabel("Saving Game...");
83 drawString("CaveCraft " + CaveGame
.VERSION
, 0,
84 getHeight() - Assets
.getStringHeight("CaveCraft " + CaveGame
.VERSION
) * 1.5f);
87 switch (CaveGame
.STATE
) {
89 CaveGame
.STATE
= AppState
.NEW_GAME
;
92 CaveGame
.STATE
= AppState
.LOAD_GAME
;
95 CaveGame
.STATE
= AppState
.SAVE_GAME
;