Пример #1
0
 public void addedToEngine(Engine engine) {
   movedEntities =
       engine.getEntitiesFor(
           Family.getFamilyFor(
               BoundsComponent.class, PositionComponent.class, MovementComponent.class));
   entities = engine.getEntitiesFor(Family.getFamilyFor(BoundsComponent.class));
 }
 public TimeLapseSystem() {
   super(
       Family.one(IntervalComponent.class, InvincibleComponent.class, LifeDurationComponent.class)
           .exclude(KillComponent.class)
           .exclude(RemovedComponent.class)
           .get());
 }
Пример #3
0
  public AnimationSystem() {
    super(Family.all(TextureComponent.class, AnimationComponent.class, StateComponent.class).get());

    tm = ComponentMapper.getFor(TextureComponent.class);
    am = ComponentMapper.getFor(AnimationComponent.class);
    sm = ComponentMapper.getFor(StateComponent.class);
  }
Пример #4
0
  public PhysicsSystem(World world, OrthographicCamera camera) {
    super(Family.all(BodyComponent.class, TransformComponent.class).get());

    debugRenderer = new Box2DDebugRenderer();
    this.world = world;
    this.camera = camera;
    this.bodiesQueue = new Array<Entity>();
  }
Пример #5
0
 public CrosshairSystem() {
   super(
       Family.all(
               AttachedComponent.class,
               CrosshairComponent.class,
               PositionComponent.class,
               RenderableComponent.class,
               SpriteComponent.class)
           .get());
 }
Пример #6
0
  @SuppressWarnings("unchecked")
  public HudSystem() {
    super(Family.all(PlayerComponent.class, ShapeComponent.class).get());

    this.batch = new SpriteBatch();
    this.font = new BitmapFont();
    this.font.setColor(Color.RED);

    this.playerM = ComponentMapper.getFor(PlayerComponent.class);
    this.shapeM = ComponentMapper.getFor(ShapeComponent.class);
  }
Пример #7
0
 public OutOfBoundsSystem(
     FitViewport viewport,
     LightsManager lightsManager,
     PooledEngine engine,
     BodyGenerator bodyGenerator) {
   super(Family.all(RenderableComponent.class, OutOfBoundsComponent.class).get());
   this.viewport = viewport;
   this.lightsManager = lightsManager;
   this.engine = engine;
   this.bodyGenerator = bodyGenerator;
 }
Пример #8
0
  public ControllerSystem() {
    super(
        Family.all(
                TransformComponent.class,
                BodyComponent.class,
                PlayerComponent.class,
                ControllerComponent.class)
            .get());

    tm = ComponentMapper.getFor(TransformComponent.class);
    bm = ComponentMapper.getFor(BodyComponent.class);
    cm = ComponentMapper.getFor(ControllerComponent.class);
  }
Пример #9
0
  private void updateRunning(float deltaTime) {
    // Implement Pause button check here
    /* See ashley-jumper -> GameScreen -> line 155 */

    ApplicationType appType = Gdx.app.getType();

    float accelX = 0.0f;
    boolean fireMissile = false;
    if (appType == ApplicationType.Android || appType == ApplicationType.iOS) {
      accelX = Gdx.input.getAccelerometerX();
      if (Gdx.input.isTouched()) {
        fireMissile = true;
      }
    } else {
      if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) {
        accelX = 5f;
      }
      if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) {
        accelX = -5f;
      }
      if (Gdx.input.isKeyPressed(Keys.F)) {
        fireMissile = true;
      }
    }

    engine.getSystem(DefenderSystem.class).setAccelX(accelX);
    engine.getSystem(DefenderSystem.class).setIsFiring(fireMissile);

    // Check if all aliens are gone
    ImmutableArray<Entity> aliens =
        engine.getEntitiesFor(
            Family.all(
                    AlienComponent.class,
                    BoundsComponent.class,
                    MovementComponent.class,
                    TransformComponent.class,
                    StateComponent.class)
                .get());
    if (aliens.size() == 0) {
      world.state = World.WORLD_STATE_GAME_OVER;
    }
    if (world.state == World.WORLD_STATE_GAME_OVER) {
      state = GAME_OVER;
      pauseSystems();
    }
  }
Пример #10
0
 public ExplosionSystem(int priority) {
   super(Family.all(ExplosionComponent.class).get(), priority);
 }
Пример #11
0
public final class Entities {
  public static final ComponentMapper<Destroyable> destroyable =
      ComponentMapper.getFor(Destroyable.class);
  public static final ComponentMapper<Health> health = ComponentMapper.getFor(Health.class);
  public static final ComponentMapper<MiniMapObject> miniMap =
      ComponentMapper.getFor(MiniMapObject.class);
  public static final ComponentMapper<Position> position = ComponentMapper.getFor(Position.class);
  public static final ComponentMapper<Rotation> rotation = ComponentMapper.getFor(Rotation.class);
  public static final ComponentMapper<Sprite> sprite = ComponentMapper.getFor(Sprite.class);
  public static final ComponentMapper<Velocity> velocity = ComponentMapper.getFor(Velocity.class);

  public static final Family players =
      Family.all(Position.class, Velocity.class, Health.class, Rotation.class, Sprite.class).get();

  private Entities() {}

  // The following are factory methods to create new entities with component presets

  public static Entity createPlayer(Level level, TextureRegion[][] spriteSheet) {
    final Entity player = level.createEntity();
    player.add(
        level
            .createComponent(Position.class)
            .set(level.getNextSpawnLocation())); // TODO: This can return null!
    player.add(level.createComponent(Velocity.class).reset());
    player.add(
        level
            .createComponent(Health.class)
            .reset(20)); // TODO change default based on selected character
    player.add(level.createComponent(Sprite.class).set(spriteSheet[0][0]));

    return player;
  }

  public static Entity createWithPosition(Level level, int x, int y) {
    final Entity tile = level.createEntity();
    tile.add(level.createComponent(Position.class).set(x, y));

    return tile;
  }

  private static Entity createBaseTile(Level level, int x, int y, Color color, boolean isWall) {
    x *= Tiles.SIZE;
    y *= Tiles.SIZE;

    final Entity tile = createWithPosition(level, x, y);
    tile.add(level.createComponent(MiniMapObject.class).setColor(color));

    if (isWall) {
      tile.add(new BoundingBox().set(x, y, Tiles.SIZE));
    }

    return tile;
  }

  public static Entity createTile(
      Level level, int x, int y, Color color, TextureRegion texture, boolean isWall) {
    final Entity tile = createBaseTile(level, x, y, color, isWall);
    tile.add(level.createComponent(Sprite.class).set(texture));
    return tile;
  }

  public static Entity createTile(
      Level level, int x, int y, Color color, TextureRegion[] textures, boolean isWall) {
    return createTile(
        level, x, y, color, textures[level.generator.random.nextInt(textures.length)], isWall);
  }
}
Пример #12
0
  public BoundsSystem() {
    super(Family.all(BoundsComponent.class, TransformComponent.class).get());

    bm = ComponentMapper.getFor(BoundsComponent.class);
    tm = ComponentMapper.getFor(TransformComponent.class);
  }
Пример #13
0
 public CollisionSystem() {
   super(Family.all(CollisionComponent.class).get());
 }
 public void addedToEngine(Engine engine) {
   player = engine.getEntitiesFor(Family.all(PlayerSteerableComponent.class).get());
   entities = engine.getEntitiesFor(Family.all(TalkComponent.class).get());
 }
Пример #15
0
  public ApocalypseSystem() {
    super(Family.all(SettlementFlag.class, Health.class).get());

    healthComponentMapper = ComponentMapper.getFor(Health.class);
  }
/** Created by ruimadeira on 02/01/16. */
public class PlatformMonsterSys extends IteratingSystem implements ContactListener {

  private static Family family =
      Family.all(PlatformMonsterComp.class, MonsterMovementComp.class, BodyComp.class).get();
  private PhysicsSys phisicsSys;

  public PlatformMonsterSys(PhysicsSys physicsSys) {
    super(family);
    this.phisicsSys = physicsSys;
  }

  public void addedToEngine(Engine e) {
    super.addedToEngine(e);
    phisicsSys.addListener(this);
  }

  public void removedFromEngine(Engine e) {
    super.removedFromEngine(e);
    phisicsSys.removeListener(this);
  }

  @Override
  protected void processEntity(Entity entity, float deltaTime) {
    PlatformMonsterComp pm = entity.getComponent(PlatformMonsterComp.class);
    MonsterMovementComp mm = entity.getComponent(MonsterMovementComp.class);
    BodyComp b = entity.getComponent(BodyComp.class);
    Vector2 pos = b.body.getPosition();
    pos.x *= b.invWorldScale;
    pos.y *= b.invWorldScale;
    switch (mm.moveType) {
      case LEFT:
        if (pos.x <= pm.minX) {
          standMonster(pm, mm);
        }
        break;
      case STAND:
        if (pm.standCountdown > 0) {
          pm.standCountdown -= deltaTime;
        }
        if (pm.standCountdown <= 0) {
          pm.standCountdown = 0;
          if (pos.x <= pm.minX) {
            mm.moveType = MonsterMovementComp.MoveType.RIGHT;
          } else {
            mm.moveType = MonsterMovementComp.MoveType.LEFT;
          }
        }
        break;
      case RIGHT:
        if (pos.x >= pm.maxX) {
          standMonster(pm, mm);
        }
        break;
    }
  }

  private void standMonster(PlatformMonsterComp pm, MonsterMovementComp mm) {
    pm.standCountdown = pm.standInterval;
    mm.moveType = MonsterMovementComp.MoveType.STAND;
  }

  @Override
  public void beginContact(Contact contact) {
    Entity monster = PhysicsSys.getEntityFromBodyData(UserData.Type.MONSTER, contact);
    if (monster != null) {
      MonsterComp m = monster.getComponent(MonsterComp.class);
      if (m.type == MonsterComp.Type.PLATFORM_MONSTER) {
        Entity wall = PhysicsSys.getEntityFromBodyData(UserData.Type.WALL, contact);
        if (wall != null) {
          Vector2 wallPos = getPos(wall);
          Vector2 monsterPos = getPos(monster);
          PlatformMonsterComp pm = monster.getComponent(PlatformMonsterComp.class);
          if (wallPos.x < monsterPos.x) {
            pm.minX = wallPos.x + 5f;
          } else {
            pm.maxX = wallPos.x - 5f;
          }
        }
      }
    }
  }

  @Override
  public void endContact(Contact contact) {}

  @Override
  public void preSolve(Contact contact, Manifold oldManifold) {}

  @Override
  public void postSolve(Contact contact, ContactImpulse impulse) {}

  private Vector2 getPos(Entity e) {
    BodyComp b = e.getComponent(BodyComp.class);
    Vector2 pos = b.body.getPosition();
    pos.scl(b.invWorldScale);
    return pos;
  }
}
Пример #17
0
 public OrbitSystem() {
   super(
       Family.all(TransformComponent.class, MovementComponent.class, OrbitComponent.class).get());
 }
 @Override
 public void addedToEngine(Engine engine) {
   entities =
       engine.getEntitiesFor(Family.all(BodyComponent.class).exclude(PlayerComponent.class).get());
   players = engine.getEntitiesFor(Family.all(PlayerComponent.class).get());
 }
Пример #19
0
 public LifeSystem(Engine engine) {
   super(Family.all(LifeComponent.class).get());
   this.engine = engine;
 }
 @SuppressWarnings("unchecked")
 public PlainPositionSystem() {
   super(Family.getFor(PlainPosition.class));
 }
Пример #21
0
 public SpineSystem() {
   super(Family.all(SpineDataComponent.class).get());
 }
  public PhysicsSystem(World world) {
    super(Family.all(BodyComponent.class, TransformComponent.class).get());

    this.world = world;
    this.bodiesQueue = new Array<>();
  }
 public SpriteRenderSystem() {
   super(Family.all(BodyComponent.class, SpriteComponent.class).get());
 }