render mirrored

This commit is contained in:
yugecin
2016-09-29 21:40:42 +02:00
parent 72aa856818
commit 9a73ab23e9
6 changed files with 61 additions and 15 deletions

View File

@@ -89,7 +89,7 @@ public class Circle extends GameObject {
} }
@Override @Override
public void draw(Graphics g, int trackPosition) { public void draw(Graphics g, int trackPosition, boolean mirror) {
int timeDiff = hitObject.getTime() - trackPosition; int timeDiff = hitObject.getTime() - trackPosition;
final int approachTime = game.getApproachTime(); final int approachTime = game.getApproachTime();
final int fadeInTime = game.getFadeInTime(); final int fadeInTime = game.getFadeInTime();
@@ -98,6 +98,11 @@ public class Circle extends GameObject {
float fadeinScale = (timeDiff - approachTime + fadeInTime) / (float) fadeInTime; float fadeinScale = (timeDiff - approachTime + fadeInTime) / (float) fadeInTime;
float alpha = Utils.clamp(1 - fadeinScale, 0, 1); float alpha = Utils.clamp(1 - fadeinScale, 0, 1);
g.pushTransform();
if (mirror) {
g.rotate(x, y, -180f);
}
if (GameMod.HIDDEN.isActive()) { if (GameMod.HIDDEN.isActive()) {
final int hiddenDecayTime = game.getHiddenDecayTime(); final int hiddenDecayTime = game.getHiddenDecayTime();
final int hiddenTimeDiff = game.getHiddenTimeDiff(); final int hiddenTimeDiff = game.getHiddenTimeDiff();
@@ -122,6 +127,8 @@ public class Circle extends GameObject {
GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Colors.WHITE_FADE); GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Colors.WHITE_FADE);
Colors.WHITE_FADE.a = oldAlpha; Colors.WHITE_FADE.a = oldAlpha;
g.popTransform();
} }
/** /**

View File

@@ -43,7 +43,7 @@ public class DummyObject extends GameObject {
} }
@Override @Override
public void draw(Graphics g, int trackPosition) {} public void draw(Graphics g, int trackPosition, boolean mirror) {}
@Override @Override
public boolean update(boolean overlap, int delta, int mouseX, int mouseY, boolean keyPressed, int trackPosition) { public boolean update(boolean overlap, int delta, int mouseX, int mouseY, boolean keyPressed, int trackPosition) {

View File

@@ -43,7 +43,7 @@ public abstract class GameObject {
* @param g the graphics context * @param g the graphics context
* @param trackPosition the current track position * @param trackPosition the current track position
*/ */
public abstract void draw(Graphics g, int trackPosition); public abstract void draw(Graphics g, int trackPosition, boolean mirrored);
/** /**
* Updates the hit object. * Updates the hit object.

View File

@@ -176,7 +176,7 @@ public class Slider extends GameObject {
} }
@Override @Override
public void draw(Graphics g, int trackPosition) { public void draw(Graphics g, int trackPosition, boolean mirror) {
int timeDiff = hitObject.getTime() - trackPosition; int timeDiff = hitObject.getTime() - trackPosition;
final int approachTime = game.getApproachTime(); final int approachTime = game.getApproachTime();
final int fadeInTime = game.getFadeInTime(); final int fadeInTime = game.getFadeInTime();
@@ -196,6 +196,11 @@ public class Slider extends GameObject {
curve.draw(color,curveInterval); curve.draw(color,curveInterval);
color.a = alpha; color.a = alpha;
g.pushTransform();
if (mirror) {
g.rotate(x, y, -180f);
}
/* /*
// end circle // end circle
Vec2f endCircPos = curve.pointAt(curveInterval); Vec2f endCircPos = curve.pointAt(curveInterval);
@@ -208,6 +213,8 @@ public class Slider extends GameObject {
if (!overlayAboveNumber) if (!overlayAboveNumber)
hitCircleOverlay.drawCentered(x, y, Colors.WHITE_FADE); hitCircleOverlay.drawCentered(x, y, Colors.WHITE_FADE);
g.popTransform();
// ticks // ticks
if (ticksT != null) { if (ticksT != null) {
float tickScale = 0.5f + 0.5f * AnimationEquation.OUT_BACK.calc(decorationsAlpha); float tickScale = 0.5f + 0.5f * AnimationEquation.OUT_BACK.calc(decorationsAlpha);
@@ -215,10 +222,21 @@ public class Slider extends GameObject {
for (int i = 0; i < ticksT.length; i++) { for (int i = 0; i < ticksT.length; i++) {
Vec2f c = curve.pointAt(ticksT[i]); Vec2f c = curve.pointAt(ticksT[i]);
Colors.WHITE_FADE.a = decorationsAlpha; Colors.WHITE_FADE.a = decorationsAlpha;
g.pushTransform();
if (mirror) {
g.rotate(c.x, c.y, -180f);
}
tick.drawCentered(c.x, c.y, Colors.WHITE_FADE); tick.drawCentered(c.x, c.y, Colors.WHITE_FADE);
g.popTransform();
Colors.WHITE_FADE.a = alpha; Colors.WHITE_FADE.a = alpha;
} }
} }
g.pushTransform();
if (mirror) {
g.rotate(x, y, -180f);
}
if (GameMod.HIDDEN.isActive()) { if (GameMod.HIDDEN.isActive()) {
final int hiddenDecayTime = game.getHiddenDecayTime(); final int hiddenDecayTime = game.getHiddenDecayTime();
final int hiddenTimeDiff = game.getHiddenTimeDiff(); final int hiddenTimeDiff = game.getHiddenTimeDiff();
@@ -235,6 +253,8 @@ public class Slider extends GameObject {
if (overlayAboveNumber) if (overlayAboveNumber)
hitCircleOverlay.drawCentered(x, y, Colors.WHITE_FADE); hitCircleOverlay.drawCentered(x, y, Colors.WHITE_FADE);
g.popTransform();
// repeats // repeats
if (curveInterval == 1.0f) { if (curveInterval == 1.0f) {
for (int tcurRepeat = currentRepeats; tcurRepeat <= currentRepeats + 1; tcurRepeat++) { for (int tcurRepeat = currentRepeats; tcurRepeat <= currentRepeats + 1; tcurRepeat++) {
@@ -264,8 +284,14 @@ public class Slider extends GameObject {
if (timeDiff >= 0) { if (timeDiff >= 0) {
// approach circle // approach circle
if (!GameMod.HIDDEN.isActive()) g.pushTransform();
if (mirror) {
g.rotate(x, y, -180f);
}
if (!GameMod.HIDDEN.isActive()) {
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color); GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
}
g.popTransform();
} else { } else {
// Since update() might not have run before drawing during a replay, the // Since update() might not have run before drawing during a replay, the
// slider time may not have been calculated, which causes NAN numbers and flicker. // slider time may not have been calculated, which causes NAN numbers and flicker.

View File

@@ -175,7 +175,10 @@ public class Spinner extends GameObject {
} }
@Override @Override
public void draw(Graphics g, int trackPosition) { public void draw(Graphics g, int trackPosition, boolean mirror) {
if (mirror) {
return;
}
// only draw spinners shortly before start time // only draw spinners shortly before start time
int timeDiff = hitObject.getTime() - trackPosition; int timeDiff = hitObject.getTime() - trackPosition;
final int fadeInTime = game.getFadeInTime(); final int fadeInTime = game.getFadeInTime();

View File

@@ -47,10 +47,7 @@ import itdelatrisu.opsu.render.FrameBufferCache;
import itdelatrisu.opsu.replay.PlaybackSpeed; import itdelatrisu.opsu.replay.PlaybackSpeed;
import itdelatrisu.opsu.replay.Replay; import itdelatrisu.opsu.replay.Replay;
import itdelatrisu.opsu.replay.ReplayFrame; import itdelatrisu.opsu.replay.ReplayFrame;
import itdelatrisu.opsu.ui.Colors; import itdelatrisu.opsu.ui.*;
import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.MenuButton;
import itdelatrisu.opsu.ui.UI;
import itdelatrisu.opsu.ui.animations.AnimationEquation; import itdelatrisu.opsu.ui.animations.AnimationEquation;
import java.io.File; import java.io.File;
@@ -269,8 +266,11 @@ public class Game extends BasicGameState {
private Input input; private Input input;
private final int state; private final int state;
private final Cursor mirrorCursor;
public Game(int state) { public Game(int state) {
this.state = state; this.state = state;
mirrorCursor = new Cursor();
} }
@Override @Override
@@ -599,8 +599,14 @@ public class Game extends BasicGameState {
if (isReplay) if (isReplay)
UI.draw(g, replayX, replayY, replayKeyPressed); UI.draw(g, replayX, replayY, replayKeyPressed);
else if (GameMod.AUTO.isActive()) else if (GameMod.AUTO.isActive()) {
UI.draw(g, (int) autoMousePosition.x, (int) autoMousePosition.y, autoMousePressed); UI.draw(g, (int) autoMousePosition.x, (int) autoMousePosition.y, autoMousePressed);
double dx = autoMousePosition.x - Options.width / 2d;
double dy = autoMousePosition.y - Options.height / 2d;
double d = Math.sqrt(dx * dx + dy * dy);
double a = Math.atan2(dy, dx) + Math.PI;
mirrorCursor.draw((int) (Math.cos(a) * d + Options.width / 2), (int) (Math.sin(a) * d + Options.height / 2), autoMousePressed);
}
else if (GameMod.AUTOPILOT.isActive()) else if (GameMod.AUTOPILOT.isActive())
UI.draw(g, (int) autoMousePosition.x, (int) autoMousePosition.y, Utils.isGameKeyPressed()); UI.draw(g, (int) autoMousePosition.x, (int) autoMousePosition.y, Utils.isGameKeyPressed());
else else
@@ -1389,9 +1395,13 @@ public class Game extends BasicGameState {
GameObject gameObj = gameObjects[idx]; GameObject gameObj = gameObjects[idx];
// normal case // normal case
if (!loseState) if (!loseState) {
gameObj.draw(g, trackPosition); gameObj.draw(g, trackPosition, false);
g.pushTransform();
g.rotate(Options.width / 2f, Options.height / 2f, 180f);
gameObj.draw(g, trackPosition, true);
g.popTransform();
}
// death: make objects "fall" off the screen // death: make objects "fall" off the screen
else { else {
// time the object began falling // time the object began falling
@@ -1417,7 +1427,7 @@ public class Game extends BasicGameState {
g.translate(0, dt * dt * container.getHeight()); g.translate(0, dt * dt * container.getHeight());
Vec2f rotationCenter = gameObj.getPointAt(beatmap.objects[idx].getTime()); Vec2f rotationCenter = gameObj.getPointAt(beatmap.objects[idx].getTime());
g.rotate(rotationCenter.x, rotationCenter.y, rotSpeed * dt); g.rotate(rotationCenter.x, rotationCenter.y, rotSpeed * dt);
gameObj.draw(g, trackPosition); gameObj.draw(g, trackPosition, false);
g.popTransform(); g.popTransform();
} }