diff --git a/README.md b/README.md index bfde822..fdf90b7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # My own SpaceSim written in Java pretty self explanatory idk what else to write.. +## docs i'd like to keep close +Swing tutorial (Oracle): https://docs.oracle.com/javase/tutorial/uiswing/ JFrame, JPanel, key listeners, timers, etc. +Java 2D graphics tutorial: https://docs.oracle.com/javase/tutorial/2d/ drawing shapes, images, and Graphics2D. + ## credits for assets -Ive used font from [OpenFont Library](https://openfont.org/) (the one called Caveat Brush) \ No newline at end of file +Ive used font from [OpenFont Library](https://openfont.org/) (the one called Caveat Brush) +all other assets are made by me, images are made in krita. \ No newline at end of file diff --git a/assets/planet-ZX311.png b/assets/planet-ZX311.png new file mode 100644 index 0000000..e0e80f8 Binary files /dev/null and b/assets/planet-ZX311.png differ diff --git a/src/main/java/dev/dvorakmortonxd/Game.java b/src/main/java/dev/dvorakmortonxd/Game.java index 1581c93..afb09b7 100644 --- a/src/main/java/dev/dvorakmortonxd/Game.java +++ b/src/main/java/dev/dvorakmortonxd/Game.java @@ -7,6 +7,8 @@ import java.awt.Font; import java.awt.FontFormatException; import java.io.File; import java.io.IOException; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; import java.util.Random; public class Game extends JPanel implements ActionListener, KeyListener { @@ -15,7 +17,9 @@ public class Game extends JPanel implements ActionListener, KeyListener { private final int[] starY = new int[MENU_STAR_COUNT]; private final Timer timer = new Timer(16, this); // 60 FPS private Font caveat; - + private BufferedImage planetZX311; + private int planetfloat = 0; + private String planetfloatDirection = "up"; // this makes the cool floating animation on the main menu public Game() { // sets the window size setPreferredSize(new Dimension(800,600)); @@ -25,13 +29,20 @@ public class Game extends JPanel implements ActionListener, KeyListener { starX[i] = rand.nextInt(800); starY[i] = rand.nextInt(600); } - // loads up the font + // loads up the fonts try { caveat = Font.createFont(Font.TRUETYPE_FONT, new File("assets/CaveatBrush-Regular.ttf")); } catch (FontFormatException | IOException e) { e.printStackTrace(); caveat = new Font("Arial", Font.PLAIN, 12); } + // loads up the image assets + try { + planetZX311 = ImageIO.read(new File("assets/planet-ZX311.png")); + } catch (IOException e) { + e.printStackTrace(); + } + setBackground(Color.BLACK); setFocusable(true); addKeyListener(this); @@ -40,6 +51,17 @@ public class Game extends JPanel implements ActionListener, KeyListener { @Override public void actionPerformed(ActionEvent e) { // update step + if (planetfloatDirection == "up") { + planetfloat++; + if (planetfloat > 45) { + planetfloatDirection = "down"; + } + } else { + planetfloat--; + if (planetfloat < 0) { + planetfloatDirection = "up"; + } + } repaint(); // triggers render } @@ -54,7 +76,11 @@ public class Game extends JPanel implements ActionListener, KeyListener { g.setColor(Color.GRAY); g.setFont(caveat.deriveFont(Font.BOLD, 72f)); - g.drawString("Very Cool Space Sim", 38, 80); + g.drawString("Very Cool Space Sim", 120, 80); + + if (planetZX311 != null) { + g.drawImage(planetZX311, 375, 150+planetfloat/3, 128*3, 128*3, this); + } } @Override