示例#1
0
  public static Entity makePlayerControlled(Entity entity) {
    entity.add(GameManager.getGame().engine.createComponent(PlayerOwnedComponent.class));
    entity.add(GameManager.getGame().engine.createComponent(PlayerControllerComponent.class));
    entity.add(GameManager.getGame().engine.createComponent(JoystickControllerComponent.class));

    return entity;
  }
  public void processEntity(Entity entity, float deltaTime) {
    InvincibleComponent invincibleC = Mappers.invicible.get(entity);
    LifeDurationComponent lifeDurationC = Mappers.lifeDuration.get(entity);
    IntervalComponent intervalC = Mappers.interval.get(entity);

    if (intervalC != null) {
      if (!intervalC.tickComplete) {
        intervalC.tickComplete = intervalC.interval.lapse(deltaTime);
      }
    }

    if (invincibleC != null) {
      if (invincibleC.time.lapse(deltaTime)) {
        entity.remove(InvincibleComponent.class);
      }
    }

    if (lifeDurationC != null) {
      if (lifeDurationC.interval.lapse(deltaTime)) {
        GameEntity gameEntity = lifeDurationC.gameEntity;
        gameEntity.kill();
        entity.remove(LifeDurationComponent.class);
      }
    }
  }
 @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;
   }
 }
示例#4
0
 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);
 }
示例#5
0
  public static Entity createMap() {
    Entity map = GameManager.getGame().engine.createEntity();
    MapComponent mapComponent = GameManager.getGame().engine.createComponent(MapComponent.class);
    mapComponent.init(256, 256);
    mapComponent.rectangle.x = -128;
    mapComponent.rectangle.y = -128;
    map.add(mapComponent);
    GameManager.getGame().engine.addEntity(map);

    return map;
  }
示例#6
0
 public static Entity createEntity(PooledEngine engine, String name, float x, float y, Team team) {
   factoryParam.x = x;
   factoryParam.y = y;
   factoryParam.team = team;
   Entity entity = entityFactory.createEntity(name, factoryParam);
   SetupComponent setup = engine.createComponent(SetupComponent.class);
   setup.name = name;
   setup.team = team;
   entity.add(setup);
   engine.addEntity(entity);
   return entity;
 }
示例#7
0
  // Gibt Gegner Position zur�ueck, die am naechersten ist, falls keiner im
  // Sichtfeld = null
  public Entity searchTarget() {
    ComponentMapper<PositionComponent> pm = ComponentMapper.getFor(PositionComponent.class);
    Entity result = null;
    ImmutableArray<Entity> entities = engine.getEntities();
    float smallestDistance = sightRadius * sightRadius;
    float collisionDistance = 30f;

    for (Entity entity : entities) {

      // check if entity is a point of interest
      if (entity.getClass() == PointOfInterestEntity.class) {
        PointOfInterestEntity pie = (PointOfInterestEntity) entity;
        PositionComponent piePosition = pm.get(pie);

        // if the POI is a target and the distance < collision distance => collision
        if (team == Team.GREEN
            && pie.toString() == "target"
            && piePosition.position.dst2(pm.get(this).position)
                <= (collisionDistance * collisionDistance)) {
          // add a new green boid entity
          BoidEntity boidR = new BoidEntity(BoidEntity.Team.GREEN, engine, new EvadeState());
          boidR.add(new PositionComponent());
          pm.get(boidR).position = piePosition.position.cpy();
          boidR.add(new VelocityComponent());
          boidR.add(new RenderComponent());
          boidR.add(new BoidCenterComponent());
          boidR.add(new BoidDistanceComponent());
          boidR.add(new BoidMatchVelocityComponent());
          boidR.add(new RessourceComponent());
          boidR.setPointOfInterest(pie);
          engine.addEntity(boidR);
          // heal the boid that collected the cross
          this.resetRessources();
          // set new target position
          piePosition.position.set(
              MathUtils.random(0, Gdx.graphics.getWidth()),
              MathUtils.random(0, Gdx.graphics.getHeight()));
        }
      }
      if (entity.getComponent(BoidCenterComponent.class) == null) continue;

      BoidEntity currentBoid = (BoidEntity) entity;

      float newDistance = pm.get(this).position.dst2(pm.get(currentBoid).position);
      // Checke falls Gegner in Sicht => pursue Gegner
      if (this.team != currentBoid.team && newDistance < smallestDistance) {
        smallestDistance = newDistance;
        result = currentBoid;
      }
    }

    return result;
  }
  @Override
  protected void processEntity(Entity entity, float deltaTime) {
    BodyComponent bc = entity.getComponent(BodyComponent.class);
    SpriteComponent sc = entity.getComponent(SpriteComponent.class);
    sc.sprite.setPosition(
        bc.body.getPosition().x - sc.sprite.getWidth() / 2,
        bc.body.getPosition().y - sc.sprite.getHeight() / 2);
    sc.sprite.setRotation(bc.body.getAngle() * MathUtils.radiansToDegrees);

    sc.sprite.draw(GDL.i.getBatch());
    // TODO
  }
示例#9
0
  public static Entity createPlayer(float x, float y, float width, float height) {
    Entity entity = createBasicMovingEntity(x, y, width, height);

    makePlayerControlled(entity);
    makeVisual(entity, width, height, "player_ship1.png");

    entity.add(GameManager.getGame().engine.createComponent(ShootingComponent.class));
    entity.add(GameManager.getGame().engine.createComponent(CameraFocusComponent.class));

    GameManager.getGame().engine.addEntity(entity);

    return entity;
  }
示例#10
0
  public static Entity createBullet(float x, float y, float width, float height) {
    Entity bullet = createBasicMovingEntity(x, y, width, height);

    makeVisual(bullet, width, height, null);

    bullet.add(GameManager.getGame().engine.createComponent(DamageOnCollisionComponent.class));
    //
    // bullet.add(GameManager.getGame().engine.createComponent(DestroyOnMapCollisionComponent.class));

    GameManager.getGame().engine.addEntity(bullet);

    return bullet;
  }
  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;
  }
  // TODO: Refactor into multiple functions
  @Override
  public Entity buildEntity() {
    Entity player = new Entity();

    // Define the body
    BodyDef playerBody = new BodyDef();
    playerBody.type = BodyDef.BodyType.DynamicBody;
    playerBody.position.set(0, 0);

    // Create the components
    PhysicsComponent p = new PhysicsComponent(physicsWorld.createBody(playerBody), player);
    RenderComponent r = new RenderComponent();
    KeyboardInputComponent i = new KeyboardInputComponent();
    MoveAction m = new MoveAction();

    // Properties for the components
    Polygon sprite =
        new Polygon(
            new float[] {
              0, 5,
              3, -3,
              0, -2,
              -3, -3
            });

    PolygonShape fixShape = new PolygonShape();
    fixShape.set(sprite.getVertices());

    FixtureDef def = new FixtureDef();
    def.shape = fixShape;
    def.density = 1.2f;
    def.friction = 0f;
    def.restitution = 0.1f;

    // Apply properties
    p.physicsBody.createFixture(def);

    r.renderColor = Color.BLUE;
    r.sprite = sprite;

    m.lin_v = 5f;
    m.rot_v = 2f;

    // Add to player
    player.add(p);
    player.add(r);
    player.add(i);
    player.add(m);

    return player;
  }
  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;
  }
示例#14
0
  public static Entity makeHoming(Entity entity, Entity homingTarget) {
    HomingComponent homing = GameManager.getGame().engine.createComponent(HomingComponent.class);
    homing.target = homingTarget;
    entity.add(homing);

    return entity;
  }
  public void endContact(float delta, Contact contact) {
    for (Entity e : entities) {

      if (contact.getFixtureA() == bm.get(e).body.getFixtureList().first()) {
        for (Entity player : players) {
          if (bm.has(player) && contact.getFixtureB() == sensorm.get(player).sensor) {

            e.remove(CollisionComponent.class);
            player.remove(CollisionComponent.class);
            System.out.println("No longer a touch");
            return;
          }
        }
      }
    }
  }
 @Override
 public void run(
     Entity entity, SafeProperties meta, SafeProperties properties, EntityFactoryParam param) {
   PositionComponent component = engine.createComponent(PositionComponent.class);
   component.x = param.x;
   component.y = param.y;
   entity.add(component);
 }
  @Override
  public void processEntity(com.badlogic.ashley.core.Entity e, float deltaTime) {
    PlainPosition pos = e.getComponent(PlainPosition.class);
    pos.x += 1;
    pos.y -= 1;

    voidness.consume(e);
  }
  @Override
  public void loadFromEntity(Entity entity) {
    super.loadFromEntity(entity);

    SpriterComponent spriterComponent = entity.getComponent(SpriterComponent.class);
    animationName = spriterComponent.animationName;
    animation = spriterComponent.animation;
  }
示例#19
0
  public void init(final Area area) {
    /* Dialogues */
    DialogueComponent dc = DialogueComponent.read("scroll");
    dc.events.put(
        "end",
        new Runnable() {
          @Override
          public void run() {
            Event addAttack =
                new Event() {
                  public void run(Context context) {
                    Attack attack = new Attack(Attack.prototypes.get("nmScroll"));
                    Player.addInventory(attack);
                    Player.addAttack(attack);
                    Player.addAttribute("nmScroll");
                    Player.save((Area) context);
                  }
                };
            Event hideScroll = new SetEntityVisibility("scroll", false);

            area.events.add(addAttack);
            area.events.add(hideScroll);
          }
        });

    /* Entities */
    Entity scroll = new Entity();
    scroll.add(new NameComponent("scroll"));
    scroll.add(new AreaComponent(area));
    scroll.add(new ActorComponent(new Image(Main.getTexture("scroll"))));
    scroll.add(new PositionComponent(5 * Constants.TILE_SIZE, 5 * Constants.TILE_SIZE));
    if (!Player.getAttribute("nmScroll")) scroll.add(new VisibleComponent());
    CollisionComponent cc = new CollisionComponent(0, 0, 16, 8);
    cc.events.add(new StartDialogue(dc));
    scroll.add(cc);

    Entity leave = new Entity();
    EnterZoneComponent ec = new EnterZoneComponent(area);
    ec.bounds.set(0, -Constants.TILE_SIZE, mapSize.x * Constants.TILE_SIZE, Constants.TILE_SIZE);
    ec.events.add(
        new ChangeContext(
            "puzzle1",
            new Vector2(17.5f * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE),
            new Vector2(17.5f * Constants.TILE_SIZE, 32 * Constants.TILE_SIZE)));
    leave.add(ec);

    /* Adding things to Area */
    entities = new Entity[] {scroll, leave};

    new ParticleEffectActor.EnvironmentParticleEffect("scroll", area);
  }
 @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;
         }
       }
     }
   }
 }
示例#21
0
  public static Entity makeVisual(Entity entity, float width, float height, String image) {
    VisualComponent visual = GameManager.getGame().engine.createComponent(VisualComponent.class);
    final Texture texture =
        new Texture(Gdx.files.internal(image != null ? image : images.random()));
    visual.region = new TextureRegion(texture, texture.getWidth(), texture.getHeight());
    visual.width = width;
    visual.height = height;
    entity.add(visual);

    return entity;
  }
  private Entity buildPuffin(World world) {
    Entity e = engine.createEntity();
    e.add(new PuffinComponent());

    AnimationComponent a = new AnimationComponent();
    a.animations.put(
        "DEFAULT", new Animation(1f / 16f, Assets.getPuffinArray(), Animation.PlayMode.LOOP));
    a.animations.put(
        "RUNNING", new Animation(1f / 16f, Assets.getPuffinRunArray(), Animation.PlayMode.LOOP));
    e.add(a);
    StateComponent state = new StateComponent();
    state.set("DEFAULT");
    e.add(state);
    TextureComponent tc = new TextureComponent();
    e.add(tc);

    TransformComponent tfc = new TransformComponent();
    tfc.position.set(10f, 10f, 1f);
    tfc.rotation = 15f;
    tfc.scale.set(0.25f, 0.25f);
    e.add(tfc);

    BodyComponent bc = new BodyComponent();
    BodyDef bodyDef = new BodyDef();
    // We set our body to dynamic, for something like ground which doesn't move we would set it to
    // StaticBody
    bodyDef.type = BodyDef.BodyType.DynamicBody;

    // Set our body's starting position in the world
    bodyDef.position.set(10f, 23f);

    // Create our body in the world using our body definition
    bc.body = world.createBody(bodyDef);
    bc.body.applyAngularImpulse(50f, true);

    // Create a circle shape and set its radius to 6
    CircleShape circle = new CircleShape();
    circle.setRadius(2f);

    // Create a fixture definition to apply our shape to
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = circle;
    fixtureDef.density = 20f;
    fixtureDef.friction = 0.4f;
    fixtureDef.restitution = 0.6f; // Make it bounce a little bit

    // Create our fixture and attach it to the body
    bc.body.createFixture(fixtureDef);

    // Remember to dispose of any shapes after you're done with them!
    // BodyDef and FixtureDef don't need disposing, but shapes do.
    circle.dispose();

    e.add(bc);
    return e;
  }
  @Override
  protected void processEntity(Entity entity, float deltaTime) {
    CollisionComponent collisionComponent = ComponentMappers.COLLISION.get(entity);
    TypeComponent typeComponent = ComponentMappers.TYPE.get(entity);

    if (typeComponent.type == GameObjectType.TYPE_PLAYER) {
      if (collisionComponent.isBegin)
        processPlayerBeginCollision(entity, collisionComponent.entity);
      else processPlayerEndCollision(entity, collisionComponent.entity);
    }
    entity.remove(CollisionComponent.class);
  }
 private void processPlayerEndCollision(Entity playerEntity, Entity otherEntity) {
   TypeComponent typeComponent = ComponentMappers.TYPE.get(otherEntity);
   CapsuleControlComponent capsuleControlComponent =
       ComponentMappers.CAPSULE_CONTROL.get(playerEntity);
   StateComponent stateComponent = ComponentMappers.STATE.get(otherEntity);
   if (typeComponent.type == GameObjectType.TYPE_SAFE_CAPSULE
       && capsuleControlComponent != null
       && capsuleControlComponent.isExiting) {
     playerEntity.remove(CapsuleControlComponent.class);
     stateComponent.state = States.STATE_FREE;
     ComponentMappers.PHYSIC.get(playerEntity).body.getFixtureList().get(0).setSensor(false);
   }
 }
示例#25
0
 public void update() {
   gcl = new ArrayList<GhostComponent>();
   if (SelectionManager._instance.singleSelected != null) {
     BuildingComponent bc = sm.singleSelected.getComponent(BuildingComponent.class);
     GhostComponent gc = sm.singleSelected.getComponent(GhostComponent.class);
     if (bc != null && bc.bc.playerControlled) {
       if (bp.getStage() == null) {
         stage.clear();
         stage.addActor(bp);
       }
     } else if (gc != null && gc.bc.playerControlled) {
       gcl.add(gc);
       if (gp.getStage() == null) {
         stage.clear();
         stage.addActor(gp);
       }
     }
   } else if (SelectionManager._instance.selected.size() > 0) {
     for (Entity e : sm.selected) {
       GhostComponent gc = e.getComponent(GhostComponent.class);
       if (gc != null) gcl.add(gc);
     }
     if (gp.getStage() == null) {
       stage.clear();
       stage.addActor(gp);
     }
   } else if (!HW4.stop) {
     if (rs.getStage() == null || !display) stage.clear();
   }
   f.setText("Souls: " + GhostComponent.money);
   if (cw.getStage() == null) stage.addActor(cw);
   if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) {
     display = !display;
   }
   if ((HW4.win || display) && rs.getStage() == null) {
     stage.addActor(rs);
   }
 }
 @Override
 public void run(
     Entity entity, SafeProperties meta, SafeProperties properties, EntityFactoryParam param) {
   if (param.game instanceof GameLocal) {
     EatableComponent component = engine.createComponent(EatableComponent.class);
     component.energy = properties.getFloat("energy", 0);
     component.sound = properties.getString("sound");
     String powerupName = properties.getString("powerup");
     if (powerupName != null) {
       component.powerup = powerupSystem.createPowerup(powerupName);
     }
     entity.add(component);
   }
 }
示例#27
0
  public static Entity createChainLight(
      PooledEngine engine,
      float x,
      float y,
      Color color,
      float distance,
      int rayDirection,
      ArrayList<Point> points) {
    Entity e = engine.createEntity();
    PositionComponent pc = engine.createComponent(PositionComponent.class);
    pc.x = x;
    pc.y = y;
    ChainLightComponent clc = engine.createComponent(ChainLightComponent.class);
    float chain[] = new float[points.size() * 2];
    int i = 0;
    for (Point point : points) {
      chain[i++] = (x + point.x) / GameConstants.BOX2D_SCALE;
      chain[i++] = (y + point.y) / GameConstants.BOX2D_SCALE;
    }
    final RayHandler rayHandler = engine.getSystem(LightRenderSystem.class).getRayHandler();
    clc.chainLight =
        new ChainLight(
            rayHandler,
            GameConstants.LIGHT_RAYS,
            color,
            distance / GameConstants.BOX2D_SCALE,
            rayDirection,
            chain);
    clc.chainLight.setStaticLight(false);
    e.add(pc);
    e.add(clc);

    engine.addEntity(e);

    return e;
  }
  private Entity buildFloorEntity(World world) {

    Entity e = engine.createEntity();
    Vector2 screenMeters = RenderingSystem.getScreenSizeInMeters();
    Gdx.app.log("Splash Screen", "Screen Meters:" + screenMeters.x + " x " + screenMeters.y);
    Vector2 screenPixels = RenderingSystem.getScreenSizeInPixesl();
    Gdx.app.log("Splash Screen", "Screen Pixels:" + screenPixels.x + " x " + screenPixels.y);
    // Create our body definition
    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.type = BodyDef.BodyType.StaticBody;

    // Set its world position
    groundBodyDef.position.set(new Vector2(6f, 1f));
    groundBodyDef.angle = 45f;

    BodyComponent bc = new BodyComponent();
    // Create a body from the defintion and add it to the world
    bc.body = world.createBody(groundBodyDef);

    // Create a polygon shape
    PolygonShape groundBox = new PolygonShape();
    // Set the polygon shape as a box which is twice the size of our view port and 20 high
    // (setAsBox takes half-width and half-height as arguments)

    groundBox.setAsBox(5f, 1f);

    // Create a fixture from our polygon shape and add it to our ground body
    bc.body.createFixture(groundBox, 0.0f);

    // Clean up after ourselves
    groundBox.dispose();

    e.add(bc);

    return e;
  }
示例#29
0
  public static Entity createBasicMovingEntity(float x, float y, float width, float height) {
    Entity entity = GameManager.getGame().engine.createEntity();
    PositionComponent position =
        GameManager.getGame().engine.createComponent(PositionComponent.class);
    position.x = x;
    position.y = y;
    entity.add(position);
    CollisionComponent collision =
        GameManager.getGame().engine.createComponent(CollisionComponent.class);
    collision.init(width, height);
    entity.add(collision);
    entity.add(GameManager.getGame().engine.createComponent(AccelerationComponent.class));
    entity.add(GameManager.getGame().engine.createComponent(DragComponent.class));
    entity.add(GameManager.getGame().engine.createComponent(VelocityComponent.class));
    entity.add(GameManager.getGame().engine.createComponent(AngleComponent.class));
    entity.add(GameManager.getGame().engine.createComponent(PropelComponent.class));
    entity.add(
        GameManager.getGame().engine.createComponent(StopMovementOnCollisionComponent.class));

    return entity;
  }
 @Override
 protected void translateObservableDataToView(Entity item) {
   physicsComponent = item.getComponent(PhysicsBodyComponent.class);
   viewComponent.setBodyType(physicsComponent.bodyType);
   viewComponent.getMassField().setText(physicsComponent.mass + "");
   viewComponent.getCenterOfMassXField().setText(physicsComponent.centerOfMass.x + "");
   viewComponent.getCenterOfMassYField().setText(physicsComponent.centerOfMass.y + "");
   viewComponent.getRotationalIntertiaField().setText(physicsComponent.rotationalInertia + "");
   viewComponent.getDumpingField().setText(physicsComponent.damping + "");
   viewComponent.getGravityScaleField().setText(physicsComponent.gravityScale + "");
   viewComponent.getDensityField().setText(physicsComponent.density + "");
   viewComponent.getFrictionField().setText(physicsComponent.friction + "");
   viewComponent.getRestitutionField().setText(physicsComponent.restitution + "");
   viewComponent.getAllowSleepBox().setChecked(physicsComponent.allowSleep);
   viewComponent.getAwakeBox().setChecked(physicsComponent.awake);
   viewComponent.getBulletBox().setChecked(physicsComponent.bullet);
 }