Exemple #1
0
  private void updatePosition() {
    updatePosLast();

    pos.setLocation(pos.x + vel.x * Wuigi.time(), pos.y + vel.y * Wuigi.time());

    if (!dead && pos.y + Wuigi.GROUND_LEVEL < 0) {
      kill(true);
      // pos.y = pos.y + Wuigi.GROUND_LEVEL + 1;
      falling = false;
    } else if (pos.y < 0 && !dead && !piped && (!falling || invulerable)) {
      setPos(pos.x, 0);
      // yOffset = Wuigi.GROUND_LEVEL;
    }

    if (pos.x > lastX + 20 || pos.x < lastX - 20) {
      rightFoot = !rightFoot;
      lastX = pos.x;
    }
    if (piped && pos.y + height < lineToCross && vel.y < 0) changeWorlds = true;
    if (piped && pos.y > lineToCross && vel.y > 0) {
      vel.y = 0;
      pos.y = lineToCross;
      piped = false;
    }
  }
Exemple #2
0
  public void think() {
    if (dead && deadTime > 0) {
      deadTime -= Wuigi.time();
      if (deadTime < 0) {
        vel.x = 0;
        vel.y = 15;
      }
      return;
    }

    if (star) {
      starTime += Wuigi.time();
      if (starTime > 10000 / 15) { // if you've been in starman mode for more than 10 seconds, stop
        star = false;
        starTime = 0;
        setSpriteColor(spriteColor, true);
      } else {
        setSpriteColor((int) (Math.random() * 6), true);
      }
    }

    if (invulerable) {
      invulerableTime += Wuigi.time();
      if (invulerableTime > 5000 / 15) {
        invulerable = false;
        invulerableTime = 0;
      }
    }

    if (cape) {
      capeTime += Wuigi.time();
      if (capeTime > 10000 / 15) {
        cape = false;
        capeTime = 0;
      }
    }

    updatePosition();
    xOffset += pos.x - posLast.x;
    if (xOffset > X_OFFSET) xOffset = X_OFFSET;
    else if (xOffset < -X_OFFSET) xOffset = -X_OFFSET;

    yOffset += pos.y - posLast.y;
    if (!(dead || falling)) {
      if (yOffset > Y_OFFSET) yOffset = Y_OFFSET;
      else if (yOffset < Y_OFFSET / 8) yOffset = Y_OFFSET / 8;
    }
    updateVelocity();
    // double v = vel.y;
    // if(v > 0 && vel.y < 0){
    //	System.out.println("position: " + pos.y);
    // }
    falling = false;
  }
Exemple #3
0
 // double jolt =
 private void jumpAdd() {
   if (vel.y == 0 || dead) {
     jumpAdd = 0;
   } else {
     double add = 0.4 * jumpAdd / Wuigi.COMPLETE_JUMP_TIME * Wuigi.time();
     vel.y += add;
   }
 }
Exemple #4
0
  // CONSTANT METHODS
  public void draw(Graphics g, ImageObserver o) {

    boolean transparent =
        invulerable && (invulerableTime < 3000 / 15 || System.currentTimeMillis() % 60 > 30);
    if (transparent)
      ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    int x = Wuigi.scaleW(Wuigi.screenWidth / 2.0 + xOffset - 4);
    int y = Wuigi.scaleH(Wuigi.screenHeight - yOffset);
    if (cape) {
      if (facingRight)
        g.drawImage(
            TCape.IMAGE.getBuffer(),
            x - 5,
            y,
            Wuigi.scaleW(WIDTH + 8),
            Wuigi.scaleH(HEIGHT + 2),
            o);
      else
        g.drawImage(
            TCape.IMAGE.flipX(), x + 5, y, Wuigi.scaleW(WIDTH + 8), Wuigi.scaleH(HEIGHT + 2), o);
    }

    drawAWP(g, x, y);

    g.drawImage(
        figureOutDrawImage(IMAGE),
        x,
        // (int)(Global.H-H-pos.y-Global.GROUND_LEVEL),
        y,
        Wuigi.scaleW(WIDTH + 8),
        Wuigi.scaleH(HEIGHT + 2),
        o);
    if (transparent)
      ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));

    // g.setColor(Color.WHITE);
    // g.drawRect((int)(Wuigi.W/2 - X_OFFSET), (int)(Wuigi.H - Y_OFFSET), (int)X_OFFSET*2 + width,
    // (int)(Y_OFFSET*2) - Wuigi.H);
  }
Exemple #5
0
  private void updateVelocity() {
    if (piped) {
      return;
    }
    if (jumpAdd > 0) {
      jumpAdd -= Wuigi.time();
      jumpAdd();
      acc.y = 0;
    }
    if (jumping) {
      jumping = false;
    } else if (!dead) {
      int tempMove = move;
      if (move == 0) {
        if (vel.x > 0) tempMove = -1;
        else tempMove = 1;
      }
      double xadd;
      // stopping
      if (vel.x > 0 && move <= 0 || vel.x < 0 && move >= 0) {
        xadd = tempMove * X_VEL_PER_TICK * 2.0 * Wuigi.time();
        // moving forward
      } else {
        xadd = tempMove * X_VEL_PER_TICK * Wuigi.time();
      }
      if (vel.y < 0 && !metal) {
        vel.x += xadd / 3;
      } else {
        vel.x += xadd;
      }
      if (move == 0 && tempMove * vel.x > 0) {
        vel.x = 0;
      }
      if (!infSpeed) {
        if (vel.x < -MAX_X_VEL) vel.x = -MAX_X_VEL;
        else if (vel.x > MAX_X_VEL) vel.x = MAX_X_VEL;
      }
    }

    if (vel.x < X_VEL_PER_TICK * Wuigi.time() && vel.x > -X_VEL_PER_TICK * Wuigi.time()) vel.x = 0;

    vel.x += acc.x * Wuigi.time();
    vel.y += acc.y * Wuigi.time();

    // S//ystem.out.println(acc.y);
    if (falling && invulerable) {
      falling = false;
    }
    if (pos.y > 0 && !(cape && movingUp) || falling) {
      acc.y = -Wuigi.GRAVITY;
      if (cape) {
        acc.y /= 4;
      }
    } else if (cape && movingUp && vel.y > 5) {
      acc.y = 0;
      vel.y = 5;
    } else if (!jumping && !dead && !(cape && movingUp)) {
      vel.y = 0;
      acc.y = 0;
    }
  }
Exemple #6
0
  /**
   * draws the backdrop to the screen
   *
   * @param g
   * @param o
   * @param hero to be used to check against for parallax scrolling
   */
  public void draw(Graphics g, java.awt.image.ImageObserver o, Hero hero) {
    double viewX = hero.viewX();
    double viewY = hero.viewY();
    if (underground) g.setColor(UNDERGROUND_COLOR);
    else g.setColor(Backdrop.SKY_COLOR);
    g.fillRect(0, 0, Wuigi.screenWidth, Wuigi.screenHeight);
    Image ground;
    int groundHeight, groundWidth;
    // g.setColor(SKY_COLOR);
    if (!underground) {
      ground = GRASS;
      groundHeight = ground.getHeight(o);
      groundWidth = ground.getWidth(o);
      int skyHeight = SKY.getHeight(o) * 3, skyWidth = SKY.getWidth(o) * 3;

      double x = -viewX * SKY_MULTI;
      double y = (viewY - (Wuigi.screenHeight - Wuigi.GROUND_LEVEL)) * SKY_MULTI;
      while (x > 0) x -= skyWidth;
      ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
      for (; x < Wuigi.screenWidth; x += skyWidth) {
        g.drawImage(
            SKY,
            Wuigi.scaleW(x),
            Wuigi.scaleH(y),
            Wuigi.scaleW(skyWidth),
            Wuigi.scaleH(skyHeight),
            o);
      }
      ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));

      /*((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));

        	x = -viewX*BUILDINGS_MULTI;
        	y = viewY - buildingHeight;
        	while(x > 0)
        		x -= buildingWidth;
        	for(; x < Wuigi.W; x+=buildingWidth){
        		g.drawImage(BUILDINGS, Wuigi.scaleW(x),Wuigi.scaleH(y),Wuigi.scaleW(buildingWidth),Wuigi.scaleH(buildingHeight),o);
        	}


      ((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.00f));
      */
    } else {
      ground = BRICK;
      groundHeight = ground.getHeight(o) * 2;
      groundWidth = ground.getWidth(o) * 2;
    }

    for (double y = viewY; y < Wuigi.screenHeight; y += groundHeight) {
      double x = viewX;
      x *= -GROUND_MULTI;
      while (x > 0) x -= groundWidth;

      for (; x < Wuigi.screenWidth; x += groundWidth) {
        g.drawImage(
            ground,
            Wuigi.scaleW(x),
            Wuigi.scaleH(y),
            Wuigi.scaleW(groundWidth),
            Wuigi.scaleH(groundHeight),
            o);
      }
    }
  }