Example #1
0
    /**
     * Gets whether or not this sensor senses a Pedestrian.
     *
     * @param tileMap the PedestrianTileBasedMap to use, to get the TileState, and the resulting
     *     list of Pedestrians in that tile
     * @return true if a Pedestrian is detected, false otherwise.
     */
    public MovingEntity relativePointSensesEntity(GameMap map) {

      MovingEntity entitySensed = null;

      // Get the point of the entity that may encounter an obstacle
      Point2D.Float relativePoint = this.entity.getRelativePointFromCenter(rx, ry);

      // Get the tile this point is in
      Tile tileSensed =
          map.getTile(
              (int) (relativePoint.x / GameMap.TILE_SIZE),
              (int) (relativePoint.y / GameMap.TILE_SIZE));

      // Search for an entity in this tile
      if (tileSensed != null) {
        LinkedList<Entity> entities = tileSensed.getEntities();

        for (Entity e : entities) {
          if (Math.hypot(relativePoint.x - e.getX(), relativePoint.y - e.getX()) <= SENSOR_RADIUS) {
            entitySensed = (MovingEntity) e;
            break;
          }
        }
      }

      return entitySensed;
    }
Example #2
0
  @Override
  public void run() {
    while (threadRunFlag) {
      if (queue.isEmpty()) {
        System.out.println("wait add new Data to upload thread!");
        synchronized (this) {
          try {
            wait();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }

      } else {
        Entity entity = (Entity) queue.remove();
        System.out.println("current upload is:" + entity.toString());
        System.out.println("list size i s :" + queue.size());

        try {
          Thread.sleep(300);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
  @Test
  public void recycleComponent() {
    int maxEntities = 10;
    int maxComponents = 10;
    PooledEngine engine = new PooledEngine(maxEntities, maxEntities, maxComponents, maxComponents);

    for (int i = 0; i < maxComponents; ++i) {
      Entity e = engine.createEntity();
      PooledComponentSpy c = engine.createComponent(PooledComponentSpy.class);

      assertEquals(false, c.recycled);

      e.add(c);

      engine.addEntity(e);
    }

    engine.removeAllEntities();

    for (int i = 0; i < maxComponents; ++i) {
      Entity e = engine.createEntity();
      PooledComponentSpy c = engine.createComponent(PooledComponentSpy.class);

      assertEquals(true, c.recycled);

      e.add(c);
    }

    engine.removeAllEntities();
  }
  @Test
  public void groupTitleSearch() throws Exception {
    UUID applicationId = createApplication("testOrganization", "groupTitleSearch");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    String titleName = "groupName" + UUIDUtils.newTimeUUID();

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("title", titleName);
    properties.put("path", "testPath");
    properties.put("name", "testName");

    Entity group = em.create("group", properties);
    assertNotNull(group);

    // EntityRef
    Query query = new Query();
    query.addEqualityFilter("title", titleName);

    Results r = em.searchCollection(em.getApplicationRef(), "groups", query);

    assertTrue(r.size() > 0);

    Entity returned = r.getEntities().get(0);

    assertEquals(group.getUuid(), returned.getUuid());
  }
Example #5
0
 @EventHandler
 public void onDammange(EntityDamageByEntityEvent event) {
   Entity dammage = event.getEntity();
   if (dammage.getType() == EntityType.ENDER_CRYSTAL) {
     event.setCancelled(true);
   }
 }
Example #6
0
        public void use(Entity self, Entity other, Entity activator) {
          if (self.solid == Constants.SOLID_NOT) self.solid = Constants.SOLID_TRIGGER;
          else self.solid = Constants.SOLID_NOT;
          World.SV_LinkEdict(self);

          if (0 == (self.spawnflags & 2)) self.use = null;
        }
 /**
  * Handles explosion block damage caused by TnT, Creepers, or Fireballs.<br>
  * If the arena allows explosion block breaking, each block is handled separately<br>
  * as if a player attempted to destroy it. If the arena doesn't allow explosion block breaking,
  * <br>
  * no blocks are broken.
  */
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onTntExplode(EntityExplodeEvent event) {
   Entity entity = event.getEntity();
   if (entity instanceof TNTPrimed || entity instanceof Creeper || entity instanceof Fireball) {
     Arena arena = ultimateGames.getArenaManager().getLocationArena(entity.getLocation());
     if (arena != null) {
       if (arena.getStatus() == ArenaStatus.RUNNING) {
         if (arena.allowExplosionBlockBreaking()) {
           Set<Block> canBeBroken =
               ultimateGames
                   .getWhitelistManager()
                   .getBlockBreakWhitelist()
                   .blocksWhitelisted(arena.getGame(), new HashSet<Block>(event.blockList()));
           event.blockList().clear();
           event.blockList().addAll(canBeBroken);
           arena.getGame().getGamePlugin().onEntityExplode(arena, event);
         } else if (arena.allowExplosionDamage()) {
           event.blockList().clear();
           arena.getGame().getGamePlugin().onEntityExplode(arena, event);
         } else {
           event.setCancelled(true);
         }
       } else {
         event.setCancelled(true);
       }
     }
   }
 }
Example #8
0
  private void handleSecrecy(
      Entity session,
      Entity child,
      List<ITerm> knowers,
      FunctionSymbol setSymbol,
      String protName,
      ExpressionContext ctx,
      ITerm term) {
    LocationInfo loc = term.getLocation();
    Entity rootEnt = session.findRootEntity();
    FunctionTerm secrecyTerm =
        rootEnt.secrecyTerm(
            session,
            session.getIDSymbol().term(loc, child),
            child,
            knowers,
            term /* = payload*/,
            setSymbol,
            protName,
            loc);
    // System.out.println("secrecy term: " + secrecyTerm.getRepresentation());

    ctx.addSessionGoalTerm(secrecyTerm);
    for (ITerm t : session.childChain(loc, child)) {
      ctx.addSessionGoalTerm(t);
    }
  }
Example #9
0
  /**
   * Spawns a mob somewhere on the map. Ensures it doesn't intersect anything and is on a spawn tile
   *
   * @param mob
   * @return
   */
  public boolean spawnMob(Mob mob) {
    float x = mob.getX();
    float y = mob.getY();
    TextureSet textureSet = mob.getWalkingTextureSet();

    // Check mob isn't out of bounds.
    if (x < 0
        || x > getMapWidth() - textureSet.getWidth()
        || y > getMapHeight() - textureSet.getHeight()) {
      return false;
    }

    // Check mob doesn't intersect anything.
    for (Entity entity : entities) {
      if (entity instanceof Character
          && (mob.intersects(entity.getX(), entity.getY(), entity.getWidth(), entity.getHeight())
              || mob.collidesX(0)
              || mob.collidesY(0))) {
        return false;
      }
    }

    if (getSpawnLayer().getCell((int) x / getTileWidth(), (int) y / getTileHeight()) == null) {
      return false;
    }

    entities.add(mob);
    return true;
  }
  @Override
  public boolean attackEntityAsMob(Entity victim) {
    float attackDamage =
        (float) getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
    int knockback = 0;

    if (victim instanceof EntityLivingBase) {
      attackDamage +=
          EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase) victim);
      knockback += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase) victim);
    }

    boolean attacked = victim.attackEntityFrom(DamageSource.causeMobDamage(this), attackDamage);

    if (attacked) {
      if (knockback > 0) {
        double vx = -Math.sin(Math.toRadians(rotationYaw)) * knockback * 0.5;
        double vy = 0.1;
        double vz = Math.cos(Math.toRadians(rotationYaw)) * knockback * 0.5;
        victim.addVelocity(vx, vy, vz);
        motionX *= 0.6;
        motionZ *= 0.6;
      }

      if (victim instanceof EntityLivingBase) {
        // EnchantmentThorns.func_92096_a(this, (EntityLivingBase) victim, rand);
      }

      setLastAttacker(victim);
    }

    return attacked;
  }
Example #11
0
 public static void main(String[] args) throws Exception {
   String testXml =
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
           + "<data>\n"
           + "  <message>\n"
           + "    <status>0</status>\n"
           + "    <value>处理成功</value>\n"
           + "  </message>\n"
           + "  <policeCheckInfos>\n"
           + "    <policeCheckInfo name=\"彭权艺\" id=\"431227199305110028\">\n"
           + "      <message>\n"
           + "        <status>0</status>\n"
           + "        <value>查询成功</value>\n"
           + "      </message>\n"
           + "      <name desc=\"姓名\">彭权艺</name>\n"
           + "      <identitycard desc=\"身份证号\">431227199305110028</identitycard>\n"
           + "      <compStatus desc=\"比对状态\">3</compStatus>\n"
           + "      <compResult desc=\"比对结果\">一致</compResult>\n"
           + "      <policeadd desc=\"原始发证地\">湖南省新晃侗族自治县</policeadd>\n"
           + "      <birthday2 desc=\"出生日期2\">19930511</birthday2>\n"
           + "      <sex2 desc=\"性别2\">女</sex2>\n"
           + "    </policeCheckInfo>\n"
           + "  </policeCheckInfos>\n"
           + "</data>";
   Entity reEntity = transformXmlToEntity(testXml);
   logger.trace(reEntity.dfsFind("policeCheckInfo").toString());
   return;
 }
Example #12
0
 static Entity method4886(int i, int i_34_, int i_35_, byte i_36_) {
   try {
     Class326 class326 =
         (client.aClass283_8716.method2675(-1611682495)
             .aClass326ArrayArrayArray3516[i][i_34_][i_35_]);
     if (class326 == null) return null;
     Entity class365_sub1_sub1_sub2 = null;
     int i_37_ = -1;
     for (Class322 class322 = class326.aClass322_3456;
         class322 != null;
         class322 = class322.aClass322_3360) {
       Class365_Sub1_Sub1 class365_sub1_sub1 = class322.aClass365_Sub1_Sub1_3359;
       if (class365_sub1_sub1 instanceof Entity) {
         Entity class365_sub1_sub1_sub2_38_ = (Entity) class365_sub1_sub1;
         int i_39_ = ((class365_sub1_sub1_sub2_38_.getSize() - 1) * 256 + 252);
         Class217 class217 = (class365_sub1_sub1_sub2_38_.method4337().aClass217_2599);
         int i_40_ = (int) class217.aFloat2451 - i_39_ >> 9;
         int i_41_ = (int) class217.aFloat2454 - i_39_ >> 9;
         int i_42_ = i_39_ + (int) class217.aFloat2451 >> 9;
         int i_43_ = i_39_ + (int) class217.aFloat2454 >> 9;
         if (i_40_ <= i_34_ && i_41_ <= i_35_ && i_42_ >= i_34_ && i_43_ >= i_35_) {
           int i_44_ = (1 + i_42_ - i_34_) * (i_43_ + 1 - i_35_);
           if (i_44_ > i_37_) {
             class365_sub1_sub1_sub2 = class365_sub1_sub1_sub2_38_;
             i_37_ = i_44_;
           }
         }
       }
     }
     return class365_sub1_sub1_sub2;
   } catch (RuntimeException runtimeexception) {
     throw Class346.method4175(
         runtimeexception, new StringBuilder().append("qe.id(").append(')').toString());
   }
 }
Example #13
0
 @Override
 public Entity getEntityById(int id) {
   synchronized (entities) {
     for (Entity entity : entities) if (id == entity.getId()) return entity;
     return null;
   }
 }
Example #14
0
  /**
   * @param dt
   * @param eBoundaries
   * @param listFeatIndsOfCurInp
   * @param listFeatCountOfCurInp
   * @throws IOException
   */
  private void createNgramFeatures(
      DependencyTree dt,
      int weight,
      Entity ent,
      ArrayList<Integer> listFeatIndsOfCurInp,
      ArrayList<Integer> listFeatCountOfCurInp)
      throws IOException {

    String[] feature = new String[0];

    // collecting the unigram within a window of {-x, +x}

    int x = ent.getStartWordIndex();
    for (int i = x - 1; i >= x - 2 && i >= 0; i--) {
      feature = new String[] {dt.allNodesByWordIndex[i].lemma + "$" + (i - x)};

      GenericFeatVect.addNewFeatureInList(
          feature, 1, listFeatIndsOfCurInp, listFeatCountOfCurInp, weight);
    }

    x = ent.getEndWordIndex();
    for (int i = x + 1; i <= x + 2 && i < dt.allNodesByWordIndex.length; i++) {
      feature = new String[] {dt.allNodesByWordIndex[i].lemma + "$" + (x - i)};

      GenericFeatVect.addNewFeatureInList(
          feature, 1, listFeatIndsOfCurInp, listFeatCountOfCurInp, weight);
    }
  }
Example #15
0
  public static void SP_trigger_key(Entity self) {
    if (GameBase.st.item == null) {
      ServerGame.PF_dprintf("no key item for trigger_key at " + Lib.vtos(self.s.origin) + "\n");
      return;
    }
    self.item = GameItems.FindItemByClassname(GameBase.st.item);

    if (null == self.item) {
      ServerGame.PF_dprintf(
          "item "
              + GameBase.st.item
              + " not found for trigger_key at "
              + Lib.vtos(self.s.origin)
              + "\n");
      return;
    }

    if (self.target == null) {
      ServerGame.PF_dprintf(self.classname + " at " + Lib.vtos(self.s.origin) + " has no target\n");
      return;
    }

    ServerInit.SV_SoundIndex("misc/keytry.wav");
    ServerInit.SV_SoundIndex("misc/keyuse.wav");

    self.use = trigger_key_use;
  }
Example #16
0
  /**
   * Draws everything onto the main panel.
   *
   * @param page Graphics component to draw on
   */
  public void paintComponent(Graphics page) {
    super.paintComponent(page);
    setForeground(Color.cyan);

    renderer.draw(page, this, offX, offY);

    //        hero.draw(this, page, offX, offY);

    for (Entity effect : effects) {
      effect.draw(this, page, offX, offY);
      /*if (effect instanceof Burst) {
          Burst pop = (Burst) effect;
          pop.draw(this, page, offX, offY);
      }*/
    }

    // Draw hero position information
    Rectangle r = hero.getBounds();
    page.drawString("Position: x = " + (r.x + (r.width >> 1)), SCORE_PLACE_X, SCORE_PLACE_Y);
    final int tab = 100;
    final int lineHeight = 20;
    page.drawString("y = " + (r.y + (r.height >> 1)), SCORE_PLACE_X + tab, SCORE_PLACE_Y);
    page.drawString("Frame: " + frame, SCORE_PLACE_X, SCORE_PLACE_Y + lineHeight);

    if (!running) {
      page.drawString("Game over :(", WIDTH / 2, HEIGHT / 2);
    }
  }
Example #17
0
 /*
  * QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE Pushes the player "speed"
  * defaults to 1000
  */
 public static void SP_trigger_push(Entity self) {
   InitTrigger(self);
   windsound = ServerInit.SV_SoundIndex("misc/windfly.wav");
   self.touch = trigger_push_touch;
   if (0 == self.speed) self.speed = 1000;
   World.SV_LinkEdict(self);
 }
Example #18
0
  public static String getEntityName(Class entity) {

    if (mappedName.get(entity) != null) {
      return mappedName.get(entity);
    }

    String name = null;

    Table table = (Table) entity.getAnnotation(Table.class);
    if (table != null && table.name() != null && !table.name().isEmpty()) {
      name = table.name();
    } else {
      Entity entityAnnotation = (Entity) entity.getAnnotation(Entity.class);
      if (entityAnnotation != null
          && entityAnnotation.name() != null
          && !entityAnnotation.name().isEmpty()) {
        name = entityAnnotation.name();
      } else {
        name = entity.getSimpleName();
      }
    }

    mappedName.put(entity, name);

    return name;
  }
Example #19
0
        public void touch(Entity self, Entity other, Plane plane, Surface surf) {
          int dflags;

          if (other.takedamage == 0) return;

          if (self.timestamp > GameBase.level.time) return;

          if ((self.spawnflags & 16) != 0) self.timestamp = GameBase.level.time + 1;
          else self.timestamp = GameBase.level.time + Constants.FRAMETIME;

          if (0 == (self.spawnflags & 4)) {
            if ((GameBase.level.framenum % 10) == 0)
              ServerGame.PF_StartSound(
                  other,
                  Constants.CHAN_AUTO,
                  self.noise_index,
                  (float) 1,
                  (float) Constants.ATTN_NORM,
                  (float) 0);
          }

          if ((self.spawnflags & 8) != 0) dflags = Constants.DAMAGE_NO_PROTECTION;
          else dflags = 0;
          GameCombat.T_Damage(
              other,
              self,
              self,
              Globals.vec3_origin,
              other.s.origin,
              Globals.vec3_origin,
              self.dmg,
              self.dmg,
              dflags,
              Constants.MOD_TRIGGER_HURT);
        }
Example #20
0
  public PooledEntity GetPooledEntity(Entity entity, float time) {
    synchronized (m_available) {
      if (!m_available.isEmpty()) {
        PooledEntity ent = m_available.get(0);
        ent.m_data.SetActive(true);
        try {
          ent.m_data.SetTransform((Transform2D) entity.GetTransform().clone());
        } catch (CloneNotSupportedException ex) {
          ex.printStackTrace();
        }
        ent.SetLife(time);

        m_inUse.add(ent);
        m_available.remove(0);
        return ent;
      } else {
        Entity entity_copy = entity.GetCopy();
        entity_copy.SetActive(true);

        PooledEntity ent = new PooledEntity(entity_copy, time);
        m_inUse.add(ent);
        return ent;
      }
    }
  }
  @Test
  public void userLastNameSearch() throws Exception {
    UUID applicationId = createApplication("testOrganization", "testLastName");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    String lastName = "lastName" + UUIDUtils.newTimeUUID();

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("username", "edanuff");
    properties.put("email", "*****@*****.**");
    properties.put("lastname", lastName);

    Entity user = em.create("user", properties);
    assertNotNull(user);

    // EntityRef
    Query query = new Query();
    query.addEqualityFilter("lastname", lastName);

    Results r = em.searchCollection(em.getApplicationRef(), "users", query);

    assertTrue(r.size() > 0);

    Entity returned = r.getEntities().get(0);

    assertEquals(user.getUuid(), returned.getUuid());
  }
  /** @see org.newdawn.asteroids.entity.Entity#collides(org.newdawn.asteroids.entity.Entity) */
  public boolean collides(Entity other) {
    // We're going to use simple circle collision here since we're
    // only worried about 2D collision.
    //
    // Normal math tells us that if the distance between the two
    // centres of the circles is less than the sum of their radius
    // then they collide. However, working out the distance between
    // the two would require a square root (Math.sqrt((dx*dx)+(dy*dy))
    // which could be quite slow.
    //
    // Instead we're going to square the sum of their radius and compare
    // that against the un-rooted value. This is equivilent but
    // much faster

    // Get the size of the other entity and combine it with our
    // own, giving the range of collision. Square this so we can
    // compare it against the current distance.
    float otherSize = other.getSize();
    float range = (otherSize + getSize());
    range *= range;

    // Get the distance on X and Y between the two entities, then
    // find the squared distance between the two.
    float dx = getX() - other.getX();
    float dy = getY() - other.getY();
    float distance = (dx * dx) + (dy * dy);

    // if the squared distance is less than the squared range
    // then we've had a collision!
    return (distance <= range);
  }
  @Test
  public void testKeywordsAndQuery() throws Exception {
    logger.info("testKeywordsOrQuery");

    UUID applicationId = createApplication("testOrganization", "testKeywordsAndQuery");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("title", "Galactians 2");
    properties.put("keywords", "Hot, Space Invaders, Classic");
    Entity firstGame = em.create("game", properties);

    properties = new LinkedHashMap<String, Object>();
    properties.put("title", "Bunnies Extreme");
    properties.put("keywords", "Hot, New");
    Entity secondGame = em.create("game", properties);

    properties = new LinkedHashMap<String, Object>();
    properties.put("title", "Hot Shots Extreme");
    properties.put("keywords", "Action, New");
    Entity thirdGame = em.create("game", properties);

    Query query =
        Query.fromQL("select * where keywords contains 'new' and title contains 'extreme'");
    Results r = em.searchCollection(em.getApplicationRef(), "games", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    assertEquals(2, r.size());

    assertEquals(secondGame.getUuid(), r.getEntities().get(0).getUuid());
    assertEquals(thirdGame.getUuid(), r.getEntities().get(1).getUuid());
  }
 public void a(World var1, Position var2, Entity var3, float var4) {
   if (var3.aw()) {
     super.a(var1, var2, var3, var4);
   } else {
     var3.e(var4, 0.0F);
   }
 }
Example #25
0
  @Test
  public void testSecondarySorts() throws Exception {
    logger.info("testSecondarySorts");

    UUID applicationId = createApplication("testOrganization", "testSecondarySorts");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    for (int i = alphabet.length - 1; i >= 0; i--) {
      String name = alphabet[i];
      Map<String, Object> properties = new LinkedHashMap<String, Object>();
      properties.put("name", name);
      properties.put("group", i / 3);
      properties.put("reverse_name", alphabet[alphabet.length - 1 - i]);

      em.create("item", properties);
    }

    Query query = Query.fromQL("group = 1 order by name desc");
    Results r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    int i = 6;
    for (Entity entity : r.getEntities()) {
      i--;
      assertEquals(1L, entity.getProperty("group"));
      assertEquals(alphabet[i], entity.getProperty("name"));
    }
    assertEquals(3, i);
  }
 public void a(World var1, Entity var2) {
   if (var2.aw()) {
     super.a(var1, var2);
   } else if (var2.motionY < 0.0D) {
     var2.motionY = -var2.motionY;
   }
 }
  @Test
  public void recycleEntity() {
    PooledEngine engine = new PooledEngine();

    int numEntities = 200;
    Array<Entity> entities = new Array<Entity>();

    for (int i = 0; i < numEntities; ++i) {
      Entity entity = engine.createEntity();
      assertEquals(0, entity.flags);
      engine.addEntity(entity);
      entities.add(entity);
      entity.flags = 1;
    }

    for (Entity entity : entities) {
      engine.removeEntity(entity);
      assertEquals(0, entity.flags);
    }

    for (int i = 0; i < numEntities; ++i) {
      Entity entity = engine.createEntity();
      assertEquals(0, entity.flags);
      engine.addEntity(entity);
      entities.add(entity);
    }
  }
Example #28
0
  private void runTest(TransactionWithQuery<Root, Entity> createEntityTransaction)
      throws Exception {

    // Create or load existing prevalence layer from journal and/or snapshot.
    String dataPath = "target/PrevalenceBase_" + System.currentTimeMillis();
    Prevayler<Root> prevayler = PrevaylerFactory.createPrevayler(new Root(), dataPath);

    try {
      final Entity entity = prevayler.execute(createEntityTransaction);
      final long timestampWhenInitiallyCreated = entity.getCreated();

      // close and reopen prevalence so the journal is replayed
      prevayler.close();
      prevayler = PrevaylerFactory.createPrevayler(new Root(), dataPath);

      long timestampAfterRestart =
          prevayler.execute(
              new Query<Root, Long>() {
                public Long query(Root prevalentSystem, Date executionTime) throws Exception {
                  return prevalentSystem.getEntities().get(entity.getIdentity()).getCreated();
                }
              });

      assertEquals(
          "timestamp should not have changed",
          timestampWhenInitiallyCreated,
          timestampAfterRestart);

    } finally {
      prevayler.close();
    }
  }
  public double getNetGravAccel(double x1, double y1, char component, Entity e) {
    double net = 0;

    if (ents.size() <= 1) return 0;

    try {
      for (Entity other : ents) {
        double x2 = other.getX();
        double y2 = other.getY();
        if (x1 == x2 && y1 == y2) // if distance is 0 (testing itself) then it will divide by 0
        continue;
        double distance = Util.distance(x1, y1, x2, y2);
        // if(Refs.sim.isCollisionType(Simulation.NONCOLLIDE)) //if current collision type is
        // noncollide
        if (Util.areColliding(e, other)) // if colliding, no gravitational effect
        continue;
        double accel = 0;
        accel = other.getMass() / Math.pow(distance, 2);
        double proportion = 1;
        if (component == 'x') proportion = ((x2 - x1)) / distance;
        if (component == 'y') proportion = ((y2 - y1)) / distance;
        net += accel * proportion;
      }
    } catch (Exception ex) {
    }

    return Refs.sim.getGravitationConstant() * net;
  }
Example #30
0
File: Graph.java Project: AKSW/SINA
 public Entity addLiteralEntity(int index) {
   Entity j = new Entity();
   j.setIRI("?l" + index);
   j.settype(Constants.TYPE_LITERAL); // type of literal
   LiteralVariable.add(j);
   return j;
 }