1 package ru
.deadsoftware
.cavecraft
.menu
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.utils
.Array
;
5 import ru
.deadsoftware
.cavecraft
.*;
6 import ru
.deadsoftware
.cavecraft
.game
.GameSaver
;
7 import ru
.deadsoftware
.cavecraft
.menu
.objects
.Button
;
9 public class MenuRenderer
extends Renderer
{
11 public Array
<Button
> menuMainButtons
;
13 public MenuRenderer(int width
) {
14 super(width
,width
*((float) GameScreen
.getHeight()/GameScreen
.getWidth()));
15 menuMainButtons
= new Array
<Button
>();
16 menuMainButtons
.add(new Button("New game", getWidth()/2-100, getHeight()/4));
17 menuMainButtons
.add(new Button("Load game", getWidth()/2-100, getHeight()/4+30,GameSaver
.exists()?
1:0));
18 menuMainButtons
.add(new Button("Quit", getWidth()/2-100, getHeight()/4+60));
21 public void buttonClicked(Button button
) {
22 if (button
.getLabel().toLowerCase().equals("new game")) {
26 CaveGame
.STATE
= AppState
.GOTO_NEW_GAME
;
27 } else if (button
.getLabel().toLowerCase().equals("load game")) {
31 CaveGame
.STATE
= AppState
.GOTO_LOAD_GAME
;
32 } else if (button
.getLabel().toLowerCase().equals("quit")) {
37 private void drawButton(Button button
) {
38 spriteBatch
.draw(Assets
.menuButton
[button
.getType()], button
.getX(), button
.getY());
39 setFontColor(255,255,255);
40 drawString(button
.getLabel(),
41 (button
.getX()+button
.getWidth()/2)-Assets
.getStringWidth(button
.getLabel())/2,
42 (button
.getY()+button
.getHeight()/2)-Assets
.getStringHeight(button
.getLabel())/2);
45 private void drawMenuMain() {
46 for (Button button
: menuMainButtons
) {
47 if (button
.getType()>0) {
48 if (button
.getRect().contains(Gdx
.input
.getX()*getWidth()/GameScreen
.getWidth(),
49 Gdx
.input
.getY()*getHeight()/GameScreen
.getHeight()))
51 else button
.setType(1);
57 private void drawGenWorld() {
58 for (int x
=0; x
<=getWidth()/16; x
++)
59 for (int y
=0; y
<=getHeight()/16; y
++) {
60 spriteBatch
.draw(Items
.BLOCKS
.get("dirt").getTexture(), x
* 16, y
* 16);
61 spriteBatch
.draw(Assets
.shade
,x
*16,y
*16);
63 spriteBatch
.draw(Assets
.gameLogo
, getWidth()/2-Assets
.gameLogo
.getWidth()/2, 0);
64 drawString("Generating World...");
69 public void render() {
71 for (int x
=0; x
<=getWidth()/16; x
++)
72 for (int y
=0; y
<=getHeight()/16; y
++) {
73 spriteBatch
.draw(Items
.BLOCKS
.get("dirt").getTexture(), x
* 16, y
* 16);
74 spriteBatch
.draw(Assets
.shade
,x
*16,y
*16);
76 spriteBatch
.draw(Assets
.gameLogo
, getWidth()/2-Assets
.gameLogo
.getWidth()/2, 0);
78 switch (CaveGame
.STATE
) {
79 case MENU_MAIN
: drawMenuMain(); break;
82 drawString("CaveCraft "+CaveGame
.VERSION
,0,
83 getHeight()-Assets
.getStringHeight("CaveCraft "+CaveGame
.VERSION
)*1.5f);