From 763339edcb198326bad1c70b12a50ee5fd97f081 Mon Sep 17 00:00:00 2001 From: Wyatt Jacob Herkamp Date: Sun, 21 Feb 2021 08:09:18 -0500 Subject: [PATCH 1/3] Starting better jump --- .../client/scenes/maingamescene/PlayerMovement.java | 11 ++++++++--- .../client/scenes/maingamescene/SceneUtils.java | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java b/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java index 4d0efc60..7c8a298c 100644 --- a/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java +++ b/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java @@ -20,6 +20,7 @@ public class PlayerMovement { boolean playerInJump = false; + boolean hasJumped = false; float lastYPos = 0; private final MainGameScene mainGameScene; private MeshGameItem item; @@ -64,14 +65,15 @@ protected void playerMovement() { if (ki.isKeyPressed(GLFW_KEY_LEFT_SHIFT)) { item.movePositionByCamera(0, -0.3f, 0, gameCamera); } - if (ki.isKeyPressed(GLFW_KEY_SPACE) && !playerInJump) { + if (ki.isKeyPressed(GLFW_KEY_SPACE) && !playerInJump && !hasJumped) { playerInJump = true; + hasJumped = true; lastYPos = item.getPosition().y; item.setVelocityY(4); } - if (playerInJump) { + if(playerInJump){ item.movePositionByCamera(0, 0.3F, 0, gameCamera); - if (item.getPosition().y > lastYPos + 3) { + if (item.getPosition().y > lastYPos + 1.1) { playerInJump = false; item.setVelocityY(-9.18f); } @@ -105,4 +107,7 @@ protected void playerMovement() { } } + public void resetJump() { + if (hasJumped) hasJumped = false; + } } diff --git a/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java b/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java index fa076a4e..00813482 100644 --- a/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java +++ b/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java @@ -38,7 +38,8 @@ protected UUID createPlayerObject() { return true; } } - + //TODO check if bottom of player has touched the ground. Currently just reset on any touch. + gameScene.movement.resetJump(); return false; }); object.setCollider(boxCollider); From fd21619fb6cb3c4597cf2d5dfbe1ea63db1696d0 Mon Sep 17 00:00:00 2001 From: Wyatt Jacob Herkamp Date: Sun, 28 Feb 2021 19:38:01 -0500 Subject: [PATCH 2/3] Updated Engine --- .../scenes/maingamescene/PlayerMovement.java | 64 ++++++++++--------- .../scenes/maingamescene/SceneUtils.java | 31 +++++---- 2 files changed, 54 insertions(+), 41 deletions(-) diff --git a/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java b/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java index 7c8a298c..8c8b1284 100644 --- a/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java +++ b/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java @@ -6,12 +6,15 @@ import org.kakara.core.common.world.Location; import org.kakara.engine.Camera; import org.kakara.engine.gameitems.GameItem; -import org.kakara.engine.gameitems.MeshGameItem; -import org.kakara.engine.input.KeyInput; -import org.kakara.engine.input.MouseInput; + +import org.kakara.engine.input.key.KeyInput; +import org.kakara.engine.input.mouse.MouseInput; import org.kakara.engine.math.Vector3; -import org.kakara.engine.physics.collision.Collidable; -import org.kakara.engine.renderobjects.RenderBlock; +import org.kakara.engine.physics.collision.ColliderComponent; +import org.kakara.engine.physics.collision.PhysicsComponent; +import org.kakara.engine.physics.collision.VoxelCollider; +import org.kakara.engine.voxels.Voxel; + import java.util.Optional; import java.util.UUID; @@ -23,12 +26,13 @@ public class PlayerMovement { boolean hasJumped = false; float lastYPos = 0; private final MainGameScene mainGameScene; - private MeshGameItem item; - + private GameItem item; + private PhysicsComponent physicsComponent; public PlayerMovement(MainGameScene mainGameScene) { this.mainGameScene = mainGameScene; } + protected void playerMovement() { if (mainGameScene.chatComponent != null) { if (mainGameScene.chatComponent.isFocused()) return; @@ -43,48 +47,48 @@ protected void playerMovement() { if (gameItemID.isEmpty()) return; Optional itemByID = mainGameScene.sceneUtils.getItemByID(gameItemID.get()); if (itemByID.isEmpty()) return; - item = (MeshGameItem) itemByID.get(); + item = itemByID.get(); + physicsComponent = item.getComponent(PhysicsComponent.class); } - item.setVelocityX(0); - item.setVelocityZ(0); + physicsComponent.setVelocityX(0); + physicsComponent.setVelocityZ(0); Camera gameCamera = mainGameScene.getCamera(); KeyInput ki = mainGameScene.kakaraGame.getGameHandler().getKeyInput(); if (ki.isKeyPressed(GLFW_KEY_W)) { - item.setVelocityByCamera(new Vector3(0, item.getVelocity().y, -7), gameCamera); + physicsComponent.setVelocityByCamera(new Vector3(0, physicsComponent.getVelocity().y, -7), gameCamera); } if (ki.isKeyPressed(GLFW_KEY_S)) { - item.setVelocityByCamera(new Vector3(0, item.getVelocity().y, 7), gameCamera); + physicsComponent.setVelocityByCamera(new Vector3(0, physicsComponent.getVelocity().y, 7), gameCamera); } if (ki.isKeyPressed(GLFW_KEY_A)) { - item.setVelocityByCamera(new Vector3(-7, item.getVelocity().y, 0), gameCamera); + physicsComponent.setVelocityByCamera(new Vector3(-7, physicsComponent.getVelocity().y, 0), gameCamera); } if (ki.isKeyPressed(GLFW_KEY_D)) { - item.setVelocityByCamera(new Vector3(7, item.getVelocity().y, 0), gameCamera); + physicsComponent.setVelocityByCamera(new Vector3(7, physicsComponent.getVelocity().y, 0), gameCamera); } if (ki.isKeyPressed(GLFW_KEY_LEFT_SHIFT)) { - item.movePositionByCamera(0, -0.3f, 0, gameCamera); + item.transform.movePositionByCamera(0, -0.3f, 0, gameCamera); } if (ki.isKeyPressed(GLFW_KEY_SPACE) && !playerInJump && !hasJumped) { playerInJump = true; - hasJumped = true; - lastYPos = item.getPosition().y; - item.setVelocityY(4); + lastYPos = item.transform.getPosition().y; + physicsComponent.setVelocityY(4); } - if(playerInJump){ - item.movePositionByCamera(0, 0.3F, 0, gameCamera); - if (item.getPosition().y > lastYPos + 1.1) { + if (playerInJump) { + physicsComponent.getTransform().movePositionByCamera(0, 0.3F, 0, gameCamera); + if (physicsComponent.getTransform().getPosition().y > lastYPos + 3) { playerInJump = false; - item.setVelocityY(-9.18f); + physicsComponent.setVelocityY(-9.18f); } } if (ki.isKeyPressed(GLFW_KEY_G)) - item.setVelocityY(-9.18f); + physicsComponent.setVelocityY(-9.18f); MouseInput mi = mainGameScene.kakaraGame.getGameHandler().getMouseInput(); Location location; - location = new Location(player.getLocation().getNullableWorld(), item.getPosition().x, item.getPosition().y, item.getPosition().z, player.getLocation().getPitch(), player.getLocation().getYaw()); + location = new Location(player.getLocation().getNullableWorld(), item.transform.getPosition().x, item.transform.getPosition().y, item.transform.getPosition().z, player.getLocation().getPitch(), player.getLocation().getYaw()); location = location.add(new Location(0, 0, 0, (float) mi.getDeltaPosition().y(), (float) mi.getDeltaPosition().x())); ((ClientServerController) mainGameScene.getServer().getServerController()).playerMove(location); //TODO change ordering. In this current method on a server will result in large amounts of lag. @@ -93,14 +97,16 @@ protected void playerMovement() { mainGameScene.getCamera().setRotation(l.getPitch(), l.getYaw(), 0); // Handle the block selector. try { - Collidable objectFound = mainGameScene.selectGameItems(20, gameItemID.get()); + ColliderComponent objectFound = mainGameScene.selectGameItems(20, gameItemID.get()); if (mainGameScene.blockSelector != null) { - if (objectFound instanceof RenderBlock) { - RenderBlock block = (RenderBlock) objectFound; + + if (objectFound instanceof VoxelCollider) { + VoxelCollider objectFound1 = (VoxelCollider) objectFound; + Voxel block = objectFound1.getVoxel(); // This does not mutate the Vector3. - mainGameScene.blockSelector.setPosition(block.getPosition().add(block.getParentChunk().getPosition())); + mainGameScene.blockSelector.transform.setPosition(block.getPosition().add(block.getParentChunk().getTransform().getPosition())); } else { - mainGameScene.blockSelector.setPosition((float) l.getX(), -10, (float) l.getZ()); + mainGameScene.blockSelector.transform.setPosition((float) l.getX(), -10, (float) l.getZ()); } } } catch (NullPointerException ignored) { diff --git a/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java b/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java index 00813482..9bee3be5 100644 --- a/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java +++ b/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java @@ -1,11 +1,13 @@ package org.kakara.client.scenes.maingamescene; +import org.kakara.core.common.Kakara; +import org.kakara.engine.components.MeshRenderer; import org.kakara.engine.gameitems.GameItem; -import org.kakara.engine.gameitems.MeshGameItem; import org.kakara.engine.gameitems.mesh.Mesh; import org.kakara.engine.math.Vector3; import org.kakara.engine.models.StaticModelLoader; import org.kakara.engine.physics.collision.BoxCollider; +import org.kakara.engine.physics.collision.PhysicsComponent; import java.util.Optional; import java.util.UUID; @@ -21,6 +23,7 @@ protected Optional getItemByID(UUID uuid) { return gameScene.getItemHandler().getItemWithId(uuid); } + protected UUID createPlayerObject() { Mesh[] mainPlayer = null; try { @@ -28,22 +31,26 @@ protected UUID createPlayerObject() { } catch (Exception e) { e.printStackTrace(); } - MeshGameItem object = new MeshGameItem(mainPlayer); - object.setVisible(false); - object.setPosition((float) gameScene.getServer().getPlayerEntity().getLocation().getX(), (float) gameScene.getServer().getPlayerEntity().getLocation().getY(), (float) gameScene.getServer().getPlayerEntity().getLocation().getZ()); - BoxCollider boxCollider = new BoxCollider(new Vector3(0, 0, 0), new Vector3(0.99f, 1.99f, 0.99f)); + GameItem object = new GameItem(mainPlayer); + object.getComponent(MeshRenderer.class).setVisible(false); + object.transform.setPosition((float) gameScene.getServer().getPlayerEntity().getLocation().getX(), (float) gameScene.getServer().getPlayerEntity().getLocation().getY(), (float) gameScene.getServer().getPlayerEntity().getLocation().getZ()); + PhysicsComponent physicsComponent = object.addComponent(PhysicsComponent.class); + BoxCollider boxCollider = object.addComponent(BoxCollider.class); + boxCollider.setPoint1(new Vector3(0, 0, 0)); + boxCollider.setPoint2(new Vector3(0.99f, 1.99f, 0.99f)); boxCollider.setPredicate(collidable -> { - if (collidable instanceof MeshGameItem) { - if (((MeshGameItem) collidable).getTag().equals("pickupable")) { - return true; - } - } - //TODO check if bottom of player has touched the ground. Currently just reset on any touch. gameScene.movement.resetJump(); + + if (collidable.getGameItem() == null) return false; //How? + if (collidable.getGameItem().getTag() == null) return false; + if (collidable.getGameItem().getTag().equals("pickupable")) { + return true; + } + return false; }); - object.setCollider(boxCollider); gameScene.add(object); + Kakara.LOGGER.debug("Player created with the UUID of "+ object.getUUID().toString()); return object.getUUID(); } } From fbb2271615126e643a5ab536d51d56a92f9693e9 Mon Sep 17 00:00:00 2001 From: Wyatt J Herkamp Date: Sun, 2 May 2021 15:28:06 -0400 Subject: [PATCH 3/3] Merged Master --- .../client/scenes/maingamescene/PlayerMovement.java | 8 ++++++-- .../kakara/client/scenes/maingamescene/SceneUtils.java | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java b/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java index b2430570..8e12d2db 100644 --- a/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java +++ b/client/src/main/java/org/kakara/client/scenes/maingamescene/PlayerMovement.java @@ -21,11 +21,13 @@ // TODO:: Make this class a component and add it to the player GameItem. public class PlayerMovement { boolean playerInJump = false; + boolean hasJumped = false; float lastYPos = 0; private final MainGameScene mainGameScene; private GameItem item; private PhysicsComponent physicsComponent; + public PlayerMovement(MainGameScene mainGameScene) { this.mainGameScene = mainGameScene; } @@ -67,7 +69,7 @@ protected void playerMovement() { if (Input.isKeyDown(KeyCode.LEFT_SHIFT)) { item.transform.movePositionByCamera(0, -0.3f, 0, gameCamera); } - if (Input.isKeyDown(KeyCode.SPACE) && !playerInJump) { + if (Input.isKeyDown(KeyCode.SPACE) && !playerInJump&& !hasJumped) { playerInJump = true; lastYPos = item.transform.getPosition().y; physicsComponent.setVelocityY(4); @@ -110,5 +112,7 @@ protected void playerMovement() { } catch (NullPointerException ignored) { } } - + public void resetJump() { + if (hasJumped) hasJumped = false; + } } diff --git a/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java b/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java index 9bee3be5..bdd71354 100644 --- a/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java +++ b/client/src/main/java/org/kakara/client/scenes/maingamescene/SceneUtils.java @@ -53,4 +53,5 @@ protected UUID createPlayerObject() { Kakara.LOGGER.debug("Player created with the UUID of "+ object.getUUID().toString()); return object.getUUID(); } + }