Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class InputManager extends InputAdapter{
- private Vector3 touchPoint;
- private OrthographicCamera cam;
- private Body playerBody;
- private Array<Body> clouds;
- private Rope rope;
- public InputManager(OrthographicCamera cam, Body playerBody, Array clouds, Rope rope){
- this.cam = cam;
- this.playerBody = playerBody;
- this.clouds = clouds;
- this.rope = rope;
- touchPoint = new Vector3();
- }
- @Override
- public boolean keyDown(int keycode) {
- return true;
- }
- @Override
- public boolean keyUp(int keycode) {
- return true;
- }
- @Override
- public boolean keyTyped(char character) {
- return true;
- }
- @Override
- public boolean touchDown(int screenX, int screenY, int pointer, int button) {
- cam.unproject(touchPoint.set(screenX, screenY, 0));
- for (int i = 0; i < clouds.size; i++) {
- if(overlapsOnX(playerBody, clouds.get(i))){
- rope.createRope(playerBody, clouds.get(i + 5));
- }
- }
- return true;
- }
- @Override
- public boolean touchUp(int screenX, int screenY, int pointer, int button) {
- rope.destroyRope();
- playerBody.applyLinearImpulse(5 / PPM, 10 / PPM, playerBody.getPosition().x, playerBody.getPosition().y, true);
- return true;
- }
- @Override
- public boolean touchDragged(int screenX, int screenY, int pointer) {
- return true;
- }
- @Override
- public boolean mouseMoved(int screenX, int screenY) {
- return true;
- }
- @Override
- public boolean scrolled(int amount) {
- return true;
- }
- private boolean overlapsOnX(Body player, Body cloud){ //check if the player is currently in the same X position than a cloud
- if(player.getPosition().x >= cloud.getPosition().x && player.getPosition().x <= cloud.getPosition().x){
- return true;
- }
- return false;
- }
- private boolean overlaps(Body cloud, Vector3 touch){ //check if touch overlaps with a cloud body
- if(touch.x >= cloud.getPosition().x - (20 / PPM) && touch.x <= cloud.getPosition().x + (20 / PPM)){
- if(touch.y >= cloud.getPosition().y - (4 / PPM) && touch.y <= cloud.getPosition().y + (4 / PPM)){
- return true;
- }
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment