Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

GamePanel.

java
// dưới: public int gameState
public final int titleState = 0;

public void paintComponent(Graphics g) {


//dưới: drawStart = System.nanoTime(); }
if(gameState == titleState) {
ui.draw(g2);
}
else {
//cut and paste phần ở dưới
tileM.draw(g2);

for(int i = 0; i < obj.length; i++) {


if(obj[i] != null) {
obj[i].draw(g2, this);
}
}
for(int i = 0; i < npc.length; i++) {
if(npc[i] != null) {
npc[i].draw(g2);
}
}

player.draw(g2);
ui.draw(g2)ưới
}
}

public void setupGame() {


//change
gameState = titleState;
}

UI.java
public void draw(Graphics2D g2) {
// dưới: g2.setColor(Color.white);
if(gp.gameState == gp.titleState) {
drawTitleScreen();
}
}

public void drawTitleScreen() {


if(titleScreenState == 0) {
g2.setColor(new Color(0, 0, 0));
g2.fillRect(0, 0, gp.screenWidth, gp.screenHeight);

//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);

//BLUE BOY IMAGE


x = gp.screenWidth/2 - (gp.tileSize*2)/2;
y += gp.tileSize*2;
g2.drawImage(gp.player.down1, x, y, gp.tileSize*2, gp.tileSize*2,
null);

//MENU
g2.setFont(g2.getFont().deriveFont(Font.BOLD,48F));

text = "NEW GAME";


x = getXforCenteredText(text);
y += gp.tileSize*4;
g2.drawString(text, x, y);
if(commandNum == 0) {
g2.drawString(">", x-gp.tileSize, y);
}

text = "LOAD GAME";


x = getXforCenteredText(text);
y += gp.tileSize*4;
g2.drawString(text, x, y);
if(commandNum == 1) {
g2.drawString(">", x-gp.tileSize, y);
}

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));

String text = "Select your class!";


int x = getXforCenteredText(text);
int y = gp.tileSize*3;
g2.drawString(text, x, y);

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;
}
}
}
}
}

You might also like