Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class move
- {
- float posX;
- float posY;
- float touchedOnScreenX;
- float touchedOnScreenY;
- float centerOfScreenX;
- float centerOfScreenY;
- float posXSetter;
- float posYSetter;
- float Speed = 150;
- float mapBoundsWidth;
- float mapBoundsHeight;
- boolean upperBounds;
- boolean lowerBounds;
- boolean rightBounds;
- boolean leftBounds;
- boolean tileCollition;
- public move() {
- }
- public void renderMove(float delta) {
- if(Gdx.input.isTouched()) {
- screenAndTouchInfo();
- checkBoundsBoolean();
- checkForCollision();
- }
- }
- //slows game down
- private void checkForCollision()
- {
- if (upperBounds == false)
- {
- if (lowerBounds == false)
- {
- if (rightBounds == false)
- {
- if (leftBounds == false)
- {
- if (tileCollition == false)
- {
- movement();
- }
- else
- {
- collitionSide();
- }
- }
- else
- {
- posX++;
- }
- }
- else
- {
- posX--;
- }
- }
- else
- {
- posY++;
- }
- }
- else
- {
- posY --;
- }
- }
- private void movement()
- {
- posYSetter = posY;
- posXSetter = posX;
- if (touchedOnScreenX < centerOfScreenX)
- {
- posX -= Gdx.graphics.getDeltaTime() * Speed;
- }
- else
- {
- posX += Gdx.graphics.getDeltaTime() * Speed;
- }
- if (touchedOnScreenY < centerOfScreenY)
- {
- posY -= Gdx.graphics.getDeltaTime() * Speed;
- }
- else
- {
- posY += Gdx.graphics.getDeltaTime() * Speed;
- }
- if (touchedOnScreenY < centerOfScreenY + 64 && touchedOnScreenY > centerOfScreenY - 64)
- {
- posY = posYSetter;
- }
- if (touchedOnScreenX < centerOfScreenX + 64 && touchedOnScreenX > centerOfScreenX - 64)
- {
- posX = posXSetter;
- }
- }
- //buggy and slows game down. Can push you into tile if input is the opposite of the side
- public void collitionSide() {
- if (tileCollition == true){
- if (touchedOnScreenX < centerOfScreenX)
- {
- posX = posX +10;
- }
- else
- {
- posX = posX - 10;
- }
- if (touchedOnScreenY < centerOfScreenY)
- {
- posY = posY +10;
- }
- else
- {
- posY = posY -10;
- }
- }
- }
- private void screenAndTouchInfo()
- {
- touchedOnScreenX = Gdx.input.getX();
- touchedOnScreenY = (Gdx.graphics.getHeight() - Gdx.input.getY());
- centerOfScreenX = Gdx.graphics.getWidth() / 2;
- centerOfScreenY = Gdx.graphics.getHeight() / 2;
- }
- //slows game down
- private void checkBoundsBoolean()
- {
- if (posX > mapBoundsWidth)
- {
- rightBounds = true;
- }
- else {
- rightBounds = false;
- }
- if (posY > mapBoundsHeight)
- {
- upperBounds = true;
- }
- else {
- upperBounds = false;
- }
- if (posX < mapBoundsWidth - mapBoundsWidth)
- {
- leftBounds = true;
- }
- else {
- leftBounds = false;
- }
- if (posY < mapBoundsHeight - mapBoundsHeight)
- {
- lowerBounds = true;
- }
- else {
- lowerBounds = false;
- }
- }
- public void setTileCollision(boolean tileCollision) {
- this.tileCollition = tileCollision;
- }
- public float getPosX() {
- return posX;
- }
- public float getPosY() {
- return posY;
- }
- public float getTouchedOnScreenX() {
- return touchedOnScreenX;
- }
- public float getTouchedOnScreenY() {
- return touchedOnScreenY;
- }
- public float getCenterOfScreenX() {
- return centerOfScreenX;
- }
- public float getCenterOfScreenY() {
- return centerOfScreenY;
- }
- public void setMapboundsWidth(float width) {
- this.mapBoundsWidth = width;
- }
- public void setMapboundsHeight(float height) {
- this.mapBoundsHeight = height;
- }
- }
Add Comment
Please, Sign In to add comment