the main menu is finally starting to get its shape
This commit is contained in:
parent
6c7e507c5e
commit
6f04c40141
6 changed files with 109 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,6 +6,7 @@ build/
|
|||
.kotlin
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
|
|
|
|||
|
|
@ -1,2 +1,5 @@
|
|||
# My own SpaceSim written in Java
|
||||
pretty self explanatory idk what else to write..
|
||||
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)
|
||||
BIN
assets/CaveatBrush-Regular.ttf
Executable file
BIN
assets/CaveatBrush-Regular.ttf
Executable file
Binary file not shown.
23
assets/manifest.json
Executable file
23
assets/manifest.json
Executable file
|
|
@ -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"
|
||||
}
|
||||
81
src/main/java/dev/dvorakmortonxd/Game.java
Normal file
81
src/main/java/dev/dvorakmortonxd/Game.java
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package dev.dvorakmortonxd;
|
||||
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> 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 <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
||||
System.out.println("i = " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue