diff --git a/README.md b/README.md index 3b61190..6186770 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ -# retro-game +
-my "retro" game built with Java and Swing \ No newline at end of file +# Retro Game +## A simple retro-style game built with Java and Swing. + +
+ +## credits +so basically I made a zero-asset policy for this project except for the font,
+which I got from [openfont.org](https://openfont.org/), the font's name is "**Jacquard 12**" :)
+also I took some inspiration from these pinterest pages (I will list every single one):
+[Retro Game Titles by "cuilong li"](https://www.pinterest.com/pin/902408844107127097/)
+[SHOVEL KNIGHT GameBoy by "PixelJoint"](https://www.pinterest.com/pin/902408844107127145) \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 6967a47..e773016 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "dev.dvorakmortonxd" -version = "1.0-SNAPSHOT" +version = "0.0.1a" repositories { mavenCentral() @@ -17,4 +17,10 @@ dependencies { tasks.test { useJUnitPlatform() +} + +tasks.jar { + manifest { + attributes["Main-Class"] = "dev.dvorakmortonxd.Game" + } } \ No newline at end of file diff --git a/src/main/java/dev/dvorakmortonxd/Game.java b/src/main/java/dev/dvorakmortonxd/Game.java index 59d15f6..4aeb5c1 100644 --- a/src/main/java/dev/dvorakmortonxd/Game.java +++ b/src/main/java/dev/dvorakmortonxd/Game.java @@ -3,6 +3,8 @@ package dev.dvorakmortonxd; import javax.swing.*; import java.awt.*; import java.awt.event.*; +import java.io.IOException; +import java.io.InputStream; public class Game extends JPanel implements ActionListener { @@ -16,6 +18,21 @@ public class Game extends JPanel implements ActionListener { // defines the current scene public String scene = "main_menu"; + // the currently chosen option (currently used for the main menu) + public int chosenOption = 1; + + // predefines the gameFont + public static Font gameFont; + + // colors I'll be using + public static Color backgroundGreen = new Color(45, 73, 45); + public static Color lightGreen = new Color(100, 120, 100); + public static Color darkerGreen = new Color(25, 50, 25); + + // text hover animation and if it should hover down or up + public int textHoverAmount = 0; + public boolean textHoverDown = true; + // routes to Update.java (actions) @Override public void actionPerformed(ActionEvent e) { @@ -35,12 +52,21 @@ public class Game extends JPanel implements ActionListener { setPreferredSize(new Dimension(windowWidth, windowHeight)); Input in = new Input(this); addKeyListener(in); - setBackground(new Color(45, 73, 45)); + setBackground(backgroundGreen); setFocusable(true); timer.start(); } public static void main(String[] args) { + // loads the game font (which is the only game asset, that's why I did not make a loadAsset class like I did in my space-sim game) + try { + InputStream inputStream = Game.class.getResourceAsStream("/assets/gameFont.ttf"); + gameFont = Font.createFont(Font.TRUETYPE_FONT, inputStream); + } catch (FontFormatException | IOException e) { + e.printStackTrace(); + gameFont = new Font("Arial", Font.PLAIN, 12); // fallback font + } + JFrame frame = new JFrame("My cool retro game"); frame.setResizable(false); // NOT resizable frame.add(new Game()); diff --git a/src/main/java/dev/dvorakmortonxd/Input.java b/src/main/java/dev/dvorakmortonxd/Input.java index 89307d8..df56e92 100644 --- a/src/main/java/dev/dvorakmortonxd/Input.java +++ b/src/main/java/dev/dvorakmortonxd/Input.java @@ -12,14 +12,39 @@ public class Input implements KeyListener { public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_ESCAPE -> System.exit(0); - case KeyEvent.VK_SPACE -> System.out.println("Hello world!"); + case KeyEvent.VK_UP, KeyEvent.VK_W -> { + if (m.scene.equals("main_menu")) { + if (m.chosenOption > 1) { + m.chosenOption--; + } else { + m.chosenOption++; + } + } + } + case KeyEvent.VK_DOWN, KeyEvent.VK_S -> { + if (m.scene.equals("main_menu")) { + if (m.chosenOption < 2) { + m.chosenOption++; + } else { + m.chosenOption--; + } + } + } + case KeyEvent.VK_ENTER, KeyEvent.VK_SPACE -> { + if (m.scene.equals("main_menu")) { + if (m.chosenOption == 1) { + m.scene = "game entry"; + } else { + System.exit(0); + } + } + } } } // what happens when you RELEASE a key on your keyboard @Override public void keyReleased(KeyEvent e) { switch (e.getKeyCode()) { - case KeyEvent.VK_SPACE -> System.out.println("Goodbye world!"); } } // I don't know what this is, or why it exists, I'll never use it but if this wasn't in the code, it'll throw an error. diff --git a/src/main/java/dev/dvorakmortonxd/update.java b/src/main/java/dev/dvorakmortonxd/update.java index 2192f98..ad9abce 100644 --- a/src/main/java/dev/dvorakmortonxd/update.java +++ b/src/main/java/dev/dvorakmortonxd/update.java @@ -4,9 +4,43 @@ import java.awt.*; public class Update { static void performPerTick(Game m) { + if (m.textHoverDown) { + m.textHoverAmount++; + if (m.textHoverAmount >= 30) { + m.textHoverDown = false; + } + } else { + m.textHoverAmount--; + if (m.textHoverAmount <= 0) { + m.textHoverDown = true; + } + } m.repaint(); } + static void paint(Game m, Graphics g) { - Toolkit.getDefaultToolkit().sync(); + if (m.scene.equals("main_menu")) { + g.setColor(m.lightGreen); + g.setFont(m.gameFont.deriveFont(75f)); + if (m.chosenOption == 1) { + g.drawString("play game", 260, 390); + g.setColor(m.darkerGreen); + g.drawString("exit game", 265, 460); + } else if (m.chosenOption == 2) { + g.drawString("exit game", 265, 460); + g.setColor(m.darkerGreen); + g.drawString("play game", 260, 390); + } else { + m.chosenOption = 1; + } + g.drawString("by dvorakmortonxd", 135, 290 + m.textHoverAmount / 4); + g.setFont(m.gameFont.deriveFont(150f)); + g.drawString("Retro", 230, 120 + m.textHoverAmount / 4); + g.drawString("Game", 235, 220 + m.textHoverAmount / 4); + g.setFont(m.gameFont.deriveFont(40f)); + g.drawString("tip: use arrow keys to navigate through menu", 65, 550); + g.drawString("and enter to pick an option!", 200, 580); + Toolkit.getDefaultToolkit().sync(); + } } } diff --git a/src/main/resources/assets/gameFont.ttf b/src/main/resources/assets/gameFont.ttf new file mode 100755 index 0000000..2454ec0 Binary files /dev/null and b/src/main/resources/assets/gameFont.ttf differ diff --git a/src/main/resources/assets/manifest.json b/src/main/resources/assets/manifest.json new file mode 100755 index 0000000..1d64bbc --- /dev/null +++ b/src/main/resources/assets/manifest.json @@ -0,0 +1,23 @@ +{ + "name": "Jacquard 12", + "family": "Jacquard 12", + "description": "Jacquard is an expanded revival typeface from a Victorian needlepoint alphabet designed in Berlin by Heinrich Kuehn circa 1880. The Soft Type is a collection of typefaces designed for knitting color-work. Designing typefaces for knitting is essentially the same as creating pixel types. However, in practice, the pixel size is determined by the properties of the yarn in use. Scale is determined by the weight of the yarn as well as the number of pixels that make up the height of each letter. In this collection, the number following the typeface's name indicates the height of the capital letters for that typeface. These typefaces were designed with machine knitting in mind, but could be used for hand knitting, needlework, bedazzling, or many other textile crafts. Note: For Fair Isle knitting, you need to beware of floats and plan accordingly, as always. Each typeface has a “Regular” and “Charted” version, and some include multiple scales so you can fit type on your knits, no matter the project's size. Check out the charted version Jacquard 12 Charted . To contribute, please see github.com/scfried/soft-type-jacquard .", + "author": "Sarah Cadigan-Fried", + "website": "https://github.com/scfried/soft-type-jacquard", + "category": "Display", + "tags": [ + "display", + "google" + ], + "languages": [ + "en", + "es" + ], + "styles": [ + "Regular" + ], + "formats": [ + "ttf" + ], + "license": "SIL Open Font License 1.1" +} \ No newline at end of file