Rev 593 |
Rev 697 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.PonPonChun.gamestates;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.gebauz.Bauzoid.game.Game;
import com.gebauz.Bauzoid.gamestates.BaseGameState;
import com.gebauz.Bauzoid.math.Interpolation;
import com.gebauz.Bauzoid.math.MathUtil;
import com.gebauz.Bauzoid.math.Vector4;
import com.gebauz.Bauzoid.menu.Image;
import com.gebauz.Bauzoid.menu.Label;
import com.gebauz.Bauzoid.menu.Menu;
import com.gebauz.Bauzoid.menu.MenuItem;
import com.gebauz.Bauzoid.menu.MenuUtil;
import com.gebauz.PonPonChun.game.GameConsts;
public class TitleState
extends BaseGameState
{
// Constants========================================================================================
// Embedded Types===================================================================================
public class TitleAnimator
implements MenuItem.
UpdateListener
{
private float mInitX
;
private float mInitY
;
private float mTargetX
;
private float mTargetY
;
private float mTotalTime
;
private float mCurrentTime = 0.0f
;
public TitleAnimator
(float initX,
float initY,
float targetX,
float targetY,
float totalTime
)
{
mInitX = initX
;
mInitY = initY
;
mTargetX = targetX
;
mTargetY = targetY
;
mTotalTime = totalTime
;
}
@
Override
public void onUpdate
(MenuItem sender,
float deltaTime
)
{
mCurrentTime += deltaTime
;
if (mCurrentTime
> mTotalTime
)
{
sender.
setPosition(mTargetX, mTargetY
);
mTouchText.
setVisible(true);
}
else
{
float t = Interpolation.
overshoot(mCurrentTime / mTotalTime, 2.0f
);
float currentX = mInitX +
(mTargetX - mInitX
) * t
;
float currentY = mInitY +
(mTargetY - mInitY
) * t
;
sender.
setPosition(currentX, currentY
);
}
}
public boolean isFinished
()
{
return (mCurrentTime
>= mTotalTime
);
}
}
// Members==========================================================================================
//private Sprite mTitle = null;
//private Font mFont = null;
private Menu mMenu =
null;
private Label mTouchText =
null;
private Image mTitle =
null;
private float mBlinkTimer = 0.0f
;
private Vector4 mBlinkColor =
new Vector4
(1,
1,
1,
1);
private TitleAnimator mTitleAnimator =
null;
private Sound mConfirmSound =
null;
// Methods==========================================================================================
public TitleState
(Game game
)
{
super(game
);
setFading
(true,
true);
}
@
Override
public void init
(String param
)
{
/*mTitle = new Sprite(getGraphics(), new Texture(Gdx.files.internal("data/textures/title.png")));
mTitle.x = GameConsts.VIRTUAL_SCREEN_WIDTH/2;
mTitle.y = 50;
mTitle.w = 512;
mTitle.h = 256;
mTitle.pivotX = mTitle.w/2;
mTitle.pivotY = 0;*/
mMenu = MenuUtil.
createMenuFromFile(getGame
(), Gdx.
files.
internal("data/menus/title.txt"));
mMenu.
init();
mTouchText =
(Label)mMenu.
findMenuItem("touch");
mTouchText.
setColor(mBlinkColor
);
mTouchText.
setVisible(false);
mTitle =
(Image)mMenu.
findMenuItem("title");
mTitleAnimator =
new TitleAnimator
(mTitle.
getPositionX(), mTitle.
getPositionY(), 240.0f, 80.0f, 1.0f
);
mTitle.
setUpdateListener(mTitleAnimator
);
mConfirmSound = getAudio
().
getSound("menu_confirm");
/* try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
@
Override
public void exit
()
{
if (mMenu
!=
null)
{
mMenu.
exit();
mMenu =
null;
}
mTouchText =
null;
mConfirmSound =
null;
//mFont = null;
}
@
Override
public void update
(float deltaTime
)
{
mMenu.
update(deltaTime
);
if (mTitleAnimator.
isFinished())
{
mBlinkTimer += deltaTime
;
mBlinkColor.
w = 0.5f + 0.5f
* MathUtil.
cos(mBlinkTimer
* 270.0f + 180.0f
);
mTouchText.
setColor(mBlinkColor
);
}
if (Gdx.
input.
justTouched())
{
mConfirmSound.
play();
getGameStateManager
().
switchTo(com.
gebauz.
PonPonChun.
gamestates.
MainMenuState.
class,
"");
}
}
@
Override
public void render
()
{
getGraphics
().
clear(0.35f, 0.25f, 0.35f, 0.0f
);
getRenderStates
().
projection.
setOrtho(
0.0f,
GameConsts.
VIRTUAL_SCREEN_WIDTH-
1,
GameConsts.
VIRTUAL_SCREEN_HEIGHT-
1,
0.0f,
0.0f,
1.0f
);
mMenu.
render();
/* String text = "TOUCH TO START!";
float scale = 3;
float w = mFont.getTextWidth(text, scale);
float h = mFont.getTextHeight(text, scale);
mFont.drawText(text, (GameConsts.VIRTUAL_SCREEN_WIDTH-w)/2, GameConsts.VIRTUAL_SCREEN_HEIGHT/2, GameConsts.WHITE_COLOR, scale);*/
}
// Getters/Setters==================================================================================
}