Skip to content

Commit

Permalink
Merge pull request #154 from Feodor0090/pause-delay
Browse files Browse the repository at this point in the history
Delay pause menu appearing for one second
  • Loading branch information
Feodor0090 authored Jun 18, 2023
2 parents 91c1667 + ade2282 commit 93f6e51
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/nmania/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ private final void UpdateHealthX() {
* block input.
*/
public boolean isPaused = false;
/**
* Set this flag to true to allow interacting with pause menu.
*/
public boolean hudAcceptsInput = true;
/**
* Make this flag false to end update loop.
*/
Expand Down Expand Up @@ -520,6 +524,8 @@ public final void Dispose() {

protected final void keyPressed(final int k) {
if (isPaused && !failed) {
if (!hudAcceptsInput)
return;
if (k == -1 || k == '2') {
pauseItem--;
if (pauseItem < 0)
Expand All @@ -545,6 +551,8 @@ protected final void keyPressed(final int k) {
return;
}
if (isPaused && failed) {
if (!hudAcceptsInput)
return;
if (k == -1 || k == '2' || k == -2 || k == '8') {
pauseItem = pauseItem == 0 ? 1 : 0;
return;
Expand Down Expand Up @@ -650,6 +658,8 @@ public final void TriggerPause() {

protected final void pointerPressed(final int x, final int y) {
if (isPaused) {
if (!hudAcceptsInput)
return;
if (failed) {
if (y < scrH / 3)
return;
Expand Down Expand Up @@ -1039,6 +1049,27 @@ private final void PassSequence() {
* Loop method, that handles pause menu redrawing.
*/
private final void PauseUpdateLoop() {
hudAcceptsInput = false; // block overlay while it's not visible
long s = System.currentTimeMillis();
while (true) {
int p = (int) (System.currentTimeMillis() - s);
if (p < 1000) {
final int a = 360 - (p * 360 / 1000);
final int x = scrW / 2 - 30;
final int y = scrH / 2 - 30;
final int d = 60;
g.setColor(-1);
g.fillArc(x, y, d, d, 0, 360);
g.setColor(0);
g.fillArc(x, y, d, d, 90, a);
g.setColor(-1);
g.drawArc(x - 1, y - 1, d, d, 0, 360);
flushGraphics();
} else {
hudAcceptsInput = true;
break;
}
}
while (isPaused) {
int sh3 = scrH / 3;
int bh = sh3 * 2 / 3;
Expand Down

0 comments on commit 93f6e51

Please sign in to comment.