Vec vec_by_mouse(int x, int y) {
    Vec ans = new Vec();
    ans.x = (x - dim.width / 2.) / size;
    ans.y = -(y - dim.height / 2.) / size;

    return ans;
  }
Exemple #2
0
  public void nextStep() {
    synchronized (this) {
      if (needRecalc) {
        recalcImpact();
        needRecalc = false;
      }

      for (iter.x = 0; iter.x < mSize; ++iter.x) {
        for (iter.y = 0; iter.y < nSize; ++iter.y) {
          final double imp = impMat[iter.x][iter.y];
          if (rules.dieCond(imp)) {
            fldNew[iter.x][iter.y] = DEAD;
          } else if (rules.birthCond(imp)) {
            fldNew[iter.x][iter.y] = ALIVE;
          }
        }
      }
      swap();
      needRecalc = true;
      recalcImpact();
    }

    setChanged();
    notifyObservers(new FieldUpdate(this));
  }
 Vec wall_power(Ball p) {
   Vec ans = new Vec();
   is_colide = false;
   ans.x = wall_power2(p.pos.x);
   ans.y = wall_power2(p.pos.y);
   if (is_colide) ans.sub_to(p.speed.mult(10));
   return ans;
 }
Exemple #4
0
  private void recalcImpact() {
    for (iter.x = 0; iter.x < mSize; ++iter.x) {
      for (iter.y = 0; iter.y < nSize; ++iter.y) {
        double imp = 0;
        for (int i = 0; i < rules.neighborsRel.length; ++i) {
          Vec neighRel = rules.neighborsRel[i];
          reliter.set(neighRel);
          reliter.addPlace(iter);

          if (Math.abs(neighRel.y) % 2 == 1) {
            if (iter.y % 2 == 0 && neighRel.x > 0) --reliter.x;
            else if (iter.y % 2 == 1 && neighRel.x < 0) ++reliter.x;
          }
          if (vecAvail(reliter) && isAlive(reliter)) imp += rules.distImpacts[rules.dists[i]];
        }
        impMat[iter.x][iter.y] = imp;
      }
    }
  }
 Vec mult(double scalar) {
   Vec ans = new Vec();
   ans.x = x * scalar;
   ans.y = y * scalar;
   return ans;
 }
 Vec sub(Vec right) {
   Vec ans = new Vec();
   ans.x = x - right.x;
   ans.y = y - right.y;
   return ans;
 }
 Vec add(Vec right) {
   Vec ans = new Vec();
   ans.x = x + right.x;
   ans.y = y + right.y;
   return ans;
 }
 Vec div(double a) {
   Vec ans = new Vec();
   ans.x = x / a;
   ans.y = y / a;
   return ans;
 }