Scale and rotate the cursor.

- Cursor is now scaled based on window size.
- Cursor now rotates slowly (new style only).
- Cursor now expands upon mouse press.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2014-07-06 23:13:33 -04:00
parent 6d3c333a3f
commit a9cc7a3deb
8 changed files with 51 additions and 6 deletions

View File

@ -18,6 +18,7 @@
package itdelatrisu.opsu;
import itdelatrisu.opsu.states.Game;
import itdelatrisu.opsu.states.Options;
import java.awt.Font;
@ -104,6 +105,7 @@ public class Utils {
// game-related variables
private static GameContainer container;
private static StateBasedGame game;
private static Input input;
// This class should not be instantiated.
@ -118,6 +120,7 @@ public class Utils {
public static void init(GameContainer container, StateBasedGame game)
throws SlickException {
Utils.container = container;
Utils.game = game;
Utils.input = container.getInput();
// game settings
@ -245,6 +248,13 @@ public class Utils {
else
cursorTrail = new Image("cursortrail2.png");
}
// scale the cursor
float scale = 1 + ((container.getHeight() - 600) / 1000f);
cursor = cursor.getScaledCopy(scale);
cursorTrail = cursorTrail.getScaledCopy(scale);
if (cursorMiddle != null)
cursorMiddle = cursorMiddle.getScaledCopy(scale);
}
/**
@ -304,10 +314,24 @@ public class Utils {
}
cursorTrail.drawCentered(x, y);
// increase the cursor size if pressed
float scale = 1f;
if (game.getCurrentStateID() == Opsu.STATE_GAME &&
((Game) game.getState(Opsu.STATE_GAME)).isInputKeyPressed())
scale = 1.25f;
else if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ||
input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON))
scale = 1.25f;
// draw the other components
cursor.drawCentered(x, y);
if (cursorMiddle != null)
cursorMiddle.drawCentered(x, y);
Image cursorScaled = cursor.getScaledCopy(scale);
cursorScaled.setRotation(cursor.getRotation());
cursorScaled.drawCentered(x, y);
if (cursorMiddle != null) {
Image cursorMiddleScaled = cursorMiddle.getScaledCopy(scale);
cursorMiddleScaled.setRotation(cursorMiddle.getRotation());
cursorMiddleScaled.drawCentered(x, y);
}
}
/**
@ -361,6 +385,18 @@ public class Utils {
}
}
/**
* Rotates the cursor by a degree determined by a delta interval.
* If the old style cursor is being used, this will do nothing.
* @param delta the delta interval since the last call
*/
public static void updateCursor(int delta) {
if (cursorMiddle == null)
return;
cursor.rotate(delta / 40f);
}
/**
* Draws the FPS at the bottom-right corner of the game container.
* If the option is not activated, this will do nothing.

View File

@ -407,6 +407,8 @@ public class Game extends BasicGameState {
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
Utils.updateCursor(delta);
if (isLeadIn()) { // stop updating during song lead-in
leadInTime -= delta;
if (!isLeadIn())

View File

@ -97,7 +97,7 @@ public class GamePauseMenu extends BasicGameState {
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
// empty
Utils.updateCursor(delta);
}
@Override

View File

@ -136,7 +136,7 @@ public class GameRanking extends BasicGameState {
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
// empty
Utils.updateCursor(delta);
}
@Override

View File

@ -223,6 +223,8 @@ public class MainMenu extends BasicGameState {
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
Utils.updateCursor(delta);
// fade in background
if (bgAlpha < 0.9f) {
bgAlpha += delta / 1000f;

View File

@ -51,6 +51,7 @@ public class MainMenuExit extends BasicGameState {
*/
private float centerOffset;
// game-related variables
private GameContainer container;
private StateBasedGame game;
private int state;
@ -113,6 +114,8 @@ public class MainMenuExit extends BasicGameState {
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
Utils.updateCursor(delta);
// move buttons to center
float yesX = yesButton.getX(), noX = noButton.getX();
float center = container.getWidth() / 2f;

View File

@ -496,7 +496,7 @@ public class Options extends BasicGameState {
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
// empty
Utils.updateCursor(delta);
}
@Override

View File

@ -275,6 +275,8 @@ public class SongMenu extends BasicGameState {
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
Utils.updateCursor(delta);
// search
searchTimer += delta;
if (searchTimer >= SEARCH_DELAY) {