Skip to content

Commit

Permalink
move the multi input detection out to player because he knows the keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ablackbu committed Mar 29, 2017
1 parent 2e5f4f5 commit 02c32b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
28 changes: 4 additions & 24 deletions src/main/java/com/bamboo/tloll/graphics/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import com.bamboo.tloll.constants.Constants;
import com.bamboo.tloll.debug.Logger;
import com.bamboo.tloll.input.KeyboardHandler;
import com.bamboo.tloll.physics.PhysicsEngine;
import com.bamboo.tloll.physics.Vector3;

import static com.bamboo.tloll.util.Utilities.asInt;
import static org.lwjgl.glfw.GLFW.*;

/**
* Class to represent all heroes, enemies, pets, etc.
*/
Expand Down Expand Up @@ -199,8 +195,7 @@ public void setDebug(boolean debug) {
this.debug = debug;
}

public void moveUpStart(Vector3 v3) {
int numberOfSInputs = getNumberOfSimultaneousInputs();
public void moveUpStart(Vector3 v3, int numberOfSInputs) {

//TODO: abstract away the speed calculation to be generic ?
//TODO: also load max speeds on a per player basis
Expand All @@ -225,9 +220,7 @@ public void moveUpStop(Vector3 v3) {
}
}

public void moveDownStart(Vector3 v3) {
int numberOfSInputs = getNumberOfSimultaneousInputs();

public void moveDownStart(Vector3 v3, int numberOfSInputs) {
setUnitVector(getUnitVector().add(v3));
if (getUnitVector().getYComponent() < (Constants.MAX_PLAYER_SPEED_DOWN * (1.0F / numberOfSInputs))) {
getUnitVector().setYComponent(Constants.MAX_PLAYER_SPEED_DOWN * (1.0F / numberOfSInputs));
Expand All @@ -248,9 +241,7 @@ public void moveDownStop(Vector3 v3) {
}
}

public void moveLeftStart(Vector3 v3) {
int numberOfSInputs = getNumberOfSimultaneousInputs();

public void moveLeftStart(Vector3 v3, int numberOfSInputs) {
setUnitVector(getUnitVector().add(v3));
if (getUnitVector().getXComponent() < (Constants.MAX_PLAYER_SPEED_LEFT * (1.0F / numberOfSInputs))) {
getUnitVector().setXComponent(Constants.MAX_PLAYER_SPEED_LEFT * (1.0F / numberOfSInputs));
Expand All @@ -271,9 +262,7 @@ public void moveLeftStop(Vector3 v3) {
}
}

public void moveRightStart(Vector3 v3) {
int numberOfSInputs = getNumberOfSimultaneousInputs();

public void moveRightStart(Vector3 v3, int numberOfSInputs) {
setUnitVector(getUnitVector().add(v3));
if (getUnitVector().getXComponent() > (Constants.MAX_PLAYER_SPEED_RIGHT * (1.0F / numberOfSInputs))) {
getUnitVector().setXComponent(Constants.MAX_PLAYER_SPEED_RIGHT * (1.0F / numberOfSInputs));
Expand All @@ -294,15 +283,6 @@ public void moveRightStop(Vector3 v3) {
}
}

//TODO: when the movement is refactored out perhaps we can have the players "input" choices be on a list.
//TODO: that would help facilitate this to be more configurable in the future.
private int getNumberOfSimultaneousInputs() {
return asInt(KeyboardHandler.isKeyDown(GLFW_KEY_W)) + asInt(KeyboardHandler.isKeyDown(GLFW_KEY_S)) +
asInt(KeyboardHandler.isKeyDown(GLFW_KEY_A)) + asInt(KeyboardHandler.isKeyDown(GLFW_KEY_D));

//TODO: move me out
}

public void draw() {
if(debug) {
highlightUnit();
Expand Down
19 changes: 4 additions & 15 deletions src/main/java/com/bamboo/tloll/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class Player {
// TODO(map) : The player stands still on diagonal against a wall. Should slide instead.


boolean debug = false;
Unit unit;
Controls controls;

Expand All @@ -31,12 +30,6 @@ public Player(Unit unit, Controls controls) {
this.controls = controls;
}

public Player(Unit unit, Controls controls, boolean debug ) {
this.unit = unit;
this.controls = controls;
this.debug = debug;
}

public Unit getUnit() {
return unit;
}
Expand All @@ -53,10 +46,6 @@ public void setControls(Controls controls) {
this.controls = controls;
}

public boolean isDebug() {
return debug;
}

public void processMovement() {
//Since we have the controls and the player we can go ahead and trigger movement here.
processUp();
Expand All @@ -69,31 +58,31 @@ public void processMovement() {

private void processUp() {
if (KeyboardHandler.isKeyDown(controls.getUp())) {
unit.moveUpStart(new Vector3(0.0f, 1.0f, 0.0f));
unit.moveUpStart(new Vector3(0.0f, 1.0f, 0.0f), getNumberOfSimultaneousInputs());
} else {
unit.moveUpStop(new Vector3(0.0f, -1.0f, 0.0f));
}
}

private void processDown() {
if (KeyboardHandler.isKeyDown(controls.getDown())) {
unit.moveDownStart(new Vector3(0.0f, -1.0f, 0.0f));
unit.moveDownStart(new Vector3(0.0f, -1.0f, 0.0f), getNumberOfSimultaneousInputs());
} else {
unit.moveDownStop(new Vector3(0.0f, 1.0f, 0.0f));
}
}

private void processLeft() {
if (KeyboardHandler.isKeyDown(controls.getLeft())) {
unit.moveLeftStart(new Vector3(-1.0f, 0.0f, 0.0f));
unit.moveLeftStart(new Vector3(-1.0f, 0.0f, 0.0f), getNumberOfSimultaneousInputs());
} else {
unit.moveLeftStop(new Vector3(1.0f, 0.0f, 0.0f));
}
}

private void processRight() {
if (KeyboardHandler.isKeyDown(controls.getRight())) {
unit.moveRightStart(new Vector3(1.0f, 0.0f, 0.0f));
unit.moveRightStart(new Vector3(1.0f, 0.0f, 0.0f), getNumberOfSimultaneousInputs());
} else {
unit.moveRightStop(new Vector3(-1.0f, 0.0f, 0.0f));
}
Expand Down

0 comments on commit 02c32b5

Please sign in to comment.