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; } }
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; }
// 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; } }
// 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); }
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; } }