Exemple #1
0
  private void renderBlackout(Graphics g, int x, int y, int radius) {
    if (radius > 320) return;

    int[] xp = new int[20];
    int[] yp = new int[20];
    for (int i = 0; i < 16; i++) {
      xp[i] = x + (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y + (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 240;
    xp[18] = 0;
    yp[18] = 240;
    xp[19] = 0;
    yp[19] = y;
    g.fillPolygon(xp, yp, xp.length);

    for (int i = 0; i < 16; i++) {
      xp[i] = x - (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y - (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 0;
    xp[18] = 0;
    yp[18] = 0;
    xp[19] = 0;
    yp[19] = y;

    g.fillPolygon(xp, yp, xp.length);
  }
Exemple #2
0
  private void renderDirectionArrow(Graphics g) {
    if (widthArrow < 0) g.setColor(new Color(0, 0, 255, 150));
    else g.setColor(new Color(255, 0, 0, 150));

    g.fillPolygon(
        xPositionsArrow, yPositionsArrow, Math.min(xPositionsArrow.length, yPositionsArrow.length));
    g.setColor(new Color(0, 0, 0, 255));
    g.drawPolygon(
        xPositionsArrow, yPositionsArrow, Math.min(xPositionsArrow.length, yPositionsArrow.length));
  }
Exemple #3
0
  public void move() {
    if (deadTime > 0) {
      deadTime--;

      if (deadTime == 0) {
        deadTime = 1;
        for (int i = 0; i < 8; i++) {
          world.addSprite(
              new Sparkle(
                  (int) (x + Math.random() * 16 - 8) + 4,
                  (int) (y - Math.random() * 8) + 4,
                  (float) (Math.random() * 2 - 1),
                  (float) Math.random() * -1,
                  0,
                  1,
                  5));
        }
        spriteContext.removeSprite(this);
      }

      x += xa;
      y += ya;
      ya *= 0.95;
      ya += 1;

      return;
    }

    tick++;

    if (y >= yStart) {
      y = yStart;

      int xd = (int) (Math.abs(world.mario.x - x));
      jumpTime++;
      if (jumpTime > 40 && xd > 24) {
        ya = -8;
      } else {
        ya = 0;
      }
    } else {
      jumpTime = 0;
    }

    y += ya;
    ya *= 0.9;
    ya += 0.1f;

    xPic = ((tick / 2) & 1) * 2 + ((tick / 6) & 1);
  }
Exemple #4
0
  public void tick() {
    timeLeft--;

    if (widthArrow < 0) {
      widthArrow *= -1;
      tipWidthArrow *= -1;

      xPositionsArrow =
          new int[] {
            xArrow + -widthArrow / 2,
            xArrow + widthArrow / 2 - tipWidthArrow,
            xArrow + widthArrow / 2 - tipWidthArrow,
            xArrow + widthArrow / 2,
            xArrow + widthArrow / 2 - tipWidthArrow,
            xArrow + widthArrow / 2 - tipWidthArrow,
            xArrow + -widthArrow / 2
          };
      yPositionsArrow =
          new int[] {
            yArrow + -heightArrow / 4,
            yArrow + -heightArrow / 4,
            yArrow + -heightArrow / 2,
            yArrow + 0,
            yArrow + heightArrow / 2,
            yArrow + heightArrow / 4,
            yArrow + heightArrow / 4
          };
    }

    if (timeLeft == 0) {
      mario.dieTime();
    }

    xCamO = xCam;
    yCamO = yCam;

    if (startTime > 0) {
      startTime++;
    }

    float targetXCam = mario.x - 160;

    xCam = targetXCam;

    if (xCam < 0) xCam = 0;
    if (xCam > level.getWidth() * 16 - 320) xCam = level.getWidth() * 16 - 320;

    /*      if (recorder != null)
    {
    recorder.addTick(mario.getKeyMask());
    }

    if (replayer!=null)
    {
    mario.setKeys(replayer.nextTick());
    }*/

    fireballsOnScreen = 0;

    for (Sprite sprite : sprites) {
      if (sprite != mario) {
        float xd = sprite.x - xCam;
        float yd = sprite.y - yCam;
        if (xd < -64 || xd > 320 + 64 || yd < -64 || yd > 240 + 64) {
          removeSprite(sprite);
        } else {
          if (sprite instanceof Fireball) {
            fireballsOnScreen++;
          }
        }
      }
    }

    if (paused) {
      for (Sprite sprite : sprites) {
        if (sprite == mario) {
          sprite.tick();
        } else {
          sprite.tickNoMove();
        }
      }
    } else {

      tick++;
      level.tick();

      boolean hasShotCannon = false;
      int xCannon = 0;

      for (int x = (int) xCam / 16 - 1; x <= (int) (xCam + layer.width) / 16 + 1; x++)
        for (int y = (int) yCam / 16 - 1; y <= (int) (yCam + layer.height) / 16 + 1; y++) {
          int dir = 0;

          if (x * 16 + 8 > mario.x + 16) dir = -1;
          if (x * 16 + 8 < mario.x - 16) dir = 1;

          SpriteTemplate st = level.getSpriteTemplate(x, y);

          if (st != null) {
            if (st.lastVisibleTick != tick - 1) {
              if (st.sprite == null || !sprites.contains(st.sprite)) {
                st.spawn(this, x, y, dir);
              }
            }

            st.lastVisibleTick = tick;
          }

          if (dir != 0) {
            byte b = level.getBlock(x, y);
            if (((Level.TILE_BEHAVIORS[b & 0xff]) & Level.BIT_ANIMATED) > 0) {
              if ((b % 16) / 4 == 3 && b / 16 == 0) {
                if ((tick - x * 2) % 100 == 0) {
                  xCannon = x;
                  for (int i = 0; i < 8; i++) {
                    addSprite(
                        new Sparkle(
                            x * 16 + 8,
                            y * 16 + (int) (Math.random() * 16),
                            (float) Math.random() * dir,
                            0,
                            0,
                            1,
                            5));
                  }
                  addSprite(new BulletBill(this, x * 16 + 8 + dir * 8, y * 16 + 15, dir));
                  hasShotCannon = true;
                }
              }
            }
          }
        }

      if (hasShotCannon) {
        sound.play(
            Art.samples[Art.SAMPLE_CANNON_FIRE],
            new FixedSoundSource(xCannon * 16, yCam + 120),
            1,
            1,
            1);
      }

      for (Sprite sprite : sprites) {
        sprite.tick();
      }

      for (Sprite sprite : sprites) {
        sprite.collideCheck();
      }

      for (Shell shell : shellsToCheck) {
        for (Sprite sprite : sprites) {
          if (sprite != shell && !shell.dead) {
            if (sprite.shellCollideCheck(shell)) {
              if (mario.carried == shell && !shell.dead) {
                mario.carried = null;
                shell.die();
              }
            }
          }
        }
      }
      shellsToCheck.clear();

      for (Fireball fireball : fireballsToCheck) {
        for (Sprite sprite : sprites) {
          if (sprite != fireball && !fireball.dead) {
            if (sprite.fireballCollideCheck(fireball)) {
              fireball.die();
            }
          }
        }
      }
      fireballsToCheck.clear();
    }

    sprites.addAll(0, spritesToAdd);
    sprites.removeAll(spritesToRemove);
    spritesToAdd.clear();
    spritesToRemove.clear();

    // TODO: THIS IS TEST FLIP
    //        if(keys[Mario.KEY_UP] && tick%2 == 0)
    //        	level.startFlipping = true;

    //        if(level.canFlip)
    //        	flip();
  }