diff --git a/.gitignore b/.gitignore index 1fac4d5..1f80551 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build/ .kotlin ### IntelliJ IDEA ### +.idea/ .idea/modules.xml .idea/jarRepositories.xml .idea/compiler.xml diff --git a/README.md b/README.md index a0349cf..bfde822 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # My own SpaceSim written in Java -pretty self explanatory idk what else to write.. \ No newline at end of file +pretty self explanatory idk what else to write.. + +## credits for assets +Ive used font from [OpenFont Library](https://openfont.org/) (the one called Caveat Brush) \ No newline at end of file diff --git a/assets/CaveatBrush-Regular.ttf b/assets/CaveatBrush-Regular.ttf new file mode 100755 index 0000000..fa60b56 Binary files /dev/null and b/assets/CaveatBrush-Regular.ttf differ diff --git a/assets/manifest.json b/assets/manifest.json new file mode 100755 index 0000000..b332d8b --- /dev/null +++ b/assets/manifest.json @@ -0,0 +1,23 @@ +{ + "name": "Caveat Brush", + "family": "Caveat Brush", + "description": "Caveat is a handwriting type family designed by Pablo Impallari. It is designed for short annotations. For a different style, there is also a sister family, Caveat The fonts have OpenType features that enable the letters to have slight variations according to their occurrence within a word, for a natural handwritten feel.", + "author": "Impallari Type", + "website": "https://github.com/googlefonts/caveat", + "category": "Handwriting", + "tags": [ + "handwriting", + "google" + ], + "languages": [ + "en", + "es" + ], + "styles": [ + "Regular" + ], + "formats": [ + "ttf" + ], + "license": "SIL Open Font License 1.1" +} \ No newline at end of file diff --git a/src/main/java/dev/dvorakmortonxd/Game.java b/src/main/java/dev/dvorakmortonxd/Game.java new file mode 100644 index 0000000..1581c93 --- /dev/null +++ b/src/main/java/dev/dvorakmortonxd/Game.java @@ -0,0 +1,81 @@ +package dev.dvorakmortonxd; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.Font; +import java.awt.FontFormatException; +import java.io.File; +import java.io.IOException; +import java.util.Random; + +public class Game extends JPanel implements ActionListener, KeyListener { + private final int MENU_STAR_COUNT = 75; + private final int[] starX = new int[MENU_STAR_COUNT]; + private final int[] starY = new int[MENU_STAR_COUNT]; + private final Timer timer = new Timer(16, this); // 60 FPS + private Font caveat; + + public Game() { + // sets the window size + setPreferredSize(new Dimension(800,600)); + // sets the star count for the main menu + Random rand = new Random(); + for (int i = 0; i < MENU_STAR_COUNT; i++) { + starX[i] = rand.nextInt(800); + starY[i] = rand.nextInt(600); + } + // loads up the font + 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); + } + setBackground(Color.BLACK); + setFocusable(true); + addKeyListener(this); + timer.start(); + } + + @Override + public void actionPerformed(ActionEvent e) { // update step + repaint(); // triggers render + } + + @Override + protected void paintComponent(Graphics g) { // render step + super.paintComponent(g); // this clears the previous frame + + g.setColor(Color.WHITE); + for (int i = 0; i < MENU_STAR_COUNT; i++) { // drawing the stars + g.fillOval(starX[i], starY[i], 2, 2); + } + + g.setColor(Color.GRAY); + g.setFont(caveat.deriveFont(Font.BOLD, 72f)); + g.drawString("Very Cool Space Sim", 38, 80); + } + + @Override + public void keyPressed(KeyEvent e) { // input + switch (e.getKeyCode()) { + case KeyEvent.VK_ESCAPE -> System.exit(0); + } + } + + @Override + public void keyReleased(KeyEvent e) { // what happens when you let go of a key + } + + @Override public void keyTyped(KeyEvent e) {} + public static void main(String[] args) { + JFrame frame = new JFrame("My cool space sim"); + frame.setResizable(false); // makes it so gamers cant just resize the window and leave black parts of the window + frame.add(new Game()); + frame.pack(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // makes the X button on the titlebar functional + frame.setLocationRelativeTo(null); // centers the window on the screen + frame.setVisible(true); // makes the window visible + } +} \ No newline at end of file diff --git a/src/main/java/dev/dvorakmortonxd/Main.java b/src/main/java/dev/dvorakmortonxd/Main.java deleted file mode 100644 index 8297e2a..0000000 --- a/src/main/java/dev/dvorakmortonxd/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.dvorakmortonxd; - -//TIP To Run code, press or -// click the icon in the gutter. -public class Main { - public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); - - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - System.out.println("i = " + i); - } - } -} \ No newline at end of file