public ActuatorEntity addCameraActuator(Camera camera, short height, float damping, float minDistanceX, float minDistanceY, String followTagEntity) { CameraActuator component = (CameraActuator) recoverComponent(ActuatorComponentsLookup.CameraActuator); if (component == null) { component = new CameraActuator(camera, height, damping, minDistanceX, minDistanceY, followTagEntity); } else { component.actuator = (indexOwner) -> { Set<GameEntity> followEntities = Indexed .getTagEntities(followTagEntity); for (GameEntity followEntity : followEntities) { RigidBody rc = followEntity.getRigidBody(); Transform transform = rc.body.getTransform(); Vector3 position = camera.position; position.x += (transform.getPosition().x + minDistanceX - position.x) * damping; position.y += (transform.getPosition().y + minDistanceY - position.y) * height; } }; } addComponent(ActuatorComponentsLookup.CameraActuator, component); return this; }
public ActuatorEntity replaceCameraActuator(Camera camera, short height, float damping, float minDistanceX, float minDistanceY, String followTagEntity) { CameraActuator component = (CameraActuator) recoverComponent(ActuatorComponentsLookup.CameraActuator); if (component == null) { component = new CameraActuator(camera, height, damping, minDistanceX, minDistanceY, followTagEntity); } else { component.actuator = (indexOwner) -> { Set<GameEntity> followEntities = Indexed .getTagEntities(followTagEntity); for (GameEntity followEntity : followEntities) { RigidBody rc = followEntity.getRigidBody(); Transform transform = rc.body.getTransform(); Vector3 position = camera.position; position.x += (transform.getPosition().x + minDistanceX - position.x) * damping; position.y += (transform.getPosition().y + minDistanceY - position.y) * height; } }; } replaceComponent(ActuatorComponentsLookup.CameraActuator, component); return this; }
public ActuatorEntity addParticleEffectActuator(ParticleEffect effect, boolean autoStart, float locaPosX, float locaPosY) { ParticleEffectActuator component = (ParticleEffectActuator) recoverComponent(ActuatorComponentsLookup.ParticleEffectActuator); if (component == null) { component = new ParticleEffectActuator(effect, autoStart, locaPosX, locaPosY); } else { component.particleEffect = effect; component.actuator = (indexOwner) -> { GameEntity owner = Indexed.getInteractiveEntity(indexOwner); RigidBody rc = owner.getRigidBody(); Transform transform = rc.body.getTransform(); effect.setPosition(transform.getPosition().x + locaPosX, transform.getPosition().y + locaPosY); effect.update(Gdx.graphics.getDeltaTime()); if (autoStart && effect.isComplete()) effect.start(); }; } addComponent(ActuatorComponentsLookup.ParticleEffectActuator, component); return this; }
public ActuatorEntity replaceParticleEffectActuator(ParticleEffect effect, boolean autoStart, float locaPosX, float locaPosY) { ParticleEffectActuator component = (ParticleEffectActuator) recoverComponent(ActuatorComponentsLookup.ParticleEffectActuator); if (component == null) { component = new ParticleEffectActuator(effect, autoStart, locaPosX, locaPosY); } else { component.particleEffect = effect; component.actuator = (indexOwner) -> { GameEntity owner = Indexed.getInteractiveEntity(indexOwner); RigidBody rc = owner.getRigidBody(); Transform transform = rc.body.getTransform(); effect.setPosition(transform.getPosition().x + locaPosX, transform.getPosition().y + locaPosY); effect.update(Gdx.graphics.getDeltaTime()); if (autoStart && effect.isComplete()) effect.start(); }; } replaceComponent(ActuatorComponentsLookup.ParticleEffectActuator, component); return this; }
@Override public void processActuator(CameraActuator actuator, float deltaTime) { Entity target = null; if(actuator.followEntity != null) target = actuator.followEntity; else if(actuator.followTagEntity != null) actuator.followEntity = target = engine.getEntities(actuator.followTagEntity).first(); if(target != null) { RigidBodiesComponents rc = target.getComponent(RigidBodiesComponents.class); Transform transform = rc.rigidBodies.first().getTransform(); Vector3 position = actuator.camera.position; position.x += (transform.getPosition().x - position.x) * actuator.damping; position.y += (transform.getPosition().y - position.y) * actuator.damping; } }
public static float ComputeSubmergedArea(CircleShape shape, Vector2 normal, float offset, Transform xf, Vector2 c) { Vector2 p = xf.mul(shape.getPosition()); float l = -(normal.dot(p) - offset); float r = shape.getRadius(); if (l < -r) { // Completely dry return 0; } if (l > r) { // Completely wet c.set(p); return MathUtils.PI * r * r; } float r2 = r * r; float l2 = l * l; float area = r2 * ((float) Math.asin(l / r) + MathUtils.PI / 2) + l * (float) Math.sqrt(r2 - l2); float com = -2.0f / 3.0f * (float) Math.pow(r2 - l2, 1.5f) / area; c.x = p.x + normal.x * com; c.y = p.y + normal.y * com; return area; }
public CameraActuator(Camera camera, short height, float damping, float minDistanceX, float minDistanceY, String followTagEntity) { this.actuator = (indexOwner) -> { Set<GameEntity> followEntities = Indexed.getTagEntities(followTagEntity); for (GameEntity followEntity : followEntities) { RigidBody rc = followEntity.getRigidBody(); Transform transform = rc.body.getTransform(); Vector3 position = camera.position; position.x += (transform.getPosition().x + minDistanceX - position.x) * damping; position.y += (transform.getPosition().y + minDistanceY - position.y) * height; } }; }
public ParticleEffectActuator(ParticleEffect effect, boolean autoStart, float locaPosX, float locaPosY) { this.particleEffect = effect; this.actuator = (indexOwner)-> { GameEntity owner = Indexed.getInteractiveEntity(indexOwner); RigidBody rc = owner.getRigidBody(); Transform transform = rc.body.getTransform(); effect.setPosition(transform.getPosition().x + locaPosX, transform.getPosition().y + locaPosY); effect.update(Gdx.graphics.getDeltaTime()); if(autoStart && effect.isComplete()) effect.start(); }; }
@Override protected void createContext() { // Create Player Entity entityBuilder.initialize(); IdentityComponent identityPlayer = entityBuilder.getComponent(IdentityComponent.class); identityPlayer.tag = "Player"; transform = new Transform(new Vector2(), 0); /* TextureView view = new TextureView(); view.attachedTransform = transform; view.width = 4; view.height = 3; entityBuilder.getComponent(ViewsComponent.class).views.add(view); */ sensor =builders.getBrickBuilder(MouseSensorBuilder.class) .setMouseEvent(MouseSensor.MouseEvent.MOVEMENT) .setName("sensorPlayer") .getBrick(); ConditionalController controllerGround =builders.getBrickBuilder(ConditionalControllerBuilder.class) .setOp(ConditionalController.Op.OP_AND) .getBrick(); ActuatorTest actuatorTest = new ActuatorTest(); player = entityBuilder .addController(controllerGround, "Default") .connectToSensor(sensor) .connectToActuator(actuatorTest) .getEntity(); sensorSystem = engine.getSystem(MouseSensorSystem.class); }
/** * Draws body lines and AABB. * @param camera Specify which game camera you want. */ @Override public void drawDebug(FlxCamera camera) { if(B2FlxDebug.drawBodies || B2FlxDebug.drawAABBs) { if (body.isActive() && B2FlxDebug.drawInactiveBodies) return; Transform transform = body.getTransform(); if(B2FlxDebug.drawBodies) { for(int i = 0; i < _fixtures.size; i++) { _fixtureDebug = _fixtures.get(i); if(body.isActive() == false) drawShape(_fixtureDebug, transform, B2FlxDebug.SHAPE_NOT_ACTIVE); else if(body.getType() == BodyType.StaticBody) drawShape(_fixtureDebug, transform, B2FlxDebug.SHAPE_STATIC); else if(body.getType() == BodyType.KinematicBody) drawShape(_fixtureDebug, transform, B2FlxDebug.SHAPE_KINEMATIC); else if(body.isAwake() == false) drawShape(_fixtureDebug, transform, B2FlxDebug.SHAPE_NOT_AWAKE); else drawShape(_fixtureDebug, transform, B2FlxDebug.SHAPE_AWAKE); if(B2FlxDebug.drawAABBs) { if(_fixtureDebug.getType() != Type.Edge && _fixtureDebug.getType() != Type.Chain) drawAABB(_fixtureDebug, transform); } } } } }
public View setAttachedTransform(Transform attachedTransform) { this.attachedTransform = attachedTransform; return this; }
public static float ComputeSubmergedArea(ChainShape shape, Vector2 normal, float offset, Transform xf, Vector2 c) { return 0; }
public static float ComputeSubmergedArea(EdgeShape shape, Vector2 normal, float offset, Transform xf, Vector2 c) { return 0; }
public Vector2 getBodyPixelCoord (Body b) { Transform xf = b.getTransform(); return coordWorldToPixels(xf.getPosition()); }