private void renderBox (Body body, float halfWidth, float halfHeight) { // get the bodies center and angle in world coordinates Vector2 pos = body.getWorldCenter(); float angle = body.getAngle(); // set the translation and rotation matrix transform.setToTranslation(pos.x, pos.y, 0); transform.rotate(0, 0, 1, (float)Math.toDegrees(angle)); // render the box renderer.begin(ShapeType.Line); renderer.setTransformMatrix(transform); renderer.setColor(1, 1, 1, 1); renderer.rect(-halfWidth, -halfHeight, halfWidth * 2, halfHeight * 2); renderer.end(); }
public void applyLinearImpulse(Vector2 impulse) { body.applyLinearImpulse(impulse, body.getWorldCenter(), true); }
public void jump(){ if ( currentState != State.JUMPING ) { b2body.applyLinearImpulse(new Vector2(0, 4f), b2body.getWorldCenter(), true); currentState = State.JUMPING; } }
public void jump() { if (!(jumping || dodging || hit)) { body.applyLinearImpulse(getUserData().getJumpingLinearImpulse(), body.getWorldCenter(), true); jumping = true; } }
public void handleInput(float dt){ //control our player using immediate impulses if(player.currentState != Mario.State.DEAD) { if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) player.jump(); if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) && player.b2body.getLinearVelocity().x <= 2) player.b2body.applyLinearImpulse(new Vector2(0.1f, 0), player.b2body.getWorldCenter(), true); if (Gdx.input.isKeyPressed(Input.Keys.LEFT) && player.b2body.getLinearVelocity().x >= -2) player.b2body.applyLinearImpulse(new Vector2(-0.1f, 0), player.b2body.getWorldCenter(), true); if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) player.fire(); } }
@Override public CompletionEnum tick(float dt){ PrismaticJoint joint = (PrismaticJoint)executor.getPhysicsJoint(this.joint); if(joint.isMotorEnabled() && towardA && executor.getPhysicsObject(name).getWorldCenter().dst(pointA) < TURN_DISTANCE){ towardA = false; joint.setMaxMotorForce(maxMotorForceB); joint.setMotorSpeed(motorSpeedB); joint.enableMotor(false); executor.getPhysicsObject(name).setType(BodyType.StaticBody); timeChangeDirection = System.currentTimeMillis() + waitDuration; }else if(joint.isMotorEnabled() && !towardA && executor.getPhysicsObject(name).getWorldCenter().dst(pointB) < TURN_DISTANCE){ towardA = true; joint.setMaxMotorForce(maxMotorForceA); joint.setMotorSpeed(motorSpeedA); joint.enableMotor(false); executor.getPhysicsObject(name).setType(BodyType.StaticBody); timeChangeDirection = System.currentTimeMillis() + waitDuration; }else if(!joint.isMotorEnabled() && System.currentTimeMillis() > timeChangeDirection){ joint.enableMotor(true); executor.getPhysicsObject(name).setType(BodyType.DynamicBody); } return CompletionEnum.EXECUTING; }
public void die() { if (!isDead()) { MarioBros.manager.get("audio/music/mario_music.ogg", Music.class).stop(); MarioBros.manager.get("audio/sounds/mariodie.wav", Sound.class).play(); marioIsDead = true; Filter filter = new Filter(); filter.maskBits = MarioBros.NOTHING_BIT; for (Fixture fixture : b2body.getFixtureList()) { fixture.setFilterData(filter); } b2body.applyLinearImpulse(new Vector2(0, 4f), b2body.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);
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);
body.applyLinearImpulse(toVector.scl(enemy.getSpeed()), body.getWorldCenter(), true);