コード例 #1
0
 @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;
   }
 }
コード例 #2
0
  @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
  }
コード例 #3
0
  @Override
  public void loadFromEntity(Entity entity) {
    super.loadFromEntity(entity);

    SpriterComponent spriterComponent = entity.getComponent(SpriterComponent.class);
    animationName = spriterComponent.animationName;
    animation = spriterComponent.animation;
  }
コード例 #4
0
  @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);
  }
コード例 #5
0
 @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;
         }
       }
     }
   }
 }
コード例 #6
0
ファイル: BoidEntity.java プロジェクト: wanische/ki_tools
  // 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;
  }
コード例 #7
0
 @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);
 }
コード例 #8
0
ファイル: GameGUI.java プロジェクト: KnightPickles/CS328
 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);
   }
 }
コード例 #9
0
  @Override
  public void update(float deltaTime) {

    for (Entity entity : movedEntities.values()) {
      bounds = entity.getComponent(BoundsComponent.class);
      position = entity.getComponent(PositionComponent.class);
      movement = entity.getComponent(MovementComponent.class);

      for (Entity otherEntity : entities.values()) {
        oBounds = otherEntity.getComponent(BoundsComponent.class);
        if (!otherEntity.equals(entity) && !oBounds.isPassable()) {
          // Y COLLISION
          if (movement.getVelocity().y < 0
              && oBounds.getBounds().getY() + oBounds.getBounds().getHeight()
                  < position.getPosition().y + bounds.getBoundsOffset().y + 1) {
            if (bounds.getBounds().overlaps(oBounds.getBounds())) {
              position.getPosition().y =
                  oBounds.getBounds().getY()
                      + oBounds.getBounds().getHeight()
                      - bounds.getBoundsOffset().y;
              movement.getVelocity().y = 0;
              bounds.getBounds().setY(position.getPosition().y + bounds.getBoundsOffset().y);
              signal.dispatch(new CollisionEvent(new Entity[] {entity, otherEntity}));
            }
          } else if (movement.getVelocity().y > 0
              && oBounds.getBounds().getY()
                  > bounds.getBounds().getHeight()
                      + position.getPosition().y
                      + bounds.getBoundsOffset().y
                      - 1) {
            if (bounds.getBounds().overlaps(oBounds.getBounds())) {
              position.getPosition().y =
                  oBounds.getBounds().getY()
                      - bounds.getBounds().getHeight()
                      - bounds.getBoundsOffset().y;
              movement.getVelocity().y = 0;
              bounds.getBounds().setY(position.getPosition().y + bounds.getBoundsOffset().y);
              signal.dispatch(new CollisionEvent(new Entity[] {entity, otherEntity}));
            }
          }
          // X COLLISION
          if (movement.getVelocity().x < 0
              && oBounds.getBounds().getX() + oBounds.getBounds().getWidth()
                  < position.getPosition().x + bounds.getBoundsOffset().x + 1) {
            if (bounds.getBounds().overlaps(oBounds.getBounds())) {
              position.getPosition().x =
                  oBounds.getBounds().getX()
                      + oBounds.getBounds().getWidth()
                      - bounds.getBoundsOffset().x;
              movement.getVelocity().x = 0;
              bounds.getBounds().setX(position.getPosition().x + bounds.getBoundsOffset().x);
              signal.dispatch(new CollisionEvent(new Entity[] {entity, otherEntity}));
            }
          } else if (movement.getVelocity().x > 0
              && oBounds.getBounds().getX()
                  > position.getPosition().x
                      + bounds.getBounds().getWidth()
                      + bounds.getBoundsOffset().x
                      - 1) {
            if (bounds.getBounds().overlaps(oBounds.getBounds())) {
              position.getPosition().x =
                  oBounds.getBounds().getX()
                      - bounds.getBounds().getWidth()
                      - bounds.getBoundsOffset().x;
              movement.getVelocity().x = 0;
              bounds.getBounds().setX(position.getPosition().x + bounds.getBoundsOffset().x);
              signal.dispatch(new CollisionEvent(new Entity[] {entity, otherEntity}));
            }
          }
        }
      }
    }
  }
コード例 #10
0
 public HealthBarComponent(Entity parent, float x, float y) {
   this.parent = parent;
   this.parentHealth = parent.getComponent(HealthComponent.class);
   this.drawOffset = new Vector2(x, y);
 }
コード例 #11
0
 public HealthBarComponent(Entity parent, Vector2 drawOffset) {
   this.parent = parent;
   this.parentHealth = parent.getComponent(HealthComponent.class);
   this.drawOffset = drawOffset;
 }
コード例 #12
0
 public HealthBarComponent(Entity parent) {
   this.parent = parent;
   this.parentHealth = parent.getComponent(HealthComponent.class);
   this.drawOffset = new Vector2(0f, 300f);
 }
コード例 #13
0
 private Vector2 getPos(Entity e) {
   BodyComp b = e.getComponent(BodyComp.class);
   Vector2 pos = b.body.getPosition();
   pos.scl(b.invWorldScale);
   return pos;
 }