summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-03-07 19:41:05 -0800
committerElizabeth Alexander Hunt <me@liz.coffee>2026-03-07 19:46:56 -0800
commit1f628c9ee7e08206752cf12f2424de931904ecdd (patch)
tree016eec8f5397082c47155fb25242aefb53b6795c
parentf643f0afb8c7d91a7a39ff96f58b95baac985ce0 (diff)
downloaddyl-1f628c9ee7e08206752cf12f2424de931904ecdd.tar.gz
dyl-1f628c9ee7e08206752cf12f2424de931904ecdd.zip
Adding coyote time and tweaking jumping physics constants a bit
-rw-r--r--core/src/main/java/coffee/liz/dyl/actions/JumpAction.java6
-rw-r--r--core/src/main/java/coffee/liz/dyl/components/physics/CollisionContacts.java3
-rw-r--r--core/src/main/java/coffee/liz/dyl/components/physics/Jump.java1
-rw-r--r--core/src/main/java/coffee/liz/dyl/config/PhysicsConstants.java15
-rw-r--r--core/src/main/java/coffee/liz/dyl/systems/control/InputSystem.java4
-rw-r--r--core/src/main/java/coffee/liz/dyl/systems/control/JumpActionConsumerSystem.java26
-rw-r--r--core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java3
-rw-r--r--docs/todo.txt2
-rw-r--r--lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java2
9 files changed, 43 insertions, 19 deletions
diff --git a/core/src/main/java/coffee/liz/dyl/actions/JumpAction.java b/core/src/main/java/coffee/liz/dyl/actions/JumpAction.java
index 0d8eda5..6143da6 100644
--- a/core/src/main/java/coffee/liz/dyl/actions/JumpAction.java
+++ b/core/src/main/java/coffee/liz/dyl/actions/JumpAction.java
@@ -1,4 +1,10 @@
package coffee.liz.dyl.actions;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor
+@Getter
public class JumpAction implements Action {
+ private final boolean justPressed;
}
diff --git a/core/src/main/java/coffee/liz/dyl/components/physics/CollisionContacts.java b/core/src/main/java/coffee/liz/dyl/components/physics/CollisionContacts.java
index 033c3b6..b76dcb5 100644
--- a/core/src/main/java/coffee/liz/dyl/components/physics/CollisionContacts.java
+++ b/core/src/main/java/coffee/liz/dyl/components/physics/CollisionContacts.java
@@ -5,6 +5,7 @@ import coffee.liz.ecs.model.Component;
import coffee.liz.ecs.model.Entity;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import lombok.Setter;
import java.util.ArrayList;
import java.util.Collections;
@@ -13,6 +14,8 @@ import java.util.List;
@Getter
public class CollisionContacts implements Component {
private final List<Contact> contacts = new ArrayList<>();
+ @Setter
+ private float lastGroundedTime;
public void clear() {
contacts.clear();
diff --git a/core/src/main/java/coffee/liz/dyl/components/physics/Jump.java b/core/src/main/java/coffee/liz/dyl/components/physics/Jump.java
index c791040..912d4af 100644
--- a/core/src/main/java/coffee/liz/dyl/components/physics/Jump.java
+++ b/core/src/main/java/coffee/liz/dyl/components/physics/Jump.java
@@ -12,4 +12,5 @@ import lombok.Setter;
@Setter
public class Jump implements Component {
private float startTime;
+ private boolean applyForce;
}
diff --git a/core/src/main/java/coffee/liz/dyl/config/PhysicsConstants.java b/core/src/main/java/coffee/liz/dyl/config/PhysicsConstants.java
index 6414629..f28a1a0 100644
--- a/core/src/main/java/coffee/liz/dyl/config/PhysicsConstants.java
+++ b/core/src/main/java/coffee/liz/dyl/config/PhysicsConstants.java
@@ -1,13 +1,14 @@
package coffee.liz.dyl.config;
public final class PhysicsConstants {
- public static final float GRAVITY = 40f;
- public static final float ADDITIONAL_JUMP_OVER_GRAVITY = 1.05f;
- public static final float MOVE_SPEED = 8.0f;
- public static final float JUMP_INITIAL_VEL = 10.0f;
- public static final float MAX_JUMP_SECONDS = 0.1f;
- public static final float JUMP_BUFFER_SECONDS = 0.2f;
- public static final float JUMP_CUT_FACTOR = 0.5f;
+ public static final float GRAVITY = 52f;
+ public static final float ADDITIONAL_JUMP_OVER_GRAVITY = 1.30f;
+ public static final float MOVE_SPEED = 9.0f;
+ public static final float JUMP_IMPULSE_VEL = 10.0f;
+ public static final float JUMP_SUSTAIN_FORCE = 20;
+ public static final float MAX_JUMP_SECONDS = 0.22f;
+ public static final float JUMP_BUFFER_SECONDS = 0.15f;
+ public static final float COYOTE_TIME_SECONDS = 0.08f;
public static final float DAMAGE_TIME = 0.25f;
private PhysicsConstants() { }
diff --git a/core/src/main/java/coffee/liz/dyl/systems/control/InputSystem.java b/core/src/main/java/coffee/liz/dyl/systems/control/InputSystem.java
index ca114ee..4123604 100644
--- a/core/src/main/java/coffee/liz/dyl/systems/control/InputSystem.java
+++ b/core/src/main/java/coffee/liz/dyl/systems/control/InputSystem.java
@@ -43,8 +43,8 @@ public class InputSystem implements System {
actionQueue.queue(action, time);
}
- if (entity.has(Jumpable.class) && justPressed.contains(KeyBinds.Action.JUMP)) {
- actionQueue.queue(new JumpAction(), time, JUMP_BUFFER_SECONDS);
+ if (entity.has(Jumpable.class) && held.contains(KeyBinds.Action.JUMP)) {
+ actionQueue.queue(new JumpAction(justPressed.contains(KeyBinds.Action.JUMP)), time, JUMP_BUFFER_SECONDS);
}
});
}
diff --git a/core/src/main/java/coffee/liz/dyl/systems/control/JumpActionConsumerSystem.java b/core/src/main/java/coffee/liz/dyl/systems/control/JumpActionConsumerSystem.java
index eadc402..d9bdcb9 100644
--- a/core/src/main/java/coffee/liz/dyl/systems/control/JumpActionConsumerSystem.java
+++ b/core/src/main/java/coffee/liz/dyl/systems/control/JumpActionConsumerSystem.java
@@ -5,6 +5,7 @@ import coffee.liz.dyl.components.control.ActionQueue;
import coffee.liz.dyl.components.physics.*;
import coffee.liz.dyl.config.PhysicsConstants;
import coffee.liz.dyl.systems.collision.SolidCollisionSystem;
+import coffee.liz.ecs.math.Vec2f;
import coffee.liz.ecs.model.System;
import coffee.liz.ecs.model.World;
@@ -31,6 +32,11 @@ public class JumpActionConsumerSystem implements System {
.anyMatch(contact -> contact.getSeparationVector().getY() > 0 && contact.getContactEntity().has(Solid.class));
final boolean hasCurrentJump = entity.has(Jump.class);
+ if (solidUnderUs) {
+ contacts.setLastGroundedTime(time);
+ }
+ final boolean withinCoyoteTime = (time - contacts.getLastGroundedTime()) <= PhysicsConstants.COYOTE_TIME_SECONDS;
+
final boolean bonkedIntoCeiling = solidOverUs && hasCurrentJump;
final boolean justHitFloor = solidUnderUs && hasCurrentJump;
final boolean notJumping = !hasCurrentJump || bonkedIntoCeiling || justHitFloor;
@@ -38,16 +44,24 @@ public class JumpActionConsumerSystem implements System {
entity.remove(Jump.class);
}
- queue.consume(JumpAction.class, time, _action -> {
- if (notJumping && solidUnderUs) {
- entity.add(new Jump(time));
+ final boolean doneControllingHeightOfJumpForce = entity.has(Jump.class) && !queue.has(JumpAction.class);
+ if (doneControllingHeightOfJumpForce) {
+ entity.get(Jump.class).setApplyForce(false);
+ }
+
+ queue.consume(JumpAction.class, time, action -> {
+ final boolean canStartJump = notJumping && (solidUnderUs || withinCoyoteTime) && action.isJustPressed();
+ if (canStartJump) {
+ velocity.setVelocity(velocity.getVelocity()
+ .transform(x -> x, y -> PhysicsConstants.JUMP_IMPULSE_VEL));
+ entity.add(new Jump(time, true));
+ contacts.setLastGroundedTime(0f);
}
if (entity.has(Jump.class)) {
final Jump jump = entity.get(Jump.class);
final boolean inTimeWindowToApplyJump = (time - jump.getStartTime()) <= PhysicsConstants.MAX_JUMP_SECONDS;
- if (inTimeWindowToApplyJump) {
- velocity.setVelocity(velocity.getVelocity()
- .transform(x -> x, y -> PhysicsConstants.JUMP_INITIAL_VEL));
+ if (inTimeWindowToApplyJump && jump.isApplyForce() && entity.has(Forces.class)) {
+ entity.get(Forces.class).add(new Force(new Vec2f(0f, PhysicsConstants.JUMP_SUSTAIN_FORCE)));
return true;
}
}
diff --git a/core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java b/core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java
index fb1f847..c35f1da 100644
--- a/core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java
+++ b/core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java
@@ -23,8 +23,7 @@ import com.badlogic.gdx.Gdx;
public class DylGameWorld extends DAGWorld {
public DylGameWorld(final DylGame game) {
super(
- new InputSystem(
- () -> game.getSettings().getKeyBinds().filterActiveActions(Gdx.input::isKeyPressed),
+ new InputSystem(() -> game.getSettings().getKeyBinds().filterActiveActions(Gdx.input::isKeyPressed),
() -> game.getSettings().getKeyBinds().filterActiveActions(Gdx.input::isKeyJustPressed)),
new AccelerationSystem(PhysicsConstants.GRAVITY),
new MovementSystem(),
diff --git a/docs/todo.txt b/docs/todo.txt
index 023868e..7d80f0f 100644
--- a/docs/todo.txt
+++ b/docs/todo.txt
@@ -1,5 +1,5 @@
Terrain:
-- [ ] Basic platforming
+- [X] Basic platforming
- [ ] First dungeon
- [ ] First overworld attempt
diff --git a/lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java b/lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java
index 3c2990b..1c3d152 100644
--- a/lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java
+++ b/lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java
@@ -26,7 +26,7 @@ public class Lwjgl3Launcher {
//// useful for testing performance, but can also be very stressful to some hardware.
//// You may also need to configure GPU drivers to fully disable Vsync; this can cause screen tearing.
- configuration.setDecorated(false);
+ configuration.setDecorated(true);
configuration.setWindowedMode(1024, 1024);
//// You can change these files; they are in lwjgl3/src/main/resources/ .
//// They can also be loaded from the root of assets/ .