示例#1
0
  public void run() {
    // boolean frame=Clock.frame;
    counter++;
    if (life != 0) {
      life--;
      image = ani[counter / 5 % 4];
      if (life >= 0) image = ani[8];
      if (life > 2) image = ani[7];
      if (life > 4) image = ani[6];
      if (life > 6) image = ani[5];
      if (life > 8) image = ani[4];
      // Clock.waitFor(frame=!frame);
      // if(Clock.dead)break;

      if (life < 0) {
        // vX*=.98;vY*=.98;
        x += vX;
        y -= vY;
      }
      if (life == -200) {
        vY = vX = 0;
        life = 10;
        x += 4 - round(8 * random());
        y += 4 - round(8 * random());
      }
      for (VisibleObject en : Room.enemies) {
        if (Collisions.collides(this, en)) {
          ((Enemy) en).damage(Element.WATER, 3);
          ((Enemy) en).vMultiplier = .00001f;
        }
      }
      if (life >= 0) return;
      for (Wall wal : Room.walls) {
        // if (vY==0&&vX==0)break;
        if (Collisions.collides(this, wal)) {
          vY = vX = 0;
          life = 10;
          x += 4 - round(8 * random());
          y += 4 - round(8 * random());
          // AudioPack.playAudio("BExplosion2.wav",0.05);
          AudioPack.playClip(boom);
          if (wal.damagable) {
            ((DamageableWall) wal).life -= 5;
            // if
            // (Jump.kraidLife<=0&&Jump.countdown<0){Jump.countdown=500;
            // AudioPack.playAudio("Ima Firen Mah Lazor!.wav",0.1);
            // }
          }
        }
      }
      // out.println(life);
    } else dead = true;
  }
示例#2
0
  public void run() {
    if (life <= 0) {
      for (int d = (int) (3 * random()); d > 0; d--) {
        Room.items.add(new Health(x + w / 2, y + h / 2, vx, vy));
      }
      AudioPack.playClip(screams[(int) (screams.length * random())]);
      dead = true;
    }
    if (life > 0 && !dead) {
      // if(Thread.interrupted())break;
      // Clock.waitFor();
      // if(Clock.dead)break;
      curFrame++;
      curFrame %= 20;
      image = images[curFrame / 5];
      if (Collisions.collides(this, Player.player)) {
        Player.damage(1);
      }

      if (vMultiplier == 0) vMultiplier = 10 * Float.MIN_VALUE;

      vx *= vMultiplier;
      vy *= vMultiplier;

      x += vx;
      // if(x<0||x>Room.WIDTH){vx=-vx;}
      for (Wall wal : Room.walls) {
        if (vx == 0) break;
        if (Collisions.willCollide(this, wal, vx, 0)) {
          if (vx > 0) {
            x = wal.x - w;
          } else {
            x = wal.x + wal.w;
          }
          vx = -vx;
          break;
        }
      }

      vx /= vMultiplier;
      vy /= vMultiplier;

      vMultiplier += .03 * (1 - vMultiplier > 0 ? 1 : (abs(vMultiplier) <= .03 ? 0 : -1));
    }
  }
示例#3
0
  public void run() {
    // boolean frame=Clock.frame;
    if (life != 0) {
      counter++;
      vY -= .07;
      int p = (counter / 3) % 8;
      image = ani[p];

      if (life > -1) {
        image = ani[min(life, 8) / 2 + 8];
      }

      // Clock.waitFor(frame=!frame);
      // if(Clock.dead)break;
      life--;
      if (life < 0) {
        x += vX;
        y -= vY;
      } else return;
      /*
       * if (!(x>0&&x<Jump.WIDTH&&y>0&&y<Jump.HEIGHT)&&life<0){vY=vX=0;
       * life=60; w=h=16; x-=round(10*random()); y-=round(10*random());
       * //AudioPack.playAudio("BExplosion2.wav",0.05);
       * AudioPack.playClip(boom); }
       */
      boolean collided = false;
      for (int i = 0; i < Room.walls.size(); i++) {
        Wall wal = Room.walls.get(i);
        if (vY == 0 && vX == 0) break;
        if (Collisions.collides(this, wal)) {

          collided = true;
          if (wal.damagable) {
            ((DamageableWall) wal).life -= 40;
            // if
            // (Jump.kraidLife<=0&&Jump.countdown<0){Jump.countdown=500;
            // AudioPack.playAudio("Ima Firen Mah Lazor!.wav",0.1);
            // }
          }
        }
      }

      if (Collisions.collides(this, Player.player)) {
        collided = true;
        Player.damage(40);
      }
      if (collided) {
        double offset = Math.PI * ((80 * random()) % 8) / 4;
        Room.projectiles.add(
            new RockProjectile(x, y, (float) cos(offset) * 3, (float) sin(offset) * 3));
        Room.projectiles.add(
            new RockProjectile(
                x, y, (float) cos(offset + PI * 2 / 3) * 3, (float) sin(offset + PI * 2 / 3) * 3));
        Room.projectiles.add(
            new RockProjectile(
                x, y, (float) cos(offset + PI * 4 / 3) * 3, (float) sin(offset + PI * 4 / 3) * 3));

        life = 12;
        w = h = 11;
        x -= round(vY * random());
        y -= round(vX * random());
        vY = vX = 0;
        // AudioPack.playAudio("BExplosion2.wav",0.05);
        AudioPack.playClip(boom);
      }

    } else dead = true;
  }