Пример #1
0
  public boolean isFree(Entity ee, double xc, double yc, int w, int h, double xa, double ya) {
    if (ee.interactsWithWorld) {
      return isBulletFree(ee, xc, yc, w, h);
    }
    double e = 0.1;
    int x0 = (int) (xc / 10);
    int y0 = (int) (yc / 10);
    int x1 = (int) ((xc + w - e) / 10);
    int y1 = (int) ((yc + h - e) / 10);
    boolean ok = true;
    for (int x = x0; x <= x1; x++)
      for (int y = y0; y <= y1; y++) {
        if (x >= 0 && y >= 0 && x < width && y < height) {
          byte ww = walls[x + y * width];
          if (ww != 0) ok = false;
          if (ww == 8) ok = true;
          if (ww == 4 && ya != 0) ee.hitSpikes();
          if (ww == 6) {
            ee.xa += 0.12;
          }
          if (ww == 7) {
            ee.xa -= 0.12;
          }
        }
      }

    return ok;
  }
Пример #2
0
 public void tick() {
   tick++;
   if (player.removed) {
     respawnTime++;
     if (respawnTime == 20) {
       screen.mayRespawn = true;
     }
   }
   for (int i = 0; i < entities.size(); i++) {
     Entity e = entities.get(i);
     int xSlotOld = e.xSlot;
     int ySlotOld = e.ySlot;
     if (!e.removed) e.tick();
     e.xSlot = (int) ((e.x + e.w / 2.0) / 10);
     e.ySlot = (int) ((e.y + e.h / 2.0) / 10);
     if (e.removed) {
       if (xSlotOld >= 0 && ySlotOld >= 0 && xSlotOld < width && ySlotOld < height) {
         entityMap[xSlotOld + ySlotOld * width].remove(e);
       }
       entities.remove(i--);
     } else {
       if (e.xSlot != xSlotOld || e.ySlot != ySlotOld) {
         if (xSlotOld >= 0 && ySlotOld >= 0 && xSlotOld < width && ySlotOld < height) {
           entityMap[xSlotOld + ySlotOld * width].remove(e);
         }
         if (e.xSlot >= 0 && e.ySlot >= 0 && e.xSlot < width && e.ySlot < height) {
           entityMap[e.xSlot + e.ySlot * width].add(e);
         } else {
           e.outOfBounds();
         }
       }
     }
   }
 }
Пример #3
0
  public void render(Screen screen, Camera camera) {
    matrix.idt();
    matrix.setToTranslation(camera.x, camera.y, 0);
    screen.spriteBatch.setTransformMatrix(matrix);
    screen.spriteBatch.begin();
    // g.translate(-camera.x, -camera.y);

    int xo = 0;
    int yo = 0;
    for (int x = xo; x <= xo + camera.width / 10; x++) {
      for (int y = yo; y <= yo + camera.height / 10; y++) {
        if (x >= 0 && y >= 0 && x < width && y < height) {
          int ximg = 0;
          int yimg = 0;
          byte w = walls[x + y * width];
          if (w == 0) yimg = 1;
          if (w == 1) ximg = 0;
          if (w == 2) ximg = 2;
          if (w == 3) ximg = 1;
          if (w == 9) ximg = 7;
          if (w == 8) {
            ximg = 4;
            yimg = 1;
          }
          if (w == 5) {
            ximg = 1;
            yimg = 1;
          }
          if (w == 6) {
            ximg = (tick / 4 + x * 2) & 3;
            yimg = 2;
          }
          if (w == 7) {
            ximg = (-tick / 4 + x * 2) & 3;
            yimg = 3;
          }
          if (w == 4) {
            if (walls[x + (y - 1) * width] == 1) {
              yimg++;
            }
            ximg = 3;
          }

          if (w == 0) continue;

          screen.draw(Art.walls[ximg][yimg], x * 10, y * 10);
        }
      }
    }
    for (int i = entities.size() - 1; i >= 0; i--) {
      Entity e = entities.get(i);
      e.render(screen, camera);
    }

    screen.spriteBatch.end();
  }
Пример #4
0
  public void add(Entity e) {
    entities.add(e);
    e.init(this);

    e.xSlot = (int) ((e.x + e.w / 2.0) / 10);
    e.ySlot = (int) ((e.y + e.h / 2.0) / 10);
    if (e.xSlot >= 0 && e.ySlot >= 0 && e.xSlot < width && e.ySlot < height) {
      entityMap[e.xSlot + e.ySlot * width].add(e);
    }
  }
Пример #5
0
  public boolean isBulletFree(Entity bullet, double xc, double yc, int w, int h) {
    double e = 0.1;
    int x0 = (int) (xc / 10);
    int y0 = (int) (yc / 10);
    int x1 = (int) ((xc + w - e) / 10);
    int y1 = (int) ((yc + h - e) / 10);
    boolean ok = true;
    for (int x = x0; x <= x1; x++)
      for (int y = y0; y <= y1; y++) {
        if (x >= 0 && y >= 0 && x < width && y < height) {
          byte ww = walls[x + y * width];
          if (ww != 0) ok = false;
          if (ww == 5) ok = true;
          if (ww == 2) {
            int xPush = 0;
            int yPush = 0;

            if (Math.abs(bullet.xa) > Math.abs(bullet.ya)) {
              if (bullet.xa < 0) xPush = -1;
              if (bullet.xa > 0) xPush = 1;
            } else {
              if (bullet.ya < 0) yPush = -1;
              if (bullet.ya > 0) yPush = 1;
            }
            double r = 0.5;
            if (walls[(x + xPush) + (y + yPush) * width] == 0
                && getEntities((x + xPush) * 10 + r, (y + yPush) * 10 + r, 10 - r * 2, 10 - r * 2)
                        .size()
                    == 0) {
              walls[x + y * width] = 0;
              walls[(x + xPush) + (y + yPush) * width] = 2;
            }
            bullet.remove();
          }
          if (ww == 3) {
            Sound.boom.play();
            for (int i = 0; i < 16; i++) {
              double dir = i * Math.PI * 2 / 8.0;
              double xa = Math.sin(dir);
              double ya = Math.cos(dir);
              double dist = (i / 8) + 1;
              add(new Explosion(1, i * 3, x * 10 + 5 + xa * dist, y * 10 + 5 + ya * dist, xa, ya));
            }
            bullet.remove();
            walls[x + y * width] = 0;
          }
          if (ww == 9) {
            if ((bullet instanceof Explosion) && ((Explosion) bullet).power > 0) {
              Sound.boom.play();
              for (int i = 0; i < 16; i++) {
                double dir = i * Math.PI * 2 / 8.0;
                double xa = Math.sin(dir);
                double ya = Math.cos(dir);
                double dist = (i / 8) + 1;
                add(
                    new Explosion(
                        1, i * 3, x * 10 + 5 + xa * dist, y * 10 + 5 + ya * dist, xa, ya));
              }
              bullet.remove();
              walls[x + y * width] = 0;
            }
          }
        }
      }

    return ok;
  }