package ru.vagrant_ai.questionmarkgame.main;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import ru.vagrant_ai.questionmarkgame.util.MenuButton;
import ru.vagrant_ai.questionmarkgame.util.Text;
import ru.vagrant_ai.questionmarkgame.util.Util;
public class MainMenuState extends BasicGameState
{
int stateID = 0;
private final short Logo_offs_x = 154, Menubutton_offs_y = 78;
private int c_b, c_iter;
private boolean c_stg;
private int y_btn_coord;
static int start_iter;
int start_iter2;
MenuButton MenuButton = new MenuButton();
public void enter(GameContainer container, StateBasedGame stateBasedGame)
{
c_b = 0;
c_iter = 0;
c_stg = true;
y_btn_coord = 230;
start_iter = 0;
start_iter2 = 0;
}
MainMenuState( int stateID )
{
this.stateID = stateID;
}
@Override
public int getID()
{
return stateID;
}
public void init(GameContainer gc, StateBasedGame sbg)
{
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
{
render_background(g);
render_menubutton(g);
render_logo(g);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta)
{
Util.MouseUpdate();
chk_start_iter(sbg);
}
/* Object render zone */
private void render_background(Graphics g)
{
c_iter++;
if (c_iter >= 9 && c_stg) { c_iter = 0; c_b++; if (c_b > 60) c_stg = false; }
else if (c_iter >= 9) { c_iter = 0; c_b--; if (c_b < -10) c_stg = true; }
g.setColor(new Color(40+c_b/10, 29+c_b/10, 109+c_b));
g.fillRect(0, 0-start_iter2, Game.app_x, Game.app_y-start_iter2); //menu background
g.setColor(new Color(255, 0, 0));
g.fillRect(Game.app_x/5-start_iter, Game.app_y/3, (Game.app_x/5)*3, Game.app_y-Game.app_x/5); //red rectangle background part
}
private void render_logo(Graphics g)
{
Color col = new Color(0, 255, 255); Text.drawString(500, 182-start_iter, 0, "?", col);
col = new Color(255, 0, 255); Text.drawString(500, 182+Logo_offs_x-start_iter, 0, "?", col);
col = new Color(255, 255, 0); Text.drawString(500, 182+Logo_offs_x*2-start_iter, 0, "?", col);
Text.drawString(55, 209-start_iter, 13, "V.AI's"); //author
Text.drawString(70, Text.extractLength("ver. "+Game.ver+" '"+Game.ver_str+"'",70)-start_iter, Game.app_y-30, "ver. "+Game.ver+" '"+Game.ver_str+"'"); //version
}
private void render_menubutton(Graphics g)
{
if (MenuButton.create("START", Text.extractLength("START",150)-start_iter, y_btn_coord, 150))
MainMenuState.onStart();
if (MenuButton.create("QUIT", Text.extractLength("QUIT",150)-start_iter, y_btn_coord+Menubutton_offs_y, 150))
MainMenuState.onQuit();
}
private void chk_start_iter(StateBasedGame sbg)
{
if (start_iter != 0)
{
start_iter += 20;
if (start_iter > 640)
start_iter = 640;
}
if (start_iter == 640)
{
start_iter2 += 20;
if (start_iter2 > 640)
{
sbg.enterState(Game.GAMEPLAYSTATE);
}
}
}
/* MenuButton action methods */
public static void onStart()
{
if (start_iter == 0)
start_iter++;
}
public static void onQuit()
{
if (start_iter == 0)
Game.app.exit();
}
}