List of usage examples for com.badlogic.gdx.physics.box2d Fixture getUserData
public Object getUserData()
From source file:genuini.world.ContactHandler.java
@Override public void beginContact(Contact contact) { Fixture fa = contact.getFixtureA(); Fixture fb = contact.getFixtureB();/* ww w . j av a 2 s . c o m*/ if (fa == null || fb == null) return; if (fa.getUserData() != null && fa.getUserData().equals("foot")) { numFootContacts++; } if (fb.getUserData() != null && fb.getUserData().equals("foot")) { numFootContacts++; } if ((fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null && fb.getUserData().equals("spring")) || (fa.getUserData() != null && fa.getUserData().equals("spring") && fb.getUserData() != null && fb.getUserData().equals("foot"))) { bounce = true; } if ((fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null && fb.getUserData().equals("button")) || (fa.getUserData() != null && fa.getUserData().equals("button") && fb.getUserData() != null && fb.getUserData().equals("foot"))) { button = true; } if (fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null && fb.getUserData().equals("spike") || fa.getUserData() != null && fa.getUserData().equals("spike") && fb.getUserData() != null && fb.getUserData().equals("foot")) { bounce = true; dangerous = true; playerHurt(); } if (fa.getUserData() != null && fa.getUserData().equals("fireball")) { if (fb.getUserData() != null && fb.getUserData().equals("player")) { dangerous = true; playerHurt(); } } if (fb.getUserData() != null && fb.getUserData().equals("fireball")) { if (fa.getUserData() != null && fa.getUserData().equals("player")) { dangerous = true; playerHurt(); } } if (fa.getUserData() != null && (fa.getUserData().equals("slime") || fa.getUserData().equals("snail"))) { if (fb.getUserData() != null && fb.getUserData().equals("player")) { dangerous = true; fb.getBody().applyLinearImpulse(0, 8f, 0, 0, true); playerHurt(); } } if (fb.getUserData() != null && (fb.getUserData().equals("slime") || fb.getUserData().equals("snail"))) { if (fa.getUserData() != null && fa.getUserData().equals("player")) { dangerous = true; fa.getBody().applyLinearImpulse(0, 8f, 0, 0, true); playerHurt(); } } if ((fa.getUserData() != null && fa.getUserData().equals("victory")) || (fb.getUserData() != null && fb.getUserData().equals("victory"))) { victory = true; } if (fa.getUserData() != null && fa.getUserData().equals("questionBox")) { fa.setUserData("questionBoxDisabled"); } else if (fb.getUserData() != null && fb.getUserData().equals("questionBox")) { fb.setUserData("questionBoxDisabled"); } }
From source file:genuini.world.ContactHandler.java
@Override public void endContact(Contact contact) { Fixture fa = contact.getFixtureA(); Fixture fb = contact.getFixtureB();// ww w . j a v a 2 s . c om if (fa == null || fb == null) return; if (fa.getUserData() != null && fa.getUserData().equals("foot")) { numFootContacts--; } if (fb.getUserData() != null && fb.getUserData().equals("foot")) { numFootContacts--; } if (fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null && fb.getUserData().equals("spring") || fa.getUserData() != null && fa.getUserData().equals("spring") && fb.getUserData() != null && fb.getUserData().equals("foot")) { bounce = false; } if ((fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null && fb.getUserData().equals("button")) || (fa.getUserData() != null && fa.getUserData().equals("button") && fb.getUserData() != null && fb.getUserData().equals("foot"))) { button = false; } if (fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null && fb.getUserData().equals("spike") || fa.getUserData() != null && fa.getUserData().equals("spike") && fb.getUserData() != null && fb.getUserData().equals("foot")) { bounce = false; dangerous = false; } if (fa.getUserData() != null && fa.getUserData().equals("fireball")) { if (fb.getUserData() != null && fb.getUserData().equals("player")) { dangerous = false; } if (fb.getUserData() != null && (fb.getUserData().equals("slime") || fb.getUserData().equals("snail"))) { fb.setUserData("setToDestroy"); } fa.setUserData("toDestroy"); } if (fb.getUserData() != null && fb.getUserData().equals("fireball")) { if (fa.getUserData() != null && fa.getUserData().equals("player")) { dangerous = false; } if (fa.getUserData() != null && (fa.getUserData().equals("slime") || fa.getUserData().equals("snail"))) { fa.setUserData("setToDestroy"); } fb.setUserData("toDestroy"); } if (fa.getUserData() != null && fa.getUserData().equals("slime")) { if (fb.getUserData() != null && fb.getUserData().equals("player")) { dangerous = false; fa.setUserData("setToDestroy"); } } if (fb.getUserData() != null && fb.getUserData().equals("slime")) { if (fa.getUserData() != null && fa.getUserData().equals("player")) { dangerous = false; fb.setUserData("setToDestroy"); } } }
From source file:headmade.arttag.ArtTagContactListener.java
License:Apache License
private void handleBeginContactWithGuardLight(Contact contact, Fixture fixLight, Fixture fixOther) { if (isPlayer(fixOther)) { Gdx.app.log(TAG, "Player entered Guards FOV!"); final Guard g = (Guard) fixLight.getUserData(); g.playerInView.add(fixOther);/*from w ww .j av a 2 s . c om*/ } }
From source file:headmade.arttag.ArtTagContactListener.java
License:Apache License
private void handleEndContactWithGuardLight(Contact contact, Fixture fixLight, Fixture fixOther) { if (isPlayer(fixOther)) { final Guard g = (Guard) fixLight.getUserData(); Gdx.app.log(TAG, "Guard can no longer see player!"); g.playerInView.removeValue(fixOther, true); g.isAlert = false;/*from w w w . ja v a2s . c om*/ } }
From source file:io.piotrjastrzebski.sfg.game.ContactDispatcher.java
License:Open Source License
private boolean checkSensor(Fixture sensor, Fixture other) { final SensorType type = (SensorType) sensor.getUserData(); final Object sensorData = sensor.getBody().getUserData(); final Object otherData = other.getBody().getUserData(); if (type == null) return false; switch (type) { case SCORE:// w ww . ja v a 2s .com if (otherData instanceof Player) { events.queueEvent(EventType.PLAYER_SCORED, sensorData); } return true; default: break; } return false; }
From source file:net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** creates a {@link Fixture} from a {@link MapObject} * @param mapObject the {@link MapObject} to parse * @param body the {@link Body} to create the {@link Fixture Fixtures} on * @return the parsed {@link Fixture} */ public Fixture createFixture(MapObject mapObject, Body body) { MapProperties properties = mapObject.getProperties(); Shape shape = null;/*from www . ja v a 2 s. c om*/ if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); float x = rectangle.x * unitScale, y = rectangle.y * unitScale, width = rectangle.width * unitScale, height = rectangle.height * unitScale; ((PolygonShape) shape).setAsBox(width / 2, height / 2, vec2.set(x - body.getPosition().x + width / 2, y - body.getPosition().y + height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = new Polygon(((PolygonMapObject) mapObject).getPolygon().getTransformedVertices()); polygon.setScale(unitScale, unitScale); polygon.setPosition(-body.getPosition().x, -body.getPosition().y); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = new Polyline( ((PolylineMapObject) mapObject).getPolyline().getTransformedVertices()); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); ((ChainShape) shape).createChain(polyline.getTransformedVertices()); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle mapObjectCircle = ((CircleMapObject) mapObject).getCircle(); Circle circle = new Circle(mapObjectCircle.x, mapObjectCircle.y, mapObjectCircle.radius); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; CircleShape circleShape = (CircleShape) shape; circleShape.setPosition(vec2.set(circle.x, circle.y)); circleShape.setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x + ellipse.width / 2, ellipse.y + ellipse.height / 2, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject, body); } throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s that are not circles are not supported"); } else if (mapObject instanceof TextureMapObject) throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s are not supported"); else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; assignProperties(fixtureDef, heritage); assignProperties(fixtureDef, mapProperties); assignProperties(fixtureDef, layerProperties); assignProperties(fixtureDef, properties); Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(getProperty(layerProperties, aliases.userData, fixture.getUserData())); fixture.setUserData(getProperty(properties, aliases.userData, fixture.getUserData())); shape.dispose(); fixtures.put(findAvailableName(mapObject.getName(), fixtures), fixture); return fixture; }
From source file:net.dermetfan.utils.libgdx.box2d.Box2DUtils.java
License:Apache License
/** creates a deep copy of a {@link Fixture} * @param fixture the {@link Fixture} to copy * @param body the {@link Body} to create a copy of the given {@code fixture} on * @param shape if the {@link Fixture#getShape() shape} of the given {@code fixture} should be deep {@link #copy(Shape) copied} as well * @return the copied {@link Fixture} */ public static Fixture copy(Fixture fixture, Body body, boolean shape) { FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = fixture.getDensity(); Filter filter = fixture.getFilterData(); fixtureDef.filter.categoryBits = filter.categoryBits; fixtureDef.filter.groupIndex = filter.groupIndex; fixtureDef.filter.maskBits = filter.maskBits; fixtureDef.friction = fixture.getFriction(); fixtureDef.isSensor = fixture.isSensor(); fixtureDef.restitution = fixture.getRestitution(); fixtureDef.shape = shape ? copy(fixture.getShape()) : fixture.getShape(); Fixture copy = body.createFixture(fixtureDef); copy.setUserData(copy.getUserData()); return copy;/* w ww . ja v a 2 s .c o m*/ }
From source file:net.dermetfan.utils.libgdx.graphics.Box2DSprite.java
License:Apache License
/** draws all the {@link Box2DSprite Box2DSprites} on the {@link Body} or {@link Fixture} that hold them in their user data in the given {@link World} */ public static void draw(Batch batch, World world, boolean sortByZ) { world.getBodies(tmpBodies);/* w w w.ja v a 2 s .c o m*/ if (!sortByZ) { for (Body body : tmpBodies) { if ((tmpBox2DSprite = userDataAccessor.access(body.getUserData())) != null) tmpBox2DSprite.draw(batch, body); for (Fixture fixture : body.getFixtureList()) if ((tmpBox2DSprite = userDataAccessor.access(fixture.getUserData())) != null) tmpBox2DSprite.draw(batch, fixture); } return; } for (Body body : tmpBodies) { if ((tmpBox2DSprite = userDataAccessor.access(body.getUserData())) != null) tmpZMap.put(tmpBox2DSprite, body); for (Fixture fixture : body.getFixtureList()) if ((tmpBox2DSprite = userDataAccessor.access(fixture.getUserData())) != null) tmpZMap.put(tmpBox2DSprite, fixture); } Array<Box2DSprite> keys = tmpZMap.keys().toArray(); keys.sort(zComparator); Object value; for (Box2DSprite key : keys) { value = tmpZMap.get(key); if (value instanceof Body) key.draw(batch, (Body) value); else key.draw(batch, (Fixture) value); } tmpZMap.clear(); }
From source file:org.csproduction.descendant.B2D.GameContactListener.java
@Override public void beginContact(Contact contact) { Fixture fa = contact.getFixtureA();//from w w w . ja va2s .c om Fixture fb = contact.getFixtureB(); Vector2 normal = contact.getWorldManifold().getNormal(); switch (fa.getFilterData().categoryBits) { case BIT_PLAYER: Player p = ((Player) fa.getBody().getUserData()); switch (fb.getFilterData().categoryBits) { case BIT_GROUND: if (normal.y < 0) { boolean[] groundArray = (boolean[]) fb.getUserData(); if (!groundArray[0]) { p.changeGroundCount(1); groundArray[0] = true; } } break; case BIT_SPELL: case BIT_SPELL2: ((Spell) fb.getBody().getUserData()).land(); p.takeDamage(((Spell) fb.getBody().getUserData()).getDamage()); break; } break; case BIT_PLAYER2: p = ((Player) fa.getBody().getUserData()); switch (fb.getFilterData().categoryBits) { case BIT_GROUND: if (normal.y < 0) { boolean[] groundArray = (boolean[]) fb.getUserData(); if (!groundArray[1]) { p.changeGroundCount(1); groundArray[1] = true; } } break; case BIT_SPELL: case BIT_SPELL2: ((Spell) fb.getBody().getUserData()).land(); p.takeDamage(((Spell) fb.getBody().getUserData()).getDamage()); break; } break; case BIT_GROUND: switch (fb.getFilterData().categoryBits) { case BIT_PLAYER: p = ((Player) fb.getBody().getUserData()); if (normal.y < 0) { boolean[] groundArray = (boolean[]) fa.getUserData(); if (!groundArray[0]) { p.changeGroundCount(1); groundArray[0] = true; } } break; case BIT_PLAYER2: p = ((Player) fb.getBody().getUserData()); if (normal.y < 0) { boolean[] groundArray = (boolean[]) fa.getUserData(); if (!groundArray[1]) { p.changeGroundCount(1); groundArray[1] = true; } } break; case BIT_SPELL: case BIT_SPELL2: ((Spell) fb.getBody().getUserData()).land(); break; } break; case BIT_SPELL: switch (fb.getFilterData().categoryBits) { case BIT_GROUND: ((Spell) fa.getBody().getUserData()).land(); break; case BIT_PLAYER: case BIT_PLAYER2: ((Spell) fa.getBody().getUserData()).land(); ((Player) fb.getBody().getUserData()).takeDamage(((Spell) fa.getBody().getUserData()).getDamage()); break; case BIT_SPELL2: ((Spell) fa.getBody().getUserData()).land(); ((Spell) fb.getBody().getUserData()).land(); break; } break; case BIT_SPELL2: switch (fb.getFilterData().categoryBits) { case BIT_GROUND: ((Spell) fa.getBody().getUserData()).land(); break; case BIT_PLAYER: case BIT_PLAYER2: ((Spell) fa.getBody().getUserData()).land(); ((Player) fb.getBody().getUserData()).takeDamage(((Spell) fa.getBody().getUserData()).getDamage()); break; case BIT_SPELL: ((Spell) fa.getBody().getUserData()).land(); ((Spell) fb.getBody().getUserData()).land(); break; } break; } }
From source file:org.csproduction.descendant.B2D.GameContactListener.java
@Override public void endContact(Contact contact) { Fixture fa = contact.getFixtureA();//from w ww .j a va 2s . co m Fixture fb = contact.getFixtureB(); switch (fa.getFilterData().categoryBits) { case BIT_PLAYER: switch (fb.getFilterData().categoryBits) { case BIT_GROUND: boolean[] groundArray = (boolean[]) fb.getUserData(); if (groundArray[0]) { Player p = ((Player) fa.getBody().getUserData()); p.changeGroundCount(-1); groundArray[0] = false; } break; } break; case BIT_PLAYER2: switch (fb.getFilterData().categoryBits) { case BIT_GROUND: boolean[] groundArray = (boolean[]) fb.getUserData(); if (groundArray[1]) { Player p = ((Player) fa.getBody().getUserData()); p.changeGroundCount(-1); groundArray[1] = false; } break; } break; case BIT_GROUND: switch (fb.getFilterData().categoryBits) { case BIT_PLAYER: boolean[] groundArray = (boolean[]) fa.getUserData(); if (groundArray[0]) { Player p = ((Player) fb.getBody().getUserData()); p.changeGroundCount(-1); groundArray[0] = false; } break; case BIT_PLAYER2: groundArray = (boolean[]) fa.getUserData(); if (groundArray[1]) { Player p = ((Player) fb.getBody().getUserData()); p.changeGroundCount(-1); groundArray[1] = false; } break; } break; } }