Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Game mechanics #107

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -110,5 +112,7 @@ protected void playerMovement() {
} catch (NullPointerException ignored) {
}
}

public void resetJump() {
if (hasJumped) hasJumped = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected Optional<GameItem> getItemByID(UUID uuid) {
return gameScene.getItemHandler().getItemWithId(uuid);
}


protected UUID createPlayerObject() {
Mesh[] mainPlayer = null;
try {
Expand All @@ -38,15 +39,19 @@ protected UUID createPlayerObject() {
boxCollider.setPoint1(new Vector3(0, 0, 0));
boxCollider.setPoint2(new Vector3(0.99f, 1.99f, 0.99f));
boxCollider.setPredicate(collidable -> {
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;
});
gameScene.add(object);
Kakara.LOGGER.debug("Player created with the UUID of "+ object.getUUID().toString());
return object.getUUID();
}

}