Cool planet floating icon :3

This commit is contained in:
dvorakmortonxd 2026-10-19 09:54:09 +02:00
commit 9fe1d27f80
3 changed files with 35 additions and 4 deletions

View file

@ -1,5 +1,10 @@
# My own SpaceSim written in Java
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
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -7,6 +7,8 @@ import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.util.Random;
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 Timer timer = new Timer(16, this); // 60 FPS
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() {
// sets the window size
setPreferredSize(new Dimension(800,600));
@ -25,13 +29,20 @@ public class Game extends JPanel implements ActionListener, KeyListener {
starX[i] = rand.nextInt(800);
starY[i] = rand.nextInt(600);
}
// loads up the font
// loads up the fonts
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);
}
// loads up the image assets
try {
planetZX311 = ImageIO.read(new File("assets/planet-ZX311.png"));
} catch (IOException e) {
e.printStackTrace();
}
setBackground(Color.BLACK);
setFocusable(true);
addKeyListener(this);
@ -40,6 +51,17 @@ public class Game extends JPanel implements ActionListener, KeyListener {
@Override
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
}
@ -54,7 +76,11 @@ public class Game extends JPanel implements ActionListener, KeyListener {
g.setColor(Color.GRAY);
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