package com.gebauz.PonPonChun.game.entities;
import java.util.Vector;
import com.badlogic.gdx.Gdx;
import com.gebauz.Bauzoid.gamestates.GameStateManager;
import com.gebauz.Bauzoid.graphics.Font;
import com.gebauz.Bauzoid.math.MathUtil;
import com.gebauz.Bauzoid.menu.EventProcessor;
import com.gebauz.Bauzoid.menu.Menu;
import com.gebauz.Bauzoid.menu.MenuEventListener;
import com.gebauz.Bauzoid.menu.MenuItem;
import com.gebauz.Bauzoid.menu.MenuUtil;
import com.gebauz.PonPonChun.game.GameConsts;
import com.gebauz.PonPonChun.game.GameLogic;
public class GameOverScreen
extends Entity implements MenuEventListener
{
// Constants========================================================================================
/** Time to wait until game over menu is displayed. */
public static final float MENU_WAIT_TIME = 1.0f
;
// Embedded Types===================================================================================
// Fields===========================================================================================
private Menu mGameOverMenu =
null;
private boolean mShowMenu =
false;
private float mTimer = 0.0f
;
private float mTextTimer = 0.0f
;
private Font mFont =
null;
// Methods==========================================================================================
public GameOverScreen
(GameLogic gameLogic
)
{
super(gameLogic
);
}
@
Override
public void init
()
{
mFont = getGameLogic
().
getGame().
getFont("scoring");
mGameOverMenu = MenuUtil.
createMenuFromFile(getGameLogic
().
getGame(), Gdx.
files.
internal("data/menus/gameover.txt"));
mGameOverMenu.
init();
mGameOverMenu.
setEventListener(this);
}
@
Override
public void exit
()
{
mFont =
null;
if (mGameOverMenu
!=
null)
{
mGameOverMenu.
exit();
mGameOverMenu =
null;
}
}
@
Override
public void update
(float deltaTime
)
{
mTextTimer += deltaTime
;
if (mTimer
> 0.0f
)
{
mTimer -= deltaTime
;
if (mTimer
<= 0.0f
)
{
mGameOverMenu.
startFadeIn();
mShowMenu =
true;
}
}
if (mShowMenu
)
{
mGameOverMenu.
update(deltaTime
);
}
}
@
Override
public void render
()
{
if (mShowMenu
)
{
mGameOverMenu.
render();
float scale = 4.0f
;
float offset = 10.0f
;
String text =
"GAME OVER";
float totalWidth = mFont.
getTextWidth(text, scale
);
float characterWidth = totalWidth / text.
length();
totalWidth += offset
* (text.
length()-
1);
float x =
(GameConsts.
VIRTUAL_SCREEN_WIDTH - totalWidth
) / 2.0f
;
float y = PlayField.
PLAYFIELD_TOP_BORDER + 200.0f
;
for (int i =
0; i
< text.
length(); i++
)
{
float yOffset = MathUtil.
sin((float)i
* 100.0f + mTextTimer
* 400.0f
) * 10.0f
;
mFont.
drawText(String.
format("%c", text.
charAt(i
)), x, y + yOffset, GameConsts.
WHITE_COLOR, scale
);
x += characterWidth + offset
;
}
}
}
public void startGameOverScreen
()
{
mTimer = MENU_WAIT_TIME
;
mShowMenu =
false;
}
@
Override
public void onMessage
(Menu menu,
MenuItem sender,
String msgType,
Vector<String> paramList
)
{
//Gdx.app.log(GameConsts.LOG_TAG, msgType);
for (String param : paramList
)
{
if (param.
equalsIgnoreCase("exit_to_menu"))
{
GameStateManager gs = getGameLogic
().
getGame().
getGameStateManager();
gs.
switchTo(com.
gebauz.
PonPonChun.
gamestates.
MainMenuState.
class, gs.
getCurrentParam());
}
else if (param.
equalsIgnoreCase("restart"))
{
getGameLogic
().
restart();
}
else
{
EventProcessor.
processEvent(menu, sender, msgType, param
);
}
}
}
// Getters/Setters==================================================================================
public boolean isShowingMenu
()
{
return mShowMenu
;
}
}