@Override public boolean touchDown (int x, int y, int pointer, int newParam) { // translate the mouse coordinates to world coordinates testPoint.set(x, y, 0); camera.unproject(testPoint); // ask the world which bodies are within the given // bounding box around the mouse pointer hitBody = null; world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f, testPoint.x + 0.1f, testPoint.y + 0.1f); // if we hit something we create a new mouse joint // and attach it to the hit body. if (hitBody != null) { MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint.x, testPoint.y); def.maxForce = 1000.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); } else { for (Body box : boxes) world.destroyBody(box); boxes.clear(); createBoxes(); } return false; }
@Override public boolean touchDown (int x, int y, int pointer, int button) { // translate the mouse coordinates to world coordinates camera.unproject(testPoint.set(x, y, 0)); // ask the world which bodies are within the given // bounding box around the mouse pointer hitBody = null; world.QueryAABB(callback, testPoint.x - 0.0001f, testPoint.y - 0.0001f, testPoint.x + 0.0001f, testPoint.y + 0.0001f); if (hitBody == groundBody) hitBody = null; // ignore kinematic bodies, they don't work with the mouse joint if (hitBody != null && hitBody.getType() == BodyType.KinematicBody) return false; // if we hit something we create a new mouse joint // and attach it to the hit body. if (hitBody != null) { MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint.x, testPoint.y); def.maxForce = 1000.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); } return false; }
float mass = body.getMass();
@Override public boolean touchDown (int x, int y, int pointer, int button) { // Screen coordinates to world coordinates viewport.getCamera().unproject(point.set(x, y, 0)); if (button == Input.Buttons.LEFT) { float force = 100f * player1.getBody().getMass(); Vector2 target = new Vector2(point.x, point.y); Vector2 direction = target.sub(player1.getBody().getPosition()); player1.getBody().applyForceToCenter(direction.scl(force), true); } return false; }
@Override public boolean touchDown (int x, int y, int pointer, int button) { // Mouse coordinates to world coordinates viewport.getCamera().unproject(point.set(x, y, 0)); if(button == Input.Buttons.RIGHT) { hitBody = null; // Check if a interactive body has been right-clicked world.QueryAABB(callback, point.x - 0.0001f, point.y - 0.0001f, point.x + 0.0001f, point.y + 0.0001f); if (hitBody == groundBody) hitBody = null; // if we hit an interactive body we create a new mouse joint // and attach it to the hit body. if (hitBody != null) { MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(point.x, point.y); def.maxForce = 1000.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); } } return false; }
@Override public boolean touchDown (int x, int y, int pointer, int newParam) { if(world == null)return false; // translate the mouse coordinates to world coordinates testPoint.set(Engine.screenToWorld(x, y).scl(1/Box2dObject.RADIO)); // ask the world which bodies are within the given // bounding box around the mouse pointer hitBody = null; world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f, testPoint.x + 0.1f, testPoint.y + 0.1f); // if we hit something we create a new mouse joint // and attach it to the hit body. if (hitBody != null) { MouseJointDef def = new MouseJointDef(); def.bodyA = fixBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint.x, testPoint.y); def.maxForce = 1000.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); return true; } return false; }
@Override public boolean touchUp(int x, int y, int arg2, int arg3) { Vector3 coordinates = new Vector3(x,y,0); camera.unproject(coordinates); if(lastTouchPolygon != null){ Vector2 impulse = new Vector2(coordinates.x, coordinates.y). sub(lastTouchCoordinates).scl(lastTouchPolygon.getMass()); Log.log("LiveMode.touchUp", "applying impulse: " + impulse + " on body: " + lastTouchPolygon.getPosition()); lastTouchPolygon.applyLinearImpulse(impulse, lastTouchPolygonLocalCoordinates.add(lastTouchPolygon.getPosition()),true); lastTouchCoordinates = null; lastTouchPolygon = null; lastTouchPolygonLocalCoordinates = null; } return false; }
def.collideConnected = true; def.target.set(point.x, point.y); def.maxForce = 1000.0f * hitBody.getMass();
state.setCurrentState("walking_left"); if (body.getLinearVelocity().x > -enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(-enemy.getSpeed() * body.getMass(), 0), body.getWorldCenter(), true); state.setCurrentState("walking_right"); if (body.getLinearVelocity().x < enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(enemy.getSpeed() * body.getMass(), 0), body.getWorldCenter(), true); state.setCurrentState("walking_up"); if (body.getLinearVelocity().y < enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(0, enemy.getSpeed() * body.getMass()), body.getWorldCenter(), true); state.setCurrentState("walking_down"); if (body.getLinearVelocity().y > -enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(0, -enemy.getSpeed() * body.getMass()), body.getWorldCenter(), true);
state.setCurrentState("walking_left"); if (body.getLinearVelocity().x > -enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(-enemy.getSpeed() * body.getMass(), 0), body.getWorldCenter(), true); state.setCurrentState("walking_right"); if (body.getLinearVelocity().x < enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(enemy.getSpeed() * body.getMass(), 0), body.getWorldCenter(), true); state.setCurrentState("walking_up"); if (body.getLinearVelocity().y < enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(0, enemy.getSpeed() * body.getMass()), body.getWorldCenter(), true); state.setCurrentState("walking_down"); if (body.getLinearVelocity().y > -enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(0, -enemy.getSpeed() * body.getMass()), body.getWorldCenter(), true);
if (player.invincible || !hitBombVertical(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x, body.getPosition().y + 0.5f))) { if (Math.abs(linearVelocity.y) < maxSpeed) { body.applyLinearImpulse(new Vector2(0, player.acceleration * body.getMass()), body.getWorldCenter(), true); if (player.invincible || !hitBombVertical(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x, body.getPosition().y - 0.5f))) { if (Math.abs(linearVelocity.y) < maxSpeed) { body.applyLinearImpulse(new Vector2(0, -player.acceleration * body.getMass()), body.getWorldCenter(), true); if (player.invincible || !hitBombHorizontal(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x - 0.5f, body.getPosition().y))) { if (Math.abs(linearVelocity.x) < maxSpeed) { body.applyLinearImpulse(new Vector2(-player.acceleration * body.getMass(), 0), body.getWorldCenter(), true); if (player.invincible || !hitBombHorizontal(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x + 0.5f, body.getPosition().y))) { if (Math.abs(linearVelocity.x) < maxSpeed) { body.applyLinearImpulse(new Vector2(player.acceleration * body.getMass(), 0), body.getWorldCenter(), true);