List of usage examples for com.badlogic.gdx.physics.box2d Body getJointList
public Array<JointEdge> getJointList()
From source file:com.arkanoid.game.model.GameField.java
License:Apache License
public void removeBody(Body body) { step(1);//from ww w .j a v a 2 s . co m if (!world.isLocked()) { if (body != null) { body.setUserData(null); //to prevent some obscure c assertion that happened randomly once in a blue moon final Array<JointEdge> list = body.getJointList(); for (JointEdge edge : list) { world.destroyJoint(edge.joint); } // actual remove this.world.destroyBody(body); } } }
From source file:com.laex.cg2d.render.impl.ScreenManagerImpl.java
License:Open Source License
@Override public void destroyJointForEntity(String id) { Body b = getEntityById(id); Array<JointEdge> jointList = b.getJointList(); for (JointEdge je : jointList) { world.destroyJoint(je.joint);//w w w. j a v a2 s . c o m } }
From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouse.java
License:Open Source License
/** Get the highest free(no joints) card. */ public Body getHighestCard() { float top = cardHouseDef.groundY; Body highestBody = null;/* w w w.j a va 2 s. co m*/ float hh = cardHouseDef.cardHeight * 0.5f; float hw = cardHouseDef.cardWidth * 0.5f; for (Thing thing : world.boxWorld.things) { Body body = thing.getBody(); boolean isCard = body.isActive() && body.getType() != BodyDef.BodyType.StaticBody; if (!isCard) continue; boolean isFreeCard = body.getJointList().size == 0; if (!isFreeCard) continue; float y = body.getPosition().y; y += Math.max(Math.abs(Math.cos(body.getAngle()) * hh), hw); if (y > top) { top = y; highestBody = body; } } return highestBody; }
From source file:se.danielj.slashatthegame.Game.java
License:GNU General Public License
@Override public void create() { SpriteManager.init();/*from w w w .j a va2 s .co m*/ FontManager.init(); SoundEffectsManager.init(); MusicManager.init(); Gdx.input.setCatchBackKey(true); if (world != null) { disposeSystems(world); } world = new World(); world.setManager(new GroupManager()); box2dWorld = new com.badlogic.gdx.physics.box2d.World(new Vector2(0, -3), true); stage = new Stage(960, 540, false); if (tweenManager == null) { tweenManager = new TweenManager(); } inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(stage); inputMultiplexer.addProcessor(this); Gdx.input.setInputProcessor(inputMultiplexer); final LabelStyle labelStyle = new LabelStyle(); labelStyle.font = FontManager.getNormalFont(); labelStyle.fontColor = new Color(0, 0, 0, 1); if (level == 0) { final Song song = new Song(MusicManager.getSong(MusicManager.THEME)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 2f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("logo")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("logo")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); level = 1; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); return false; } }); button.setBounds(0, 0, stage.getWidth(), stage.getHeight()); stage.addActor(button); logic = new Logic() { @Override public void render() { timer += Gdx.graphics.getDeltaTime(); tweenManager.update(Gdx.graphics.getDeltaTime()); stage.draw(); stage.act(world.getDelta()); } }; } else if (level == 1) { Progress.init(); world.setSystem(new SpriteRenderSystem()); world.setSystem(new EffectSystem()); world.setSystem(new TableSystem()); world.setSystem(new PhysicsSystem(box2dWorld)); world.initialize(); EntityCreator.createRoomT(world).addToWorld(); EntityCreator.createTableT(world).addToWorld(); EntityCreator.createTommieT(world).addToWorld(); final Entity glow = EntityCreator.createGlow(world, 132, 6); glow.addToWorld(); glow.disable(); timer = 0; health = 3; progressSpeed = -2; progressing = false; won = false; final Song song = new Song(MusicManager.getSong(MusicManager.TOMMIE)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("button")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("button_pressed")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); progressing = true; progressSpeed = -progressSpeed; if (health == 3 && Math.abs(progressSpeed) == 2.0) { glow.enable(); } return false; } }); button.setBounds(10, 10, 170, 170); stage.addActor(button); style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("tommie_button_green")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("tommie_button_red")); final Button speedButton = new Button(style); speedButton.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (glow.isActive()) { glow.disable(); } if (Math.abs(progressSpeed) == 10.0) { progressSpeed /= 5; } else { progressSpeed *= 5; } return false; } }); speedButton.setBounds(805, 40, 70, 70); stage.addActor(speedButton); logic = new Logic() { @Override public void render() { world.setDelta(Gdx.graphics.getDeltaTime()); world.process(); tweenManager.update(world.getDelta()); stage.draw(); stage.act(world.getDelta()); if (progressing) { Progress.setProgress(Progress.getProgress() + progressSpeed * world.getDelta()); if (progressSpeed > 0 && Progress.getProgress() > 4) { button.setTouchable(Touchable.enabled); button.setChecked(false); progressing = false; } else if (progressSpeed < 0 && Progress.getProgress() < 1) { button.setTouchable(Touchable.enabled); button.setChecked(false); progressing = false; } if (!progressing && Math.abs(progressSpeed) == 10.0) { --health; if (health <= 0 && progressSpeed > 0) { Progress.setProgress(Progress.getProgress() + 1); blowUp(); button.setTouchable(Touchable.disabled); button.setChecked(true); won = true; Label label = new Label("Tommie has been defeated!", labelStyle); stage.addActor(label); movingLabel(label); SoundEffectsManager.explode(); } } } if (won) { timer += world.getDelta(); if (timer > 5) { level = 2; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); // disposeSystems(world); } } } }; Label label = new Label("Meet the evil Tommie", labelStyle); stage.addActor(label); movingLabel(label); } else if (level == 2) { world.setSystem(new PeopleSystem()); world.setSystem(new SpriteRenderSystem()); world.setSystem(new EffectSystem()); world.setSystem(new LightSystem()); world.setSystem(new PhysicsSystem(box2dWorld)); world.initialize(); EntityCreator.createScene(world).addToWorld(); EntityCreator.createJezper(world).addToWorld(); EntityCreator.createPeople1(world).addToWorld(); EntityCreator.createPeople2(world).addToWorld(); EntityCreator.createPeople3(world).addToWorld(); EntityCreator.createLight1(world).addToWorld(); EntityCreator.createLight2(world).addToWorld(); EntityCreator.createLight3(world).addToWorld(); EntityCreator.createWorld(box2dWorld); EntityCreator.createBall(world, box2dWorld, 15, 60).addToWorld(); EntityCreator.createBall(world, box2dWorld, 50, 75).addToWorld(); EntityCreator.createBall(world, box2dWorld, 100, 80).addToWorld(); EntityCreator.createBall(world, box2dWorld, 150, 75).addToWorld(); timer = 0; won = false; health = 0; Progress.setProgress(0); final Song song = new Song(MusicManager.getSong(MusicManager.JEZPER)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("button")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("button_pressed")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); EntityCreator.createFire(world, 90, 40).addToWorld(); EntityCreator.createFire(world, 60, 40).addToWorld(); won = true; timer = 0; SoundEffectsManager.explode(); Label label = new Label("Jezper has been defeated!", labelStyle); stage.addActor(label); movingLabel(label); Iterator<Body> bodies = box2dWorld.getBodies(); while (bodies.hasNext()) { Body body = bodies.next(); if (body.getUserData() instanceof Entity) { List<JointEdge> joints = body.getJointList(); for (int i = 0; i < joints.size(); ++i) { box2dWorld.destroyJoint(joints.get(0).joint); } } } box2dWorld.setContactListener(new ContactListener() { @Override public void beginContact(Contact contact) { if (health < 10) { Vector2 p = contact.getFixtureA().getBody().getPosition(); Body a = contact.getFixtureA().getBody(); Body b = contact.getFixtureB().getBody(); Body body = null; if (a.getUserData() instanceof Entity) { body = a; } if (b.getUserData() instanceof Entity) { // Entity B collided with wall if (body == null) { p = b.getPosition(); EntityCreator.createFire(world, p.x * 10, p.y * 10).addToWorld(); // A collided with B } else { EntityCreator .createFire(world, (a.getPosition().x + b.getPosition().x) * 10 / 2, (a.getPosition().y + b.getPosition().y) * 10 / 2) .addToWorld(); } } else { // A collided with wall p = a.getPosition(); EntityCreator.createFire(world, p.x * 10, p.y * 10).addToWorld(); } SoundEffectsManager.explode(); ++health; } } @Override public void endContact(Contact contact) { } @Override public void preSolve(Contact contact, Manifold oldManifold) { } @Override public void postSolve(Contact contact, ContactImpulse impulse) { } }); return false; } }); button.setBounds(10, 10, 170, 170); button.setTouchable(Touchable.disabled); button.setChecked(true); stage.addActor(button); Label label = new Label("Meet the evil Jezper", labelStyle); stage.addActor(label); movingLabel(label); logic = new Logic() { @Override public void render() { world.setDelta(Gdx.graphics.getDeltaTime()); world.process(); tweenManager.update(world.getDelta()); stage.draw(); stage.act(world.getDelta()); timer += world.getDelta(); if (won) { if (timer > 8) { level = 3; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); // disposeSystems(world); } } else { // wait 3 seconds until enabling the button Progress.setProgress(Progress.getProgress() + world.getDelta()); if (timer > 3 && button.getTouchable() == Touchable.disabled) { button.setTouchable(Touchable.enabled); button.setChecked(false); } } } }; } else if (level == 3) { final LabelStyle creditsLabelStyle = new LabelStyle(); creditsLabelStyle.font = FontManager.getCreditsFont(); creditsLabelStyle.fontColor = new Color(0, 0, 0, 1); final Label label = new Label( "Congratulations! You have defeated the Slashat crew!\nThe people of earth have been saved and can once again\nlive in peace and harmony\n\n\n\nCredits\n\nMade by, programming & graphics:\n Daniel \"MaTachi\" Jonsson, http://danielj.se\n\nJava libraries:\n LibGDX, Artemis & Tween Engine\nSoftware used:\n Eclipse, GIMP & Aseprite on Ubuntu\nFonts:\n Rase GPL & EptKazoo\nMusic:\n Theme Music by Alexandr Zhelanov\n Dissonant Waltz by Yubatake\n Below The Shift by Clearside\nSound effect:\n Explode by Michel Baradari\n\n\nThanks Slashat for all years of podcast!\n\n\nDisclaimer: This game is just something silly and shouldn't\nbe taken seriously. I have no connection with Slashat\nother than being a fan and a longtime listener. :)\nIf I had had more time I would have made levels for\nMagnus and Johan too.", creditsLabelStyle); stage.addActor(label); Song song = new Song(MusicManager.getSong(MusicManager.THEME)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 2f).target(1.0f).ease(Quart.INOUT)) .start(tweenManager); logic = new Logic() { float timer = 0; @Override public void render() { timer += Gdx.graphics.getDeltaTime(); label.setPosition(20, 40 * timer - 1540); tweenManager.update(Gdx.graphics.getDeltaTime()); stage.draw(); stage.act(world.getDelta()); } }; } }