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
.AppState
;
7 import ru
.deadsoftware
.cavecraft
.menu
.objects
.Button
;
9 public class MenuRenderer
extends Renderer
{
11 public Array
<Button
> buttons
;
13 public MenuRenderer(int width
) {
14 super(width
,width
*((float) GameScreen
.getHeight()/GameScreen
.getWidth()));
15 buttons
= new Array
<Button
>();
16 buttons
.add(new Button("Play", getWidth()/2-100, getHeight()/4));
17 buttons
.add(new Button("Quit", getWidth()/2-100, getHeight()/4+30));
20 public void buttonClicked(Button button
) {
21 if (button
.getLabel().toLowerCase().equals("play")) {
22 CaveGame
.STATE
= AppState
.GOTO_GAME
;
23 } else if (button
.getLabel().toLowerCase().equals("quit")) {
28 private void drawButton(Button button
) {
29 spriteBatch
.draw(Assets
.menuButton
[button
.getType()], button
.getX(), button
.getY());
30 setFontColor(255,255,255);
31 drawString(button
.getLabel(),
32 (button
.getX()+button
.getWidth()/2)-Assets
.getStringWidth(button
.getLabel())/2,
33 (button
.getY()+button
.getHeight()/2)-Assets
.getStringHeight(button
.getLabel())/2);
37 public void render() {
39 for (int x
=0; x
<=getWidth()/16; x
++)
40 for (int y
=0; y
<=getHeight()/16; y
++) {
41 spriteBatch
.draw(Items
.BLOCKS
.get("dirt").getTexture(), x
* 16, y
* 16);
42 spriteBatch
.draw(Assets
.shade
,x
*16,y
*16);
44 spriteBatch
.draw(Assets
.gameLogo
, getWidth()/2-Assets
.gameLogo
.getWidth()/2, 0);
45 for (Button button
: buttons
) {
46 if (button
.getRect().contains(Gdx
.input
.getX()*getWidth()/GameScreen
.getWidth(),
47 Gdx
.input
.getY()*getHeight()/GameScreen
.getHeight()) && button
.getType()>0) {
54 drawString("CaveCraft "+CaveGame
.VERSION
,0,
55 getHeight()-Assets
.getStringHeight("CaveCraft "+CaveGame
.VERSION
)*1.5f);