open NPC dialogue if you collide with it
This commit is contained in:
@@ -7,8 +7,9 @@ import java.awt.*;
|
||||
public class UI {
|
||||
|
||||
GamePanel panel;
|
||||
Graphics graphics2d;
|
||||
Graphics2D graphics2d;
|
||||
Font arial_40, arial_80B;
|
||||
public String currentDialogue;
|
||||
|
||||
public UI(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
@@ -16,7 +17,7 @@ public class UI {
|
||||
arial_80B = new Font("Arial", Font.BOLD, 80);
|
||||
}
|
||||
|
||||
public void draw(Graphics graphics2d) {
|
||||
public void draw(Graphics2D graphics2d) {
|
||||
this.graphics2d = graphics2d;
|
||||
graphics2d.setFont(arial_40);
|
||||
graphics2d.setColor(Color.white);
|
||||
@@ -29,6 +30,9 @@ public class UI {
|
||||
case GameState.PAUSE:
|
||||
drawPauseScreen();
|
||||
break;
|
||||
case GameState.DIALOGUE:
|
||||
drawDialogueScreen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +43,29 @@ public class UI {
|
||||
graphics2d.drawString(text, getCenteredX(text), y);
|
||||
}
|
||||
|
||||
public void drawDialogueScreen() {
|
||||
// WINDOW
|
||||
int x = panel.tileSize*2;
|
||||
int y = panel.tileSize/2;
|
||||
int width = panel.screenWidth - (panel.tileSize*4);
|
||||
int height = panel.tileSize*4;
|
||||
drawSubWindow(x, y, width, height);
|
||||
|
||||
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.PLAIN, 23));
|
||||
x += panel.tileSize;
|
||||
y += panel.tileSize;
|
||||
graphics2d.drawString(currentDialogue, x, y);
|
||||
}
|
||||
|
||||
public void drawSubWindow(int x, int y, int width, int height) {
|
||||
graphics2d.setColor(new Color(0,0,0,210));
|
||||
graphics2d.fillRoundRect(x, y, width, height, 35, 35);
|
||||
graphics2d.setColor(new Color(255,255,255));
|
||||
graphics2d.setStroke(new BasicStroke(5));
|
||||
graphics2d.drawRoundRect(x+5, y+5, width-10, height-10, 25, 25);
|
||||
}
|
||||
|
||||
|
||||
public int getCenteredX(String text) {
|
||||
return panel.screenWidth / 2 - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user