public static void createTrigger( PooledEngine engine, PhysixSystem physixSystem, float x, float y, float width, float height, Consumer<Entity> consumer) { Entity entity = engine.createEntity(); PhysixModifierComponent modifyComponent = engine.createComponent(PhysixModifierComponent.class); entity.add(modifyComponent); TriggerComponent triggerComponent = engine.createComponent(TriggerComponent.class); triggerComponent.consumer = consumer; entity.add(triggerComponent); modifyComponent.schedule( () -> { PhysixBodyComponent bodyComponent = engine.createComponent(PhysixBodyComponent.class); PhysixBodyDef bodyDef = new PhysixBodyDef(BodyDef.BodyType.StaticBody, physixSystem) .position(x + width / 2, y + height / 2); bodyComponent.init(bodyDef, physixSystem, entity); PhysixFixtureDef fixtureDef = new PhysixFixtureDef(physixSystem).sensor(true).shapeBox(width, height); bodyComponent.createFixture(fixtureDef); entity.add(bodyComponent); }); engine.addEntity(entity); }
/////////////////// SERVER @Override public void onReceivedNewPacket(Packet pack, Entity ent) { PhysixBodyComponent phxc = ComponentMappers.physixBody.get(ent); try { MovementPacket p = (MovementPacket) pack; InventoryComponent inventory = ComponentMappers.inventory.get(ent); MoveComponent move = ComponentMappers.move.get(ent); Vector2 vel = dummyVector.set(p.xPos, p.yPos); if ((inventory.getMetalShards() <= inventory.maxMetalShards) && (inventory.getMetalShards() > 0)) { float invtemp = (float) inventory.getMetalShards() / (float) inventory.maxMetalShards; vel.scl(move.speed - move.speed * (invtemp * 0.75f)); } else { vel.scl(move.speed); } phxc.setLinearVelocity(vel); // phxc.setAngle(p.rotation); phxc.setAngle(p.rotation * MathUtils.degreesToRadians); } catch (ClassCastException e) { } }