Created
February 22, 2016 03:04
-
-
Save Shujito/96cc2b331d49a071afe7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* <p>Title screen, it shows the logo. Makes player join by pressing its center button. | |
* | |
* @author shujito | |
*/ | |
public class ScreenTitle extends Screen { | |
public static final String TAG = ScreenTitle.class.getSimpleName(); | |
private final Music mSndBgm; | |
private final Music mSndStart; | |
private final Sprite tap; | |
private final Sprite frame; | |
private final Sprite pressText; | |
private final Sprite fade; | |
public ScreenTitle(GameFlow gameFlow) throws Exception { | |
super(gameFlow); | |
SpriteFactory factory = gameFlow.getSpriteFactory(); | |
this.setTimer(0); | |
this.setTimeOut(1000); | |
this.mSndBgm = gameFlow.getMusicFactory().create("skin/audio/082.oga"); | |
this.mSndBgm.setLoop(true); | |
this.mSndStart = gameFlow.getMusicFactory().create("skin/audio/sfx/3-2.oga"); | |
Sprite bg = factory.create( | |
"skin/title/int01.png", | |
"skin/title/int02.png", | |
"skin/title/int03.png", | |
"skin/title/int04.png", | |
"skin/title/int05.png", | |
"skin/title/int06.png", | |
"skin/title/int07.png", | |
"skin/title/int08.png", | |
"skin/title/int09.png", | |
"skin/title/int10.png", | |
"skin/title/int11.png", | |
"skin/title/int12.png", | |
"skin/title/int13.png", | |
"skin/title/int14.png", | |
"skin/title/int15.png", | |
"skin/title/int16.png", | |
"skin/title/int17.png", | |
"skin/title/int18.png", | |
"skin/title/int19.png", | |
"skin/title/int20.png", | |
"skin/title/int21.png"); | |
bg.loop(true); | |
bg.bounds(0, 0, 512, 256); | |
bg.center(256, 0); | |
bg.pos(0, 50); | |
bg.scale(640.0 / 512, 380.0 / 256); | |
for (int idx = 0; idx <= 20; idx++) { | |
bg.addState(50, idx); | |
} | |
Sprite logo = factory.create("skin/title/logo.png"); | |
logo.loop(true); | |
logo.bounds(0, 0, 512, 256); | |
logo.center(256, 128); | |
logo.pos(0, 240); | |
logo.addState(0); | |
logo.addState(525); | |
logo.scale(1.01, 1.01); | |
logo.addState(525); | |
logo.scale(1, 1); | |
// TODO: add a tap for the other player | |
this.tap = factory.create("skin/title/tap.png"); | |
this.tap.loop(true); | |
this.tap.bounds(0, 0, 80, 64); | |
this.tap.center(40, 32); | |
this.tap.pos(-220, 430); | |
for (int idx = 0; idx < 6; idx++) { | |
this.tap.bounds(idx * 80, 0, 80, 64); | |
this.tap.addState(50); | |
this.tap.addState(0); | |
} | |
this.frame = factory.create("skin/title/frame.png"); | |
this.frame.loop(true); | |
this.frame.bounds(0, 0, 128, 64); | |
this.frame.center(64, 16); | |
this.frame.pos(-220, 370); | |
this.frame.addState(250); | |
this.frame.pos(-220, 380); | |
this.frame.addState(250); | |
this.frame.pos(-220, 370); | |
this.pressText = factory.create("skin/title/press-center-step.png"); | |
this.pressText.loop(true); | |
this.pressText.bounds(0, 0, 128, 16); | |
this.pressText.center(64, 10); | |
this.pressText.pos(-220, 380); | |
this.pressText.scale(0.8, 1); | |
this.pressText.addState(250); | |
this.pressText.pos(-220, 390); | |
this.pressText.scale(1, 1); | |
this.pressText.addState(250); | |
this.pressText.pos(-220, 380); | |
this.pressText.scale(0.8, 1); | |
this.fade = factory.create("skin/common/_black.png"); | |
this.fade.setVisible(false); | |
this.fade.bounds(0, 0, 2, 2); | |
this.fade.center(1, 0); | |
this.fade.scale(640.0 / 2, 480.0 / 2); | |
this.fade.alpha(0); | |
this.fade.addState(1000); | |
this.fade.alpha(1); | |
this.addSprite(bg); | |
this.addSprite(logo); | |
this.addSprite(this.tap); | |
this.addSprite(this.frame); | |
this.addSprite(this.pressText); | |
this.addSprite(this.fade); | |
} | |
@Override | |
public void onKeyPressed(PlayerKey playerKey) { | |
if (playerKey == PlayerKey.P1_CENTER || playerKey == PlayerKey.P2_CENTER) { | |
this.getGameFlow().getGameState().addPlayer(playerKey.getPlayerNumber()); | |
this.mSndStart.play(); | |
this.tap.setVisible(false); | |
this.frame.setVisible(false); | |
this.pressText.setVisible(false); | |
this.fade.setVisible(true); | |
this.fade.restart(); | |
this.finish(); | |
} | |
} | |
@Override | |
public void onKeyReleased(PlayerKey playerKey) { | |
} | |
@Override | |
protected void onScreenIn() { | |
this.mSndBgm.play(); | |
} | |
@Override | |
protected void onScreenOut() { | |
this.mSndBgm.stop(); | |
this.mSndBgm.release(); | |
} | |
@Override | |
protected void onScreenOff() { | |
} | |
@Override | |
protected void update(long time, double delta) throws Exception { | |
} | |
@Override | |
public Screen getNextScreen() throws Exception { | |
//return new Blank(this.getFactory()); | |
return new ScreenSelect(this.getGameFlow()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment