Skip to content

Commit 59c75e9

Browse files
Fix conditional power-up timing bug
- Add pendingConditionalPowerUp to defer activation until next room - Conditional power-ups now properly activate at start of next room - Only lose conditional if it was active from previous room and not used - Add 'USE OR LOSE!' warning badge when conditional power-up is active
1 parent 3871d7f commit 59c75e9

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

src/game/logic.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,14 +729,14 @@ export function rollPowerUp(): void {
729729
addLogEntry(`Power-Up Roll: ${r}`);
730730

731731
let powerUps = state.powerUps;
732-
let conditionalPowerUp = false;
732+
let pendingConditionalPowerUp = false;
733733

734734
if (r >= 98) {
735735
powerUps += 2;
736736
addLogEntry('Gained 2 Power-Ups!');
737737
} else if (r >= 86) {
738738
powerUps += 1;
739-
conditionalPowerUp = true;
739+
pendingConditionalPowerUp = true;
740740
addLogEntry('Gained 1 Conditional Power-Up (must use next room or lose it)');
741741
} else if (r >= 76) {
742742
powerUps += 1;
@@ -745,7 +745,7 @@ export function rollPowerUp(): void {
745745
addLogEntry('No Power-Up gained');
746746
}
747747

748-
updateState({ powerUps, conditionalPowerUp, phase: 'next-room' });
748+
updateState({ powerUps, pendingConditionalPowerUp, phase: 'next-room' });
749749
}
750750

751751
export function nextRoom(): void {
@@ -757,12 +757,16 @@ export function nextRoom(): void {
757757
let isLastRoom = state.isLastRoom;
758758
let oneLastBreathPending = state.oneLastBreathPending;
759759

760+
// Check if conditional power-up from PREVIOUS room was not used
760761
if (state.conditionalPowerUp && !state.usedPowerUpThisRoom) {
761762
powerUps = Math.max(0, powerUps - 1);
762763
powerUpBlockedThisRoom = true;
763764
addLogEntry('Conditional Power-Up lost (not used this room)');
764765
}
765766

767+
// Convert pending conditional (just earned) to active conditional for next room
768+
const conditionalPowerUp = state.pendingConditionalPowerUp;
769+
766770
if (state.oneLastBreathPending) {
767771
isLastRoom = true;
768772
oneLastBreathPending = false;
@@ -783,7 +787,8 @@ export function nextRoom(): void {
783787
curseTargetRoll: null,
784788
pendingTargetCurseRolls: 0,
785789
painShiftActive: false,
786-
conditionalPowerUp: false,
790+
conditionalPowerUp,
791+
pendingConditionalPowerUp: false,
787792
powerUps,
788793
powerUpBlockedThisRoom,
789794
isLastRoom,

src/game/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function createInitialState(mode: GameMode, manualTrackType: boolean): Ga
6060
pendingTargetCurseRolls: 0,
6161
painShiftActive: false,
6262
conditionalPowerUp: false,
63+
pendingConditionalPowerUp: false,
6364
powerUpBlockedThisRoom: false,
6465
oneLastBreathPending: false,
6566
splitWoundActive: false,

src/game/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export interface GameState {
8585
pendingTargetCurseRolls: number;
8686
painShiftActive: boolean;
8787
conditionalPowerUp: boolean;
88+
pendingConditionalPowerUp: boolean;
8889
powerUpBlockedThisRoom: boolean;
8990
oneLastBreathPending: boolean;
9091
splitWoundActive: boolean;

src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ <h2>Continue Run</h2>
5151
<div>
5252
<span class="badge">Room <span id="room-number">1</span></span>
5353
<span class="badge powerup">Power-Ups: <span id="powerup-count">0</span></span>
54+
<span id="conditional-badge" class="badge warning hidden">USE OR LOSE!</span>
5455
<span class="badge" id="mode-badge">Normal</span>
5556
<span id="timer" class="badge timer hidden">5:00</span>
5657
</div>

src/styles.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ select {
152152
color: #fff;
153153
}
154154

155+
.badge.warning {
156+
background: #ff9800;
157+
color: #000;
158+
font-weight: bold;
159+
animation: pulse 1s infinite;
160+
}
161+
155162
.badge.timer {
156163
background: var(--accent);
157164
color: #fff;

src/ui/render.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export function render(): void {
3131
setText('powerup-count', String(state.powerUps));
3232
setText('mode-badge', state.mode.charAt(0).toUpperCase() + state.mode.slice(1));
3333

34+
// Show conditional power-up warning
35+
const conditionalBadge = $('conditional-badge');
36+
if (conditionalBadge) {
37+
conditionalBadge.classList.toggle('hidden', !state.conditionalPowerUp);
38+
}
39+
3440
renderTracks();
3541
renderLog();
3642
renderRoom();

0 commit comments

Comments
 (0)