예제 #1
0
    public void move() {
      x += 2.0 * gamespeed * xdir;
      if (x < 0 + xPosition) {
        xdir = 1;
      }
      if (x > pfWidth() / 2 + xPosition - 44) {
        xdir = -1;
      }
      if ((int) x % 20 == 0) {
        if (bullets.size < 3) {
          long timeNow = System.currentTimeMillis();
          if (timeNow - lastBullet > 300) {
            JGObject bullet = new JGObject("bullet", true, x - 8, y - 8, 4, "bullet", 0, -14, -2);
            bullets.put(bullet.getName(), bullet);
            playAudio("shoot");
            lastBullet = timeNow;
          }
        }
      }

      for (int i = 0; i < bullets.size; i++) {
        JGObject obj = (JGObject) bullets.values[i];
        if (!obj.isAlive()) {
          bullets.remove(obj.getName());
        }
      }
    }
예제 #2
0
    public void move() {
      if (getKey(KeyLeft) && x > 14) {
        x -= 14 * gamespeed;
      }
      if (getKey(KeyUp) && y > 14) {
        y -= 14 * gamespeed;
      }
      if (getKey(KeyRight) && x < pfWidth() - 51 - 14) {
        x += 14 * gamespeed;
      }
      if (getKey(KeyDown) && y < pfHeight() - 51 - 14) {
        y += 14 * gamespeed;
      }
      if (getKey(' ')) {
        if (bullets.size < 2) {
          long timeNow = System.currentTimeMillis();
          if (timeNow - lastBullet > 500) {
            JGObject bullet = new JGObject("bullet", true, x - 8, y - 8, 4, "bullet", 0, -14, -2);
            bullets.put(bullet.getName(), bullet);
            playAudio("shoot");
            clearKey(' ');
            lastBullet = timeNow;
          }
        }
      }

      for (int i = 0; i < bullets.size; i++) {
        JGObject obj = (JGObject) bullets.values[i];
        if (!obj.isAlive()) {
          bullets.remove(obj.getName());
        }
      }
    }