Cool planet floating icon :3
This commit is contained in:
parent
6f04c40141
commit
9fe1d27f80
3 changed files with 35 additions and 4 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
# My own SpaceSim written in Java
|
# My own SpaceSim written in Java
|
||||||
pretty self explanatory idk what else to write..
|
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
|
## credits for assets
|
||||||
Ive used font from [OpenFont Library](https://openfont.org/) (the one called Caveat Brush)
|
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.
|
||||||
BIN
assets/planet-ZX311.png
Normal file
BIN
assets/planet-ZX311.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
|
|
@ -7,6 +7,8 @@ import java.awt.Font;
|
||||||
import java.awt.FontFormatException;
|
import java.awt.FontFormatException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class Game extends JPanel implements ActionListener, KeyListener {
|
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 int[] starY = new int[MENU_STAR_COUNT];
|
||||||
private final Timer timer = new Timer(16, this); // 60 FPS
|
private final Timer timer = new Timer(16, this); // 60 FPS
|
||||||
private Font caveat;
|
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() {
|
public Game() {
|
||||||
// sets the window size
|
// sets the window size
|
||||||
setPreferredSize(new Dimension(800,600));
|
setPreferredSize(new Dimension(800,600));
|
||||||
|
|
@ -25,13 +29,20 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
starX[i] = rand.nextInt(800);
|
starX[i] = rand.nextInt(800);
|
||||||
starY[i] = rand.nextInt(600);
|
starY[i] = rand.nextInt(600);
|
||||||
}
|
}
|
||||||
// loads up the font
|
// loads up the fonts
|
||||||
try {
|
try {
|
||||||
caveat = Font.createFont(Font.TRUETYPE_FONT, new File("assets/CaveatBrush-Regular.ttf"));
|
caveat = Font.createFont(Font.TRUETYPE_FONT, new File("assets/CaveatBrush-Regular.ttf"));
|
||||||
} catch (FontFormatException | IOException e) {
|
} catch (FontFormatException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
caveat = new Font("Arial", Font.PLAIN, 12);
|
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);
|
setBackground(Color.BLACK);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
addKeyListener(this);
|
addKeyListener(this);
|
||||||
|
|
@ -40,6 +51,17 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) { // update step
|
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
|
repaint(); // triggers render
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,7 +76,11 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
|
|
||||||
g.setColor(Color.GRAY);
|
g.setColor(Color.GRAY);
|
||||||
g.setFont(caveat.deriveFont(Font.BOLD, 72f));
|
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
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue