summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/Scene/Player.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/tylermurphy/Minecraft/Scene/Player.java')
-rwxr-xr-xsrc/main/java/net/tylermurphy/Minecraft/Scene/Player.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/Minecraft/Scene/Player.java b/src/main/java/net/tylermurphy/Minecraft/Scene/Player.java
new file mode 100755
index 0000000..69e741a
--- /dev/null
+++ b/src/main/java/net/tylermurphy/Minecraft/Scene/Player.java
@@ -0,0 +1,100 @@
+package net.tylermurphy.Minecraft.Scene;
+
+import java.io.Serializable;
+
+import net.tylermurphy.Minecraft.Scene.Objects.Transform;
+import org.lwjgl.glfw.GLFW;
+
+import net.tylermurphy.Minecraft.Input.Input;
+import net.tylermurphy.Minecraft.Scene.Objects.Entity;
+import net.tylermurphy.Minecraft.Render.Data.Display;
+
+public class Player extends Entity implements Serializable {
+
+ private static final long serialVersionUID = 5135364541978251987L;
+
+ public int health = 20;
+
+ public boolean isPaused;
+
+ public Player(Transform transform) {
+ super(transform);
+ }
+
+ public void move() {
+ if(!isPaused)
+ checkInputs();
+ else {
+ this.currentForwardSpeed = 0;
+ this.currentSideSpeed = 0;
+ }
+ float distance = (float) (currentForwardSpeed * Display.getFrameTimeSeconds() * (isFlying == true ? 2 : 1) * ((isSwimming || isBobbing) && !isFlying ? .25 : 1) );
+ float dx = (float) (distance * Math.sin(Math.toRadians(getTransform().getRotation().y)));
+ float dz = (float) (distance * Math.cos(Math.toRadians(getTransform().getRotation().y)));
+ float distance2 = (float) (currentSideSpeed * Display.getFrameTimeSeconds() * (isFlying == true ? 2 : 1) * ((isSwimming || isBobbing) && !isFlying ? .25 : 1) );
+ dx += (float) (distance2 * Math.sin(Math.toRadians(90-getTransform().getRotation().y)));
+ dz += (float) (distance2 * Math.cos(Math.toRadians(90+getTransform().getRotation().y)));
+ if(isInAir && !(isFlying || isSwimming)) upwardsSpeed += GRAVITY * Display.getFrameTimeSeconds();
+ upwardsSpeed *= (isSwimming && !isFlying ? .5 : 1);
+ upwardsSpeed *= (isBobbing) ? -1 : 1;
+ float dy = (float) (upwardsSpeed * Display.getFrameTimeSeconds());
+
+ if(willCollide(dx, 0, 0))
+ getTransform().increasePosition(dx, 0, 0);
+
+ if(willCollide(0, dy, 0)) {
+ getTransform().increasePosition(0, dy, 0);
+ }
+
+ if(willCollide(0, 0, dz))
+ getTransform().increasePosition(0, 0, dz);
+
+ if(getTransform().getPosition().y < 0) {
+ getTransform().increasePosition(0, 256, 0);
+ }
+ }
+
+ private void checkInputs() {
+ int keys_pressed = 0;
+
+ if(Input.isKeyDown(GLFW.GLFW_KEY_W)) {
+ this.currentForwardSpeed = -RUN_SPEED; keys_pressed++;
+ }else if(Input.isKeyDown(GLFW.GLFW_KEY_S)) {
+ this.currentForwardSpeed = RUN_SPEED; keys_pressed++;
+ }else {
+ this.currentForwardSpeed = 0;
+ }
+
+ if(Input.isKeyDown(GLFW.GLFW_KEY_A)) {
+ this.currentSideSpeed = -RUN_SPEED; keys_pressed++;
+ }else if(Input.isKeyDown(GLFW.GLFW_KEY_D)) {
+ this.currentSideSpeed = RUN_SPEED; keys_pressed++;
+ }else {
+ this.currentSideSpeed = 0;
+ }
+
+ if(keys_pressed == 2) {
+ this.currentForwardSpeed /=1.25;
+ this.currentSideSpeed /=1.25;
+ }
+
+ if(Input.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL)) {
+ this.currentForwardSpeed *= 1.5;
+ this.currentSideSpeed *= 1.5;
+ }
+
+ if(Input.isKeyDown(GLFW.GLFW_KEY_SPACE)) {
+ if(!isInAir && !(isFlying || isSwimming)) {
+ this.upwardsSpeed = JUMP_POWER;
+ isInAir = true;
+ }else if(isFlying || isSwimming) {
+ this.upwardsSpeed = JUMP_POWER;
+ }
+ } else if(Input.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT) && isFlying || isSwimming && !isFlying) {
+ this.upwardsSpeed = -JUMP_POWER;
+ } else if(isFlying) {
+ this.upwardsSpeed = 0;
+ }
+ }
+
+}