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:
parent
6d3c333a3f
commit
a9cc7a3deb
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
package itdelatrisu.opsu;
|
package itdelatrisu.opsu;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.states.Game;
|
||||||
import itdelatrisu.opsu.states.Options;
|
import itdelatrisu.opsu.states.Options;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
@ -104,6 +105,7 @@ public class Utils {
|
||||||
|
|
||||||
// game-related variables
|
// game-related variables
|
||||||
private static GameContainer container;
|
private static GameContainer container;
|
||||||
|
private static StateBasedGame game;
|
||||||
private static Input input;
|
private static Input input;
|
||||||
|
|
||||||
// This class should not be instantiated.
|
// This class should not be instantiated.
|
||||||
|
@ -118,6 +120,7 @@ public class Utils {
|
||||||
public static void init(GameContainer container, StateBasedGame game)
|
public static void init(GameContainer container, StateBasedGame game)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
Utils.container = container;
|
Utils.container = container;
|
||||||
|
Utils.game = game;
|
||||||
Utils.input = container.getInput();
|
Utils.input = container.getInput();
|
||||||
|
|
||||||
// game settings
|
// game settings
|
||||||
|
@ -245,6 +248,13 @@ public class Utils {
|
||||||
else
|
else
|
||||||
cursorTrail = new Image("cursortrail2.png");
|
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);
|
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
|
// draw the other components
|
||||||
cursor.drawCentered(x, y);
|
Image cursorScaled = cursor.getScaledCopy(scale);
|
||||||
if (cursorMiddle != null)
|
cursorScaled.setRotation(cursor.getRotation());
|
||||||
cursorMiddle.drawCentered(x, y);
|
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.
|
* Draws the FPS at the bottom-right corner of the game container.
|
||||||
* If the option is not activated, this will do nothing.
|
* If the option is not activated, this will do nothing.
|
||||||
|
|
|
@ -407,6 +407,8 @@ public class Game extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public void update(GameContainer container, StateBasedGame game, int delta)
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
|
Utils.updateCursor(delta);
|
||||||
|
|
||||||
if (isLeadIn()) { // stop updating during song lead-in
|
if (isLeadIn()) { // stop updating during song lead-in
|
||||||
leadInTime -= delta;
|
leadInTime -= delta;
|
||||||
if (!isLeadIn())
|
if (!isLeadIn())
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class GamePauseMenu extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public void update(GameContainer container, StateBasedGame game, int delta)
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
// empty
|
Utils.updateCursor(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class GameRanking extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public void update(GameContainer container, StateBasedGame game, int delta)
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
// empty
|
Utils.updateCursor(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -223,6 +223,8 @@ public class MainMenu extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public void update(GameContainer container, StateBasedGame game, int delta)
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
|
Utils.updateCursor(delta);
|
||||||
|
|
||||||
// fade in background
|
// fade in background
|
||||||
if (bgAlpha < 0.9f) {
|
if (bgAlpha < 0.9f) {
|
||||||
bgAlpha += delta / 1000f;
|
bgAlpha += delta / 1000f;
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class MainMenuExit extends BasicGameState {
|
||||||
*/
|
*/
|
||||||
private float centerOffset;
|
private float centerOffset;
|
||||||
|
|
||||||
|
// game-related variables
|
||||||
private GameContainer container;
|
private GameContainer container;
|
||||||
private StateBasedGame game;
|
private StateBasedGame game;
|
||||||
private int state;
|
private int state;
|
||||||
|
@ -113,6 +114,8 @@ public class MainMenuExit extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public void update(GameContainer container, StateBasedGame game, int delta)
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
|
Utils.updateCursor(delta);
|
||||||
|
|
||||||
// move buttons to center
|
// move buttons to center
|
||||||
float yesX = yesButton.getX(), noX = noButton.getX();
|
float yesX = yesButton.getX(), noX = noButton.getX();
|
||||||
float center = container.getWidth() / 2f;
|
float center = container.getWidth() / 2f;
|
||||||
|
|
|
@ -496,7 +496,7 @@ public class Options extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public void update(GameContainer container, StateBasedGame game, int delta)
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
// empty
|
Utils.updateCursor(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -275,6 +275,8 @@ public class SongMenu extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public void update(GameContainer container, StateBasedGame game, int delta)
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
|
Utils.updateCursor(delta);
|
||||||
|
|
||||||
// search
|
// search
|
||||||
searchTimer += delta;
|
searchTimer += delta;
|
||||||
if (searchTimer >= SEARCH_DELAY) {
|
if (searchTimer >= SEARCH_DELAY) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user