Empty screen, finally made the project file/folder layout that I'll be using until we finish the project
This commit is contained in:
parent
01856fcf98
commit
8b700b7a91
4 changed files with 92 additions and 17 deletions
52
src/main/java/dev/dvorakmortonxd/Game.java
Normal file
52
src/main/java/dev/dvorakmortonxd/Game.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package dev.dvorakmortonxd;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Game extends JPanel implements ActionListener {
|
||||
|
||||
// this defines the window dimensions
|
||||
public final int windowWidth = 800;
|
||||
public final int windowHeight = 600;
|
||||
|
||||
// sets the fps to 30 (1000/30 = around 33)
|
||||
public Timer timer = new Timer(33, this);
|
||||
|
||||
// defines the current scene
|
||||
public String scene = "main_menu";
|
||||
|
||||
// routes to Update.java (actions)
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Update.performPerTick(this);
|
||||
}
|
||||
|
||||
// routes to Update.java (rendering)
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Update.paint(this, g);
|
||||
}
|
||||
|
||||
// sets up the window and everything
|
||||
public Game() {
|
||||
//sets up the window size
|
||||
setPreferredSize(new Dimension(windowWidth, windowHeight));
|
||||
Input in = new Input(this);
|
||||
addKeyListener(in);
|
||||
setBackground(new Color(45, 73, 45));
|
||||
setFocusable(true);
|
||||
timer.start();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame("My cool retro game");
|
||||
frame.setResizable(false); // NOT resizable
|
||||
frame.add(new Game());
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // enables the X button in the title bar
|
||||
frame.setLocationRelativeTo(null); // centers the window
|
||||
frame.setVisible(true); // duh
|
||||
}
|
||||
}
|
||||
28
src/main/java/dev/dvorakmortonxd/Input.java
Normal file
28
src/main/java/dev/dvorakmortonxd/Input.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package dev.dvorakmortonxd;
|
||||
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Input implements KeyListener {
|
||||
private final Game m;
|
||||
public Input(Game m) {
|
||||
this.m = m;
|
||||
}
|
||||
// what happens when you PRESS a key on your keyboard
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
switch (e.getKeyCode()) {
|
||||
case KeyEvent.VK_ESCAPE -> System.exit(0);
|
||||
case KeyEvent.VK_SPACE -> System.out.println("Hello world!");
|
||||
}
|
||||
}
|
||||
// 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.
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/main/java/dev/dvorakmortonxd/update.java
Normal file
12
src/main/java/dev/dvorakmortonxd/update.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package dev.dvorakmortonxd;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Update {
|
||||
static void performPerTick(Game m) {
|
||||
m.repaint();
|
||||
}
|
||||
static void paint(Game m, Graphics g) {
|
||||
Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue