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()/16; x
++)
39 for (int y
=0; y
<=getHeight()/16; y
++) {
40 if (y
== 0) spriteBatch
.draw(Items
.BLOCKS
.get("grass").getTexture(), x
* 16, y
* 16);
41 else 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);