Professional Documents
Culture Documents
Video 18
Video 18
java
// dưới: public int gameState
public final int titleState = 0;
player.draw(g2);
ui.draw(g2)ưới
}
}
UI.java
public void draw(Graphics2D g2) {
// dưới: g2.setColor(Color.white);
if(gp.gameState == gp.titleState) {
drawTitleScreen();
}
}
//TITLE NAME
g2.setFont(g2.getFont().deriveFont(Font.BOLD,96F));
String text = "Blue Boy Adventure";
int x = getXforCenteredText(text);
int y = gp.tileSize*3;
//SHADOW
g2.setColor(Color.gray);
g2.drawString(text, x+5, y+5);
//MAIN COLOR
g2.setColor(Color.white);
g2.drawString(text, x, y);
//MENU
g2.setFont(g2.getFont().deriveFont(Font.BOLD,48F));
text = "QUIT";
x = getXforCenteredText(text);
y += gp.tileSize*4;
g2.drawString(text, x, y);
if(commandNum == 2) {
g2.drawString(">", x-gp.tileSize, y);
}
}
else if(titleScreenState == 1) {
g2.setColor(Color.white);
g2.setFont(g2.getFont().deriveFont(42F));
text = "Fighter";
x = getXforCenteredText(text);
y += gp.tileSize*3;
g2.drawString(text, x, y);
if(commandNum == 0) {
g2.drawString(">", x-gp.tileSize, y);
}
text = "Thief";
x = getXforCenteredText(text);
y += gp.tileSize;
g2.drawString(text, x, y);
if(commandNum == 1) {
g2.drawString(">", x-gp.tileSize, y);
}
text = "Sorcerer";
x = getXforCenteredText(text);
y += gp.tileSize;
g2.drawString(text, x, y);
if(commandNum == 2) {
g2.drawString(">", x-gp.tileSize, y);
}
text = "Back";
x = getXforCenteredText(text);
y += gp.tileSize*2;
g2.drawString(text, x, y);
if(commandNum == 3) {
g2.drawString(">", x-gp.tileSize, y);
}
}
}
public class UI {
//dưới: public String currentDiaLogue = "";
public int commandNum = 0;
public int titleScreenState = 0; // 0: the first screen, 1: the second
screen
}
KeyHandler.java
public void KeyPressed(KeyEvent e) {
//dưới: int code = ...
if(gp.gameState == gp.titleState) {
if(gp.ui.titleScreenState == 0) {
if (code == KeyEvent.VK_W) {
gp.ui.commandNum--;
if(gp.ui.commandNum < 0) {
gp.ui.commandNum = 2;
}
}
if (code == KeyEvent.VK_S) {
gp.ui.commandNum++;
if(gp.ui.commandNum > 2) {
gp.ui.commandNum = 0;
}
if(code == KeyEvent.VK_ENTER) {
if(gp.ui.commandNum == 0) {
gp.ui.titleScreenState = 1;
}
if(gp.ui.commandNum == 1) {
}
if(gp.ui.commandNum == 2) {
System.exit(0);
}
}
}
else if(gp.ui.titleScreenState == 1) {
if (code == KeyEvent.VK_W) {
gp.ui.commandNum--;
if(gp.ui.commandNum < 0) {
gp.ui.commandNum = 3;
}
}
if (code == KeyEvent.VK_S) {
gp.ui.commandNum++;
if(gp.ui.commandNum > 3) {
gp.ui.commandNum = 0;
}
if(code == KeyEvent.VK_ENTER) {
if(gp.ui.commandNum == 0) {
System.out.println("Do some fighter specific
stuff!");
gp.gameState = gp.playState;
gp.playMusic(0);
}
if(gp.ui.commandNum == 1) {
System.out.println("Do some thief specific
stuff!");
}
if(gp.ui.commandNum == 2) {
System.out.println("Do some sorcerer specific
stuff!");
}
if(gp.ui.commandNum == 3) {
gp.ui.titleScreenState = 0;
}
}
}
}
}