c4dc075853cc17742802c8cc9b58ca38cd8ef01f
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
.menu
.objects
.Button
;
8 public class MenuRenderer
extends Renderer
{
10 public Array
<Button
> buttons
;
12 public MenuRenderer(int width
) {
13 super(width
,width
*((float) GameScreen
.getHeight()/GameScreen
.getWidth()));
14 buttons
= new Array
<Button
>();
15 buttons
.add(new Button("Play", getWidth()/2-100, getHeight()/4));
16 buttons
.add(new Button("Quit", getWidth()/2-100, getHeight()/4+30));
19 public void buttonClicked(Button button
) {
20 if (button
.getLabel().toLowerCase().equals("play")) {
21 CaveGame
.STATE
= GameState
.RESTART
;
22 } else if (button
.getLabel().toLowerCase().equals("quit")) {
27 private void drawButton(Button button
) {
28 spriteBatch
.draw(Assets
.menuButton
[button
.getType()], button
.getX(), button
.getY());
29 setFontColor(255,255,255);
30 drawString(button
.getLabel(),
31 (button
.getX()+button
.getWidth()/2)-Assets
.getStringWidth(button
.getLabel())/2,
32 (button
.getY()+button
.getHeight()/2)-Assets
.getStringHeight(button
.getLabel())/2);
36 public void render() {
38 for (int x
=0; x
<=getWidth(); x
++)
39 for (int y
=0; y
<=getHeight(); y
++)
40 spriteBatch
.draw(Items
.BLOCKS
.get("dirt").getTexture(),x
*16,y
*16);
41 spriteBatch
.draw(Assets
.gameLogo
, getWidth()/2-Assets
.gameLogo
.getWidth()/2, 0);
42 for (Button button
: buttons
) {
43 if (button
.getRect().contains(Gdx
.input
.getX()*getWidth()/GameScreen
.getWidth(),
44 Gdx
.input
.getY()*getHeight()/GameScreen
.getHeight()) && button
.getType()>0) {
51 drawString("CaveCraft "+CaveGame
.VERSION
,0,
52 getHeight()-Assets
.getStringHeight("CaveCraft "+CaveGame
.VERSION
)*2);