Compare commits
17 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 872ff7db22 | |||
| e825b08783 | |||
| ae49b3bbc1 | |||
|
|
75945b5907 | ||
|
|
79c4678315 | ||
|
|
3fcad8d95c | ||
|
|
b4851409e2 | ||
| c3a2bb55c5 | |||
|
|
41f1d820e1 | ||
|
|
d1841f0b3a | ||
| d32e8a8225 | |||
| e2438b4005 | |||
| 915afaa7cb | |||
|
|
f36b9415eb | ||
|
|
5e60db0dc4 | ||
|
|
bbf6b24fa0 | ||
| 0eba03b1fc |
1
.gitignore
vendored
|
|
@ -19,6 +19,7 @@ out/
|
||||||
!**/src/test/**/out/
|
!**/src/test/**/out/
|
||||||
|
|
||||||
# Java
|
# Java
|
||||||
|
jre-runtime/
|
||||||
build/
|
build/
|
||||||
staging/
|
staging/
|
||||||
|
|
||||||
|
|
|
||||||
39
README.md
|
|
@ -1,5 +1,40 @@
|
||||||
# My own SpaceSim written in Java
|
<div align="center">
|
||||||
pretty self-explanatory idk what else to write...
|
|
||||||
|
# My own SpaceSim written in Java!
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|
# Preview:
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<img
|
||||||
|
alt="image"
|
||||||
|
src="https://git.dvorakmortonxd.dev/dvorakmortonxd/space-sim/raw/branch/main/src/main/resources/preview.png"
|
||||||
|
style="width: 100%; max-width: 1280px; aspect-ratio: 14 / 9; object-fit: contain; height: auto;"
|
||||||
|
/>
|
||||||
|
|
||||||
|
# This is my work-in-progress game about space, it currently includes:
|
||||||
|
|
||||||
|
- Main menu with cool hovering effects (like the planet hovering and it highlighting when you hover your cursor on it)
|
||||||
|
- a rocket detaching and landing animation on the ZX311 planet
|
||||||
|
- an observatory and a walkable land on the ZX311
|
||||||
|
- neat and buttery smooth movement
|
||||||
|
- thats about it. I plan to add more stuff to the planet and a way to travel to more planets but I'm gonna need more time for that :)
|
||||||
|
|
||||||
|
# Why did I make this?
|
||||||
|
Well I've always liked space games (especially galacticraft and ad astra modpacks in minecraft) and I thought it would keep me going on making a game about it, I also thought it would pretty much fit into this weeks theme ("Outside") on Terra, so I just went for it! also I wanted to learn to make games in java since one of my favourite games (minecraft) is written in Java and I wanted to learn java for a long time, also it would help me in school since right now we are doing C# in school which has a really similar syntax to java :)
|
||||||
|
|
||||||
|
# How do I play? what are the controls for the game?
|
||||||
|
Well it is pretty basic, the main menu is just click and go so basically you only use your mouse cursor there, and until the rocket lands there aren't any other controls except the debug ones (I'll mention them at the end of this section), and when you land, theres only the basic WASD movement (however the W/S keys are used mainly for doors and stuff, since you cant really walk forward/backward on a 2d window lol) and space to jump (this one is self-explanatory). Now to the debug keys, if you opened this game in a terminal, then you can use the Control key (Ctrl) to get the players X and Y position (though it says the upper left corner of the players sprite since that's where it renders), and also this one you can use whenever but the Slash key (/) will skip the rocket's animation and will skip you to all the way to the part where you land so you can move immidiently (this will work anywhere so it's not really just the skip, it's basically a teleport to landing site and activates player movement).
|
||||||
|
|
||||||
|
# How do I install/run this?
|
||||||
|
well you need any java 21 runtime (like temurin-21 or openjdk-21-jre) and then you just gotta install the .jar file from the [releases page](https://git.dvorakmortonxd.dev/dvorakmortonxd/space-sim/releases) , ORRR.. if you are on a MacOS, I included the .dmg build with an integrated runtime meaning you can just install that one and it'll run without any other requirements! I also have linux .tar.gz builds on earlier versions however I built this one while on vacation so I can't really build it for linux without any access to my desktop at home, and I can't build a windows .exe executables since I don't use windows at all, sorry :(
|
||||||
|
|
||||||
|
## how was this made?
|
||||||
|
I made it using Java 21 and the Swing library and Java's 2D Graphics :)
|
||||||
|
|
||||||
|
# Thank you for playing/reviewing this project! below theres a few credits I thought made sense
|
||||||
|
|
||||||
## docs I'd like to keep close
|
## docs I'd like to keep close
|
||||||
Swing tutorial (Oracle): https://docs.oracle.com/javase/tutorial/uiswing/ JFrame, JPanel, key listeners, timers, etc.
|
Swing tutorial (Oracle): https://docs.oracle.com/javase/tutorial/uiswing/ JFrame, JPanel, key listeners, timers, etc.
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.dvorakmortonxd"
|
group = "dev.dvorakmortonxd"
|
||||||
version = "0.0.2a"
|
version = "0.0.4a"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,14 @@ public class Game extends JPanel implements ActionListener {
|
||||||
public static BufferedImage playerRight0;
|
public static BufferedImage playerRight0;
|
||||||
public static BufferedImage playerRight1;
|
public static BufferedImage playerRight1;
|
||||||
public static BufferedImage playerRight2;
|
public static BufferedImage playerRight2;
|
||||||
|
public static BufferedImage planetZX311Land;
|
||||||
|
public static BufferedImage closedObservatory;
|
||||||
|
public static BufferedImage openedObservatory;
|
||||||
|
public static BufferedImage doorObservatory;
|
||||||
|
|
||||||
|
|
||||||
// sets the FPS up (its 16 because 1000/60 is around 16.666 but it only accepts integers so its just rounded to 60)
|
// sets the FPS up (its 16 because 1000/60 is around 16.666 but it only accepts integers so its just rounded to 60)
|
||||||
public final Timer timer = new Timer(16, this); // 60 FPS (actually more so around 62.5 but thats kinda irrelevant)
|
public Timer timer = new Timer(16, this); // 60 FPS (actually more so around 62.5 but thats kinda irrelevant)
|
||||||
|
|
||||||
// predefines the mouse position variables
|
// predefines the mouse position variables
|
||||||
public int mouseX, mouseY;
|
public int mouseX, mouseY;
|
||||||
|
|
@ -107,17 +112,28 @@ public class Game extends JPanel implements ActionListener {
|
||||||
public int actionTimer = 0;
|
public int actionTimer = 0;
|
||||||
|
|
||||||
// defines the initial player variables
|
// defines the initial player variables
|
||||||
public int playerX = 423;
|
public double playerX = 423;
|
||||||
public int playerY = 310;
|
public double playerY = 310;
|
||||||
public int playerOldY = playerY;
|
public double playerXVelocity = 0;
|
||||||
|
public double playerYVelocity = 0;
|
||||||
|
public boolean leftHeld, rightHeld, upHeld, downHeld;
|
||||||
|
public static final double acceleration = 0.6;
|
||||||
|
public final double friction = 0.6;
|
||||||
|
public final double maxSpeed = 6.0;
|
||||||
|
public final double gravity = 1.0;
|
||||||
|
public final double jumpSpeed = -12.6;
|
||||||
|
public final double maxFall = 20.0;
|
||||||
public int playerSizeX = 14*4;
|
public int playerSizeX = 14*4;
|
||||||
public int playerSizeY = 18*4;
|
public int playerSizeY = 18*4;
|
||||||
public String playerDirection = "forward";
|
public String playerFacing = "forward";
|
||||||
public BufferedImage playerCurrentSprite;
|
public BufferedImage playerCurrentSprite;
|
||||||
public int playerWalkingModifier = 5;
|
public String currentPlayerLocation = "landingPlatformZX311";
|
||||||
public boolean playerOnFeet = true;
|
public boolean playerOnFeet = true;
|
||||||
public boolean playerJumped = false;
|
|
||||||
public boolean playerActive = false;
|
public boolean playerActive = false;
|
||||||
|
public int walkTick;
|
||||||
|
public static int ticksPerFrame = 8;
|
||||||
|
public static int[] walkCycle = {1, 0, 2, 0};
|
||||||
|
|
||||||
// Starts update.java which is basically a class that contains all the stuff that happens every tick
|
// Starts update.java which is basically a class that contains all the stuff that happens every tick
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) { // update step
|
public void actionPerformed(ActionEvent e) { // update step
|
||||||
|
|
@ -159,5 +175,6 @@ public class Game extends JPanel implements ActionListener {
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // makes the X button on the title bar functional
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // makes the X button on the title bar functional
|
||||||
frame.setLocationRelativeTo(null); // centers the window on the screen
|
frame.setLocationRelativeTo(null); // centers the window on the screen
|
||||||
frame.setVisible(true); // makes the window visible
|
frame.setVisible(true); // makes the window visible
|
||||||
|
frame.setIconImage(rocket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.dvorakmortonxd;
|
package dev.dvorakmortonxd;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
public class input implements KeyListener {
|
public class input implements KeyListener {
|
||||||
|
|
@ -11,28 +12,29 @@ public class input implements KeyListener {
|
||||||
public void keyPressed(KeyEvent e) { // input
|
public void keyPressed(KeyEvent e) { // input
|
||||||
if (m.playerActive) {
|
if (m.playerActive) {
|
||||||
switch (e.getKeyCode()) {
|
switch (e.getKeyCode()) {
|
||||||
case KeyEvent.VK_A:
|
case KeyEvent.VK_W, KeyEvent.VK_UP -> m.upHeld = true;
|
||||||
m.playerDirection = "left";
|
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> m.leftHeld = true;
|
||||||
break;
|
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> m.downHeld = true;
|
||||||
case KeyEvent.VK_D:
|
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> m.rightHeld = true;
|
||||||
m.playerDirection = "right";
|
// debug
|
||||||
break;
|
case KeyEvent.VK_TAB -> m.timer = new Timer(8, m); // speeds up the game animations (125fps)
|
||||||
case KeyEvent.VK_SPACE:
|
case KeyEvent.VK_SPACE -> {
|
||||||
if (!m.playerJumped && m.playerOnFeet) {
|
if (m.playerOnFeet) {
|
||||||
m.playerJumped = true;
|
m.playerYVelocity = m.jumpSpeed;
|
||||||
m.playerOldY = m.playerY;
|
m.playerOnFeet = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
/* ONLY FOR DEBUGGING BELOW
|
|
||||||
case KeyEvent.VK_A -> m.playerX -= m.playerWalkingModifier;
|
|
||||||
case KeyEvent.VK_D -> m.playerX += m.playerWalkingModifier;
|
|
||||||
case KeyEvent.VK_S -> m.playerY += 1;
|
|
||||||
case KeyEvent.VK_W -> m.playerY -= 1; */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (e.getKeyCode()) {
|
switch (e.getKeyCode()) {
|
||||||
case KeyEvent.VK_ESCAPE -> System.exit(0);
|
case KeyEvent.VK_ESCAPE -> System.exit(0);
|
||||||
case KeyEvent.VK_CONTROL -> System.out.println("X+Y="+m.playerX+"+"+m.playerY);
|
case KeyEvent.VK_CONTROL -> System.out.println("X+Y="+m.playerX+"+"+m.playerY);
|
||||||
|
// THE LINE BELOW IS FOR ME WHEN DEBUGGING, I LEFT IT IN BECAUSE IT'S IMPOSSIBLE TO KNOW ABOUT IT WITHOUT READING THE CODE LOL
|
||||||
|
case KeyEvent.VK_TAB -> m.timer = new Timer(16, m); // slows back the game animations (62fps)
|
||||||
|
case KeyEvent.VK_SLASH -> {
|
||||||
|
m.level = 3;
|
||||||
|
m.playerActive = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,15 +43,15 @@ public class input implements KeyListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) { // what happens when you let go of a key
|
public void keyReleased(KeyEvent e) { // what happens when you let go of a key
|
||||||
|
if (m.level == 0) {
|
||||||
|
m.level = 1;
|
||||||
|
}
|
||||||
if (m.playerActive) {
|
if (m.playerActive) {
|
||||||
switch (e.getKeyCode()) {
|
switch (e.getKeyCode()) {
|
||||||
case KeyEvent.VK_A -> m.playerDirection = "forward";
|
case KeyEvent.VK_W, KeyEvent.VK_UP -> m.upHeld = false;
|
||||||
case KeyEvent.VK_D -> m.playerDirection = "forward";
|
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> m.leftHeld = false;
|
||||||
/* ONLY FOR DEBUGGING BELOW
|
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> m.downHeld = false;
|
||||||
case KeyEvent.VK_A -> m.playerX -= m.playerWalkingModifier;
|
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> m.rightHeld = false;
|
||||||
case KeyEvent.VK_D -> m.playerX += m.playerWalkingModifier;
|
|
||||||
case KeyEvent.VK_S -> m.playerY += 1;
|
|
||||||
case KeyEvent.VK_W -> m.playerY -= 1; */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +89,10 @@ public class input implements KeyListener {
|
||||||
m.addMouseListener(new MouseAdapter() {
|
m.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
if (m.level == 1) {
|
if (m.level == 0) {
|
||||||
|
m.level = 1;
|
||||||
|
}
|
||||||
|
else if (m.level == 1) {
|
||||||
if (e.getButton() == MouseEvent.BUTTON1 && m.hoveringOverQuitButton) {
|
if (e.getButton() == MouseEvent.BUTTON1 && m.hoveringOverQuitButton) {
|
||||||
m.quitButtonX = m.quitButtonX + 5;
|
m.quitButtonX = m.quitButtonX + 5;
|
||||||
m.quitButtonY = m.quitButtonY - 5;
|
m.quitButtonY = m.quitButtonY - 5;
|
||||||
|
|
@ -101,6 +106,7 @@ public class input implements KeyListener {
|
||||||
if (e.getButton() == MouseEvent.BUTTON1 && m.hoveringOverPlanet) {
|
if (e.getButton() == MouseEvent.BUTTON1 && m.hoveringOverPlanet) {
|
||||||
m.planetX = m.planetX + 2;
|
m.planetX = m.planetX + 2;
|
||||||
m.planetYPre = m.planetYPre - 2;
|
m.planetYPre = m.planetYPre - 2;
|
||||||
|
m.level = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package dev.dvorakmortonxd;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
@ -44,7 +43,10 @@ public class loadAssets {
|
||||||
m.playerRight0 = ImageIO.read(Game.class.getResource("/assets/player/playerSpriteRight.png"));
|
m.playerRight0 = ImageIO.read(Game.class.getResource("/assets/player/playerSpriteRight.png"));
|
||||||
m.playerRight1 = ImageIO.read(Game.class.getResource("/assets/player/playerSpriteRightWalk0.png"));
|
m.playerRight1 = ImageIO.read(Game.class.getResource("/assets/player/playerSpriteRightWalk0.png"));
|
||||||
m.playerRight2 = ImageIO.read(Game.class.getResource("/assets/player/playerSpriteRightWalk1.png"));
|
m.playerRight2 = ImageIO.read(Game.class.getResource("/assets/player/playerSpriteRightWalk1.png"));
|
||||||
|
m.planetZX311Land = ImageIO.read(Game.class.getResource("/assets/planetZX311Land.png"));
|
||||||
|
m.closedObservatory = ImageIO.read(Game.class.getResource("/assets/observatoryClosed.png"));
|
||||||
|
m.openedObservatory = ImageIO.read(Game.class.getResource("/assets/observatoryOpened.png"));
|
||||||
|
m.doorObservatory = ImageIO.read(Game.class.getResource("/assets/observatoryDoor.png"));
|
||||||
m.playerCurrentSprite = m.playerForward0;
|
m.playerCurrentSprite = m.playerForward0;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,30 @@
|
||||||
package dev.dvorakmortonxd;
|
package dev.dvorakmortonxd;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class update {
|
public class update {
|
||||||
|
public static BufferedImage spriteFor(Game m, String direction, int frame) {
|
||||||
|
return switch (direction) {
|
||||||
|
case "forward" -> new BufferedImage[]{m.playerForward0, m.playerForward1, m.playerForward2}[frame];
|
||||||
|
case "backward" -> new BufferedImage[]{m.playerBackward0, m.playerBackward1, m.playerBackward2}[frame];
|
||||||
|
case "left" -> new BufferedImage[]{m.playerLeft0, m.playerLeft1, m.playerLeft2}[frame];
|
||||||
|
case "right" -> new BufferedImage[]{m.playerRight0, m.playerRight1, m.playerRight2}[frame];
|
||||||
|
default -> m.playerForward0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static double getGroundY(Game m) {
|
||||||
|
if (m.currentPlayerLocation.equals("landingPlatformZX311")) {
|
||||||
|
if (m.playerX > 290 && m.playerX < 572) { return 358; } else { return 385; }
|
||||||
|
} else if (m.currentPlayerLocation.equals("observatoryZX311") || m.currentPlayerLocation.equals("villageEntranceZX311")) {
|
||||||
|
return 385;
|
||||||
|
} else if (m.currentPlayerLocation.equals("observatoryInteriorZX311")) {
|
||||||
|
return 400;
|
||||||
|
} else {
|
||||||
|
return m.windowHeight-m.playerSizeY;
|
||||||
|
}
|
||||||
|
}
|
||||||
static void performPerTick(Game m) {
|
static void performPerTick(Game m) {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
m.starSize = rand.nextInt(2,4);
|
m.starSize = rand.nextInt(2,4);
|
||||||
|
|
@ -43,42 +64,112 @@ public class update {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m.playerActive) {
|
if (m.playerActive) {
|
||||||
if (m.playerDirection == "forward"){
|
if (m.leftHeld && !m.rightHeld) { m.playerFacing = "left"; }
|
||||||
m.playerCurrentSprite = m.playerForward0;
|
else if (m.rightHeld && !m.leftHeld) { m.playerFacing = "right"; }
|
||||||
} else if (m.playerDirection == "backward") {
|
else if (m.upHeld && !m.downHeld) { m.playerFacing = "backward"; }
|
||||||
m.playerCurrentSprite = m.playerBackward0;
|
else if (m.downHeld && !m.upHeld) { m.playerFacing = "forward"; }
|
||||||
} else if (m.playerDirection == "right") {
|
|
||||||
m.playerCurrentSprite = m.playerRight0;
|
boolean moving = m.leftHeld != m.rightHeld || m.upHeld || m.downHeld;
|
||||||
m.playerX += m.playerWalkingModifier;
|
|
||||||
} else if (m.playerDirection == "left") {
|
int frame = 0;
|
||||||
m.playerCurrentSprite = m.playerLeft0;
|
if (moving) {
|
||||||
m.playerX -= m.playerWalkingModifier;
|
frame = m.walkCycle[(m.walkTick / m.ticksPerFrame) % m.walkCycle.length];
|
||||||
}
|
m.walkTick++;
|
||||||
if (m.playerJumped) {
|
} else {
|
||||||
m.playerOnFeet = false;
|
m.walkTick = 0;
|
||||||
m.playerY -= 10;
|
|
||||||
if (m.playerOldY-100 >= m.playerY) { m.playerJumped = false; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// collisions
|
if (m.leftHeld && !m.rightHeld) {
|
||||||
if (m.level == 3 && (m.playerY < 338 || (m.playerX >= 583 || m.playerX <= 274) && m.playerY < 366)) {
|
m.playerXVelocity -= m.acceleration;
|
||||||
m.playerY += 5;
|
} else if (m.rightHeld && !m.leftHeld) {
|
||||||
m.playerOnFeet = false;
|
m.playerXVelocity +=m.acceleration;
|
||||||
} else if (m.playerX < 583 && m.playerX > 274) {
|
} else {
|
||||||
m.playerY = 338;
|
if (m.playerXVelocity > 0) {
|
||||||
|
m.playerXVelocity = Math.max(0, m.playerXVelocity - m.friction);
|
||||||
|
} else if (m.playerXVelocity < 0) {
|
||||||
|
m.playerXVelocity = Math.min(0, m.playerXVelocity + m.friction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.playerXVelocity = Math.clamp(m.playerXVelocity, -m.maxSpeed, m.maxSpeed);
|
||||||
|
m.playerX += m.playerXVelocity;
|
||||||
|
m.playerYVelocity = Math.min(m.playerYVelocity + m.gravity, m.maxFall);
|
||||||
|
m.playerY += m.playerYVelocity;
|
||||||
|
|
||||||
|
// jumping and landing mechanics + collisions
|
||||||
|
double groundY = getGroundY(m);
|
||||||
|
if (m.playerY+10 >= groundY) { // the +10 is so it feels like you can jump the instant you touch the ground even tho you technically are a bit above it, just makes the movement feel snappier
|
||||||
|
m.playerY = (int) groundY;
|
||||||
|
m.playerYVelocity = 0;
|
||||||
m.playerOnFeet = true;
|
m.playerOnFeet = true;
|
||||||
} else {
|
} else {
|
||||||
m.playerOnFeet = true;
|
m.playerOnFeet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// first ship
|
// update the player sprite based on direction and if he's walking and frame
|
||||||
if (m.playerX < -m.playerSizeX || m.playerX > m.windowWidth) { m.level = 4; }
|
m.playerCurrentSprite = spriteFor(m, m.playerFacing, frame);
|
||||||
|
// player moving between locations on planets
|
||||||
|
if (m.currentPlayerLocation.equals("landingPlatformZX311")) {
|
||||||
|
if (m.playerX < -m.playerSizeX) {
|
||||||
|
m.currentPlayerLocation = "observatoryZX311";
|
||||||
|
m.playerX = m.windowWidth - m.playerSizeX;
|
||||||
|
} else if (m.playerX > m.windowWidth) {
|
||||||
|
m.currentPlayerLocation = "villageEntranceZX311";
|
||||||
|
m.playerX = m.playerSizeX;
|
||||||
|
}
|
||||||
|
} else if (m.currentPlayerLocation.equals("observatoryZX311")) {
|
||||||
|
if (m.playerX < -m.playerSizeX) {
|
||||||
|
m.currentPlayerLocation = "villageEntranceZX311";
|
||||||
|
m.playerX = m.windowWidth - m.playerSizeX;
|
||||||
|
} else if (m.playerX > m.windowWidth) {
|
||||||
|
m.currentPlayerLocation = "landingPlatformZX311";
|
||||||
|
m.playerX = m.playerSizeX;
|
||||||
|
} else if (m.playerX > 250 && m.playerX < 390 && m.upHeld) {
|
||||||
|
m.currentPlayerLocation = "observatoryInteriorZX311";
|
||||||
|
m.playerX = m.playerSizeX;
|
||||||
|
}
|
||||||
|
} else if (m.currentPlayerLocation.equals("villageEntranceZX311")) {
|
||||||
|
if (m.playerX < -m.playerSizeX) {
|
||||||
|
m.currentPlayerLocation = "landingPlatformZX311";
|
||||||
|
m.playerX = m.windowWidth - m.playerSizeX;
|
||||||
|
} else if (m.playerX > m.windowWidth) {
|
||||||
|
m.currentPlayerLocation = "observatoryZX311";
|
||||||
|
m.playerX = m.playerSizeX;
|
||||||
|
}
|
||||||
|
} else if (m.currentPlayerLocation.equals("credits")) { // these two lines are basically responsible for the ping poing of the player when he reaches the window border on the credits scene lol
|
||||||
|
if (m.playerX < 0) {
|
||||||
|
m.playerXVelocity = 20;
|
||||||
|
} else if (m.playerX > m.windowWidth-m.playerSizeX) {
|
||||||
|
m.playerXVelocity = -20;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// triggers render
|
// triggers render
|
||||||
m.repaint();
|
m.repaint();
|
||||||
}
|
}
|
||||||
static void paint(Game m, Graphics g) {
|
static void paint(Game m, Graphics g) {
|
||||||
if (m.level == 1) {
|
if (m.level == 0) {
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.fillRect(0,0,m.windowWidth,m.windowHeight);
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.setFont(m.caveat.deriveFont(Font.BOLD, 60f));
|
||||||
|
g.drawString("Hey! You discovered my hidden page!", 20, m.windowHeight/2-215);
|
||||||
|
g.setFont(m.caveat.deriveFont(Font.BOLD, 31f));
|
||||||
|
g.drawString("this is my game project made in Java, it's actually my first game written", 20, m.windowHeight/2-200+35);
|
||||||
|
g.drawString("entirely in java, I built it using the Swing library, my only previous", 20, m.windowHeight/2-200+70);
|
||||||
|
g.drawString("experience was with pygame, the biggest advantage to switching to Swing", 20, m.windowHeight/2-200+105);
|
||||||
|
g.drawString("and java is that, this game actually uses your GPU instead of just CPU!", 20, m.windowHeight/2-200+140);
|
||||||
|
g.drawString("meaning you could squeeze in more cool effects than you could in pygame!", 20, m.windowHeight/2-200+175);
|
||||||
|
g.drawString("I plan to finish this project, I've always found space to be really cool", 20, m.windowHeight/2-200+210);
|
||||||
|
g.drawString("and I just didn't find the games about space that are out right now to be", 20, m.windowHeight/2-200+245);
|
||||||
|
g.drawString("as entertaining as I wished, the closest thing was Ad Astra/Galacticraft", 20, m.windowHeight/2-200+280);
|
||||||
|
g.drawString("modpacks in minecraft. I hope you enjoy this game it took me really long", 20, m.windowHeight/2-200+315);
|
||||||
|
g.drawString("time (as im typing this I have 19 hours, and it isnt even close to being", 20, m.windowHeight/2-200+350);
|
||||||
|
g.drawString("finished, for context right now I only finished the animations for the", 20, m.windowHeight/2-200+385);
|
||||||
|
g.drawString("main menu and rocket landing, and the player sprites, that just isn't", 20, m.windowHeight/2-200+420);
|
||||||
|
g.drawString("enough for a playable experience right now but i'll keep working on it!", 20, m.windowHeight/2-200+455);
|
||||||
|
}
|
||||||
|
else if (m.level == 1) {
|
||||||
g.setColor(Color.WHITE);
|
g.setColor(Color.WHITE);
|
||||||
for (int i = 0; i < m.MENU_STAR_COUNT; i++) { // drawing the stars
|
for (int i = 0; i < m.MENU_STAR_COUNT; i++) { // drawing the stars
|
||||||
g.fillOval(m.starX[i]-m.starSize, m.starY[i]-m.starSize, m.starSize, m.starSize);
|
g.fillOval(m.starX[i]-m.starSize, m.starY[i]-m.starSize, m.starSize, m.starSize);
|
||||||
|
|
@ -149,7 +240,7 @@ public class update {
|
||||||
g.fillOval(m.starX[i] - m.starSize, m.starY[i] - m.starSize, m.starSize, m.starSize);
|
g.fillOval(m.starX[i] - m.starSize, m.starY[i] - m.starSize, m.starSize, m.starSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((m.rocketYPre + (m.actionTimer -321)/5) <= 300){
|
if ((m.rocketYPre + (m.actionTimer -321)/5) <= 320){
|
||||||
g.drawImage(m.parachute, m.windowWidth / 2 - 73, m.rocketY - m.hoverYOffset / 3 - 42 + (m.actionTimer -321)/5, 147, 90, m);
|
g.drawImage(m.parachute, m.windowWidth / 2 - 73, m.rocketY - m.hoverYOffset / 3 - 42 + (m.actionTimer -321)/5, 147, 90, m);
|
||||||
g.drawImage(m.rocketTop, m.windowWidth / 2 - 73, m.rocketY - m.hoverYOffset / 3 + (m.actionTimer -321)/5, 147, 84, m);
|
g.drawImage(m.rocketTop, m.windowWidth / 2 - 73, m.rocketY - m.hoverYOffset / 3 + (m.actionTimer -321)/5, 147, 84, m);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -158,24 +249,23 @@ public class update {
|
||||||
g2.drawImage(m.sun, 600, -80, 384, 384, m);
|
g2.drawImage(m.sun, 600, -80, 384, 384, m);
|
||||||
g2.setComposite(AlphaComposite.SrcOver); // reset so nothing else is transparent
|
g2.setComposite(AlphaComposite.SrcOver); // reset so nothing else is transparent
|
||||||
if (m.actionTimer < 1200) {
|
if (m.actionTimer < 1200) {
|
||||||
g.drawImage(m.parachute, m.windowWidth / 2 - 73, 258, 147, 90, m);
|
g.drawImage(m.parachute, m.windowWidth / 2 - 73, 278, 147, 90, m);
|
||||||
g.drawImage(m.rocketTop, m.windowWidth / 2 - 73, 300, 147, 84, m);
|
g.drawImage(m.rocketTop, m.windowWidth / 2 - 73, 320, 147, 84, m);
|
||||||
} else if (1400 > m.actionTimer && m.actionTimer >= 1200) {
|
} else if (1400 > m.actionTimer && m.actionTimer >= 1200) {
|
||||||
g.drawImage(m.parachute, m.windowWidth / 2 - 73, 258, 147, 90, m);
|
g.drawImage(m.parachute, m.windowWidth / 2 - 73, 278, 147, 90, m);
|
||||||
g.drawImage(m.rocketLanding0, m.windowWidth / 2 - 73, 300, 147, 111, m);
|
g.drawImage(m.rocketLanding0, m.windowWidth / 2 - 73, 320, 147, 111, m);
|
||||||
} else if (1400 <= m.actionTimer && m.actionTimer < 1550) {;
|
} else if (1400 <= m.actionTimer && m.actionTimer < 1550) {;
|
||||||
g.drawImage(m.parachute, m.windowWidth / 2 - 73, 258, 147, 90, m);
|
g.drawImage(m.parachute, m.windowWidth / 2 - 73, 278, 147, 90, m);
|
||||||
g.drawImage(m.rocketLanding1, m.windowWidth / 2 - 73, 300, 147, 111, m);
|
g.drawImage(m.rocketLanding1, m.windowWidth / 2 - 73, 320, 147, 111, m);
|
||||||
} else {
|
} else {
|
||||||
g.drawImage(m.parachute, m.windowWidth / 2 - 73, 258+(m.actionTimer -1550)*3/2, 147, 90, m); // parachute is falling!
|
g.drawImage(m.parachute, m.windowWidth / 2 - 73, 278+(m.actionTimer -1550)*3/2, 147, 90, m); // parachute is falling!
|
||||||
g.drawImage(m.rocketLanding1, m.windowWidth / 2 - 73, 300, 147, 111, m);
|
g.drawImage(m.rocketLanding1, m.windowWidth / 2 - 73, 320, 147, 111, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (windowHeight-210) is the desired height
|
if ((1100-(m.actionTimer / 2 )) >= 370) {
|
||||||
if ((1100-(m.actionTimer / 2 )) >= 340) {
|
g.drawImage(m.landingPlatform, 0, 1100-(m.actionTimer /2), m.windowWidth, m.windowWidth/256*60, m);
|
||||||
g.drawImage(m.landingPlatform, 0, 1100-(m.actionTimer /2), m.windowWidth, m.windowWidth/128*30, m);
|
|
||||||
} else {
|
} else {
|
||||||
g.drawImage(m.landingPlatform, 0, 340, m.windowWidth, m.windowWidth/128*30, m);
|
g.drawImage(m.landingPlatform, 0, 370, m.windowWidth, m.windowWidth/256*60, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,14 +290,57 @@ public class update {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m.level == 3) {
|
else if (m.level == 3) {
|
||||||
g.setColor(new Color(127, 127,255));
|
if (m.currentPlayerLocation.equals("landingPlatformZX311")) {
|
||||||
g.fillRect(0,0,m.windowWidth,m.windowHeight);
|
g.setColor(new Color(127, 127, 255));
|
||||||
|
g.fillRect(0, 0, m.windowWidth, m.windowHeight);
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, m.opacityAnimation));
|
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, m.opacityAnimation));
|
||||||
g2.drawImage(m.sun, 600, -80, 384, 384, m);
|
g2.drawImage(m.sun, 600, -80, 384, 384, m);
|
||||||
g2.setComposite(AlphaComposite.SrcOver); // reset so nothing else is transparent
|
g2.setComposite(AlphaComposite.SrcOver); // reset so nothing else is transparent
|
||||||
g.drawImage(m.landingPlatform, 0, 340, m.windowWidth, m.windowWidth/128*30, m);
|
g.drawImage(m.landingPlatform, 0, 370, m.windowWidth, m.windowWidth / 256 * 60, m);
|
||||||
g.drawImage(m.rocketLanding1, m.windowWidth / 2 - 73, 300, 147, 111, m);
|
g.drawImage(m.rocketLanding1, m.windowWidth / 2 - 73, 320, 147, 111, m);
|
||||||
|
} else if (m.currentPlayerLocation.equals("observatoryZX311")) {
|
||||||
|
g.setColor(new Color(127, 127, 255));
|
||||||
|
g.fillRect(0, 0, m.windowWidth, m.windowHeight);
|
||||||
|
if (m.playerX > 240 && m.playerX < 400) {
|
||||||
|
g.drawImage(m.openedObservatory, 100, 457 - 449, 235 * 2, 228 * 2, m);
|
||||||
|
} else {
|
||||||
|
g.drawImage(m.closedObservatory, 100, 457 - 449, 235 * 2, 228 * 2, m);
|
||||||
|
}
|
||||||
|
g.drawImage(m.planetZX311Land, 0, 457, m.windowWidth, m.windowWidth/256*31, m);
|
||||||
|
if (m.playerX > 250 && m.playerX < 390) {
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.setFont(m.caveat.deriveFont(Font.BOLD, 30f));
|
||||||
|
g.drawString("Press W or UP arrow key to enter the observatory.", 180, m.windowHeight-35);
|
||||||
|
}
|
||||||
|
} else if (m.currentPlayerLocation.equals("observatoryInteriorZX311")) {
|
||||||
|
g.setColor(new Color(15, 15, 15));
|
||||||
|
g.fillRect(0, 0, m.windowWidth, m.windowHeight);
|
||||||
|
g.setColor(new Color(20, 20, 20));
|
||||||
|
g.fillRect(0, 0, m.windowWidth, 340+128);
|
||||||
|
if (m.playerX > 75) {
|
||||||
|
g.drawImage(m.doorObservatory, 0, 340, 50, 128, m);
|
||||||
|
if (m.playerX > m.windowWidth) {
|
||||||
|
m.playerX = -25;
|
||||||
|
m.currentPlayerLocation = "credits";
|
||||||
|
m.level = 4;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
g.setColor(Color.black);
|
||||||
|
g.fillRect(0, 340, 50, 127);
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.setFont(m.caveat.deriveFont(Font.BOLD, 30f));
|
||||||
|
g.drawString("Keep walking to the left thru the door to leave.", 180, m.windowHeight-35);
|
||||||
|
if (m.playerX < -m.playerSizeX) {
|
||||||
|
m.playerX = 320;
|
||||||
|
m.currentPlayerLocation = "observatoryZX311";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (m.currentPlayerLocation.equals("villageEntranceZX311")) {
|
||||||
|
g.setColor(new Color(127, 127, 255));
|
||||||
|
g.fillRect(0, 0, m.windowWidth, m.windowHeight);
|
||||||
|
g.drawImage(m.planetZX311Land, 0, 457, m.windowWidth, m.windowWidth/256*31, m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
|
@ -215,14 +348,14 @@ public class update {
|
||||||
g.setColor(Color.WHITE);
|
g.setColor(Color.WHITE);
|
||||||
g.setFont(m.caveat.deriveFont(Font.BOLD, 56f));
|
g.setFont(m.caveat.deriveFont(Font.BOLD, 56f));
|
||||||
g.drawString("Sorry, this is as far as I got with", 30, m.windowHeight/2-160);
|
g.drawString("Sorry, this is as far as I got with", 30, m.windowHeight/2-160);
|
||||||
g.drawString("this project, It's still a work in", 30, m.windowHeight/2-160+70);
|
g.drawString("this project so far, It's still a work", 30, m.windowHeight/2-160+70);
|
||||||
g.drawString("progress so I'll definitely add more", 30, m.windowHeight/2-160+140);
|
g.drawString("in progress so I'll definitely add more", 30, m.windowHeight/2-160+140);
|
||||||
g.drawString("content but I just wanted to make sure", 30, m.windowHeight/2-160+210);
|
g.drawString("content but I just wanted to make sure", 30, m.windowHeight/2-160+210);
|
||||||
g.drawString("that I could ship it for now so I", 30, m.windowHeight/2-160+280);
|
g.drawString("that I could ship it for now so I", 30, m.windowHeight/2-160+280);
|
||||||
g.drawString("could be safe from ratticus (I'm scared)", 30, m.windowHeight/2-160+350);
|
g.drawString("could be safe from Ratticus (I'm scared)", 30, m.windowHeight/2-160+350);
|
||||||
}
|
}
|
||||||
if (m.playerActive) {
|
if (m.playerActive) {
|
||||||
g.drawImage(m.playerCurrentSprite, m.playerX, m.playerY, m.playerSizeX, m.playerSizeY, m);
|
g.drawImage(m.playerCurrentSprite, (int) m.playerX, (int) m.playerY, m.playerSizeX, m.playerSizeY, m);
|
||||||
}
|
}
|
||||||
Toolkit.getDefaultToolkit().sync();
|
Toolkit.getDefaultToolkit().sync();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 638 B After Width: | Height: | Size: 1.7 KiB |
BIN
src/main/resources/assets/landingPlatform.png-autosave.kra
Normal file
BIN
src/main/resources/assets/landingPlatform.png~
Normal file
|
After Width: | Height: | Size: 638 B |
BIN
src/main/resources/assets/observatoryClosed.png
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
src/main/resources/assets/observatoryDoor.png
Normal file
|
After Width: | Height: | Size: 405 B |
BIN
src/main/resources/assets/observatoryDoor.png~
Normal file
|
After Width: | Height: | Size: 468 B |
BIN
src/main/resources/assets/observatoryOpened.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
src/main/resources/assets/planetZX311Land.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/main/resources/preview.png
Normal file
|
After Width: | Height: | Size: 166 KiB |