redesigned asset/made more accurate collisions
This commit is contained in:
parent
d32e8a8225
commit
d1841f0b3a
6 changed files with 9 additions and 5 deletions
|
|
@ -52,7 +52,7 @@ public class Game extends JPanel implements ActionListener {
|
||||||
public static BufferedImage playerRight2;
|
public static BufferedImage playerRight2;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
@ -15,6 +16,8 @@ public class input implements KeyListener {
|
||||||
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> m.leftHeld = true;
|
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> m.leftHeld = true;
|
||||||
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> m.downHeld = true;
|
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> m.downHeld = true;
|
||||||
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> m.rightHeld = true;
|
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> m.rightHeld = true;
|
||||||
|
// debug
|
||||||
|
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.playerOnFeet) {
|
if (m.playerOnFeet) {
|
||||||
m.playerYVelocity = m.jumpSpeed;
|
m.playerYVelocity = m.jumpSpeed;
|
||||||
|
|
@ -27,7 +30,8 @@ public class input implements KeyListener {
|
||||||
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 ITS IMPOSSIBLE TO KNOW ABOUT IT WITHOUT READING THE CODE LOL
|
// THE LINE BELOW IS FOR ME WHEN DEBUGGING, I LEFT IT IN BECAUSE ITS IMPOSSIBLE TO KNOW ABOUT IT WITHOUT READING THE CODE LOL
|
||||||
case KeyEvent.VK_DELETE -> {
|
case KeyEvent.VK_TAB -> m.timer = new Timer(16, m); // slows back the game animations (62fps)
|
||||||
|
case KeyEvent.VK_SLASH -> {
|
||||||
m.level = 3;
|
m.level = 3;
|
||||||
m.playerActive = true;
|
m.playerActive = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ public class update {
|
||||||
}
|
}
|
||||||
public static double getGroundY(Game m) {
|
public static double getGroundY(Game m) {
|
||||||
if (m.level == 3) {
|
if (m.level == 3) {
|
||||||
if (m.playerX > 274 && m.playerX < 583) { return 338; } else { return 366; }
|
if (m.playerX > 290 && m.playerX < 572) { return 338; } else { return 366; }
|
||||||
} else {
|
} else {
|
||||||
return m.windowHeight;
|
return m.windowHeight-m.playerSizeY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void performPerTick(Game m) {
|
static void performPerTick(Game m) {
|
||||||
|
|
@ -92,7 +92,7 @@ public class update {
|
||||||
m.playerYVelocity = Math.min(m.playerYVelocity + m.gravity, m.maxFall);
|
m.playerYVelocity = Math.min(m.playerYVelocity + m.gravity, m.maxFall);
|
||||||
m.playerY += m.playerYVelocity;
|
m.playerY += m.playerYVelocity;
|
||||||
|
|
||||||
// collisions
|
// jumping and landing mechanics + collisions
|
||||||
double groundY = getGroundY(m);
|
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
|
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.playerY = (int) groundY;
|
||||||
|
|
|
||||||
Binary file not shown.
|
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-autosave.kra
Normal file
Binary file not shown.
BIN
src/main/resources/assets/landingPlatform.png~
Normal file
BIN
src/main/resources/assets/landingPlatform.png~
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 638 B |
Loading…
Add table
Add a link
Reference in a new issue