Merge remote-tracking branch 'origin/master'
commit
f5e501d8ef
|
@ -13,8 +13,7 @@ public class MenuPanel extends JFrame implements ActionListener {
|
||||||
public MenuPanel() {
|
public MenuPanel() {
|
||||||
this.setTitle("First");
|
this.setTitle("First");
|
||||||
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
this.setSize(280, 200);
|
this.setSize(1225, 630);
|
||||||
|
|
||||||
|
|
||||||
launchGame = new JButton("Click");
|
launchGame = new JButton("Click");
|
||||||
launchGame.addActionListener(this);
|
launchGame.addActionListener(this);
|
||||||
|
@ -27,7 +26,13 @@ public class MenuPanel extends JFrame implements ActionListener {
|
||||||
|
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
super.paint(g);
|
super.paint(g);
|
||||||
g.drawString("potato", 50, 50);
|
draw(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Graphics g) {
|
||||||
|
g.setColor(Color.black);
|
||||||
|
g.setFont(new Font("Monospaced", Font.PLAIN, 60));
|
||||||
|
g.setColor(Color.white);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
|
|
@ -65,6 +65,10 @@ public class NonPlayer extends GenericSprite {
|
||||||
realX = x-GamePanel.camera.x;
|
realX = x-GamePanel.camera.x;
|
||||||
}
|
}
|
||||||
public void move(){
|
public void move(){
|
||||||
|
if (isDead) {
|
||||||
|
// preemptively end move function if enemy is dead
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!canUpdate(xVelocity, 0)){
|
if(!canUpdate(xVelocity, 0)){
|
||||||
xVelocity*=-1;
|
xVelocity*=-1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public final class TextManager {
|
||||||
|
// utility class, constructor is private to prevent initialization
|
||||||
|
private TextManager() {}
|
||||||
|
|
||||||
|
private static void drawTextBox(Graphics g, int y, int xOffset, int xWidth, int yHeight, int totalWidth,
|
||||||
|
String text, Color backgroundColor, Color textColor) {
|
||||||
|
int newX = (totalWidth - xWidth)/2;
|
||||||
|
int newY = y - yHeight/2;
|
||||||
|
g.setColor(backgroundColor);
|
||||||
|
g.drawRect(newX, newY, xWidth, yHeight);
|
||||||
|
g.setColor(textColor);
|
||||||
|
drawCenteredString(g, y, xOffset, xWidth, text);
|
||||||
|
}
|
||||||
|
private static void drawCenteredString(Graphics g, int y, int xOffset, int xWidth, String text) {
|
||||||
|
int x;
|
||||||
|
// get font size
|
||||||
|
FontMetrics metrics = g.getFontMetrics();
|
||||||
|
// determine x for the text
|
||||||
|
x = xOffset + (xWidth - metrics.stringWidth(text)) / 2;
|
||||||
|
// draw centered string
|
||||||
|
g.drawString(text, x, y);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue