gui.gamescene.scrollingtext
------------------------------「ScrollingTextTitleScene.java」-----------------------------------
package gui.gamescene.scrollingtext;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import gui.framework.scene.AbstractGameScene;
import gui.framework.scene.GameScene;
import gui.framework.window.GameFrame;
/**
* ScrollingTextゲームのタイトルシーン
*
* @author M.A.E.D.A.
* @version 1.0.3
*/
public class ScrollingTextTitleScene extends AbstractGameScene {
private long startTime = System.currentTimeMillis();
/**
* ゲームタイトルを表示する
*/
public void render(Graphics g) {
GameFrame.log("ゲームタイトルを表示する");
g.setColor(Color.CYAN);
g.setFont(new Font("SansSerif", Font.BOLD, 40));
g.drawString("TITLE SCREEN", 100, 200);
}
/**
* シーン開始から2000ミリ秒後に次のシーンへ遷移
*/
public boolean isFinished() {
return System.currentTimeMillis() - startTime > 2000;
}
public GameScene getNextScene() {
return new ScrollingTextMainScene();
}
}
------------------------------「ScrollingTextMainScene.java」-----------------------------------
package gui.gamescene.scrollingtext;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import gui.framework.scene.AbstractGameScene;
import gui.framework.scene.GameScene;
import gui.framework.window.WindowParamServer;
/**
* ScrollingTextゲームのメインシーン
*
* @author M.A.E.D.A.
* @version 1.0.3
*/
public class ScrollingTextMainScene extends AbstractGameScene{
private long startTime = System.currentTimeMillis();
private int yPosition = 0;
private int scrollSpeed = 2;
private final String message = "Hello Earth! from MAEDA";
/**
* スクロールする
*/
public void update() {
yPosition = (yPosition + scrollSpeed) % WindowParamServer.getWindowHeight();
}
/**
* メッセージを表示する
* @param g
*/
public void render(Graphics g) {
g.setColor(Color.GREEN);
g.setFont(new Font("SansSerif", Font.BOLD, 40));
g.drawString(message, 10, yPosition);
}
/**
* シーン開始から5000ミリ秒後に次のシーンへ遷移
*/
public boolean isFinished() {
return System.currentTimeMillis() - startTime > 5000;
}
public GameScene getNextScene() {
return new ScrollingTextGameOverScene();
}
}
------------------------------「ScrollingTextGameOverScene.java」-----------------------------------
package gui.gamescene.scrollingtext;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import gui.framework.scene.AbstractGameScene;
import gui.framework.scene.GameScene;
/**
* ScrollingTextゲームの終了シーン
*
* @author M.A.E.D.A.
* @version 1.0.3
*/
public class ScrollingTextGameOverScene extends AbstractGameScene {
private long startTime = System.currentTimeMillis();
public void render(Graphics g) {
g.setColor(Color.RED);
g.setFont(new Font("SansSerif", Font.BOLD, 60));
g.drawString("GAME OVER !!", 50, 200);
}
/**
* シーン開始から3000ミリ秒後に次のシーンへ遷移
*/
public boolean isFinished() {
return System.currentTimeMillis() - startTime > 3000;
}
/**
* ゲームを終了する
*/
public GameScene getNextScene() {
System.exit(0);
return null;
}
}