Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | 'use client' import { useGameMode } from '@/contexts/GameModeContext' import { useUserProfile } from '@/contexts/UserProfileContext' import { useComplementRace } from '@/arcade-games/complement-race/Provider' import type { AIRacer } from '../../lib/gameTypes' import { SpeechBubble } from '../AISystem/SpeechBubble' interface LinearTrackProps { playerProgress: number aiRacers: AIRacer[] raceGoal: number showFinishLine?: boolean } export function LinearTrack({ playerProgress, aiRacers, raceGoal, showFinishLine = true, }: LinearTrackProps) { const { state, dispatch } = useComplementRace() const { players, activePlayers } = useGameMode() const { profile: _profile } = useUserProfile() // Get the current user's active local players (consistent with navbar pattern) const activeLocalPlayers = Array.from(activePlayers) .map((id) => players.get(id)) .filter((p): p is NonNullable<typeof p> => p !== undefined && p.isLocal !== false) const playerEmoji = activeLocalPlayers[0]?.emoji ?? '👤' // Position calculation: leftPercent = Math.min(98, (progress / raceGoal) * 96 + 2) // 2% minimum (start), 98% maximum (near finish), 96% range for race const getPosition = (progress: number) => { return Math.min(98, (progress / raceGoal) * 96 + 2) } const playerPosition = getPosition(playerProgress) return ( <div data-component="linear-track" style={{ position: 'relative', width: '100%', height: '200px', background: 'linear-gradient(to bottom, #87ceeb 0%, #e0f2fe 50%, #90ee90 50%, #d4f1d4 100%)', borderRadius: '12px', overflow: 'hidden', boxShadow: '0 4px 12px rgba(0, 0, 0, 0.15)', marginTop: '20px', }} > {/* Track lines */} <div style={{ position: 'absolute', top: '50%', left: 0, right: 0, height: '2px', background: 'rgba(0, 0, 0, 0.1)', transform: 'translateY(-50%)', }} /> <div style={{ position: 'absolute', top: '40%', left: 0, right: 0, height: '1px', background: 'rgba(0, 0, 0, 0.05)', transform: 'translateY(-50%)', }} /> <div style={{ position: 'absolute', top: '60%', left: 0, right: 0, height: '1px', background: 'rgba(0, 0, 0, 0.05)', transform: 'translateY(-50%)', }} /> {/* Finish line */} {showFinishLine && ( <div style={{ position: 'absolute', right: '2%', top: 0, bottom: 0, width: '4px', background: 'repeating-linear-gradient(0deg, black 0px, black 10px, white 10px, white 20px)', boxShadow: '0 0 10px rgba(0, 0, 0, 0.3)', }} /> )} {/* Player racer */} <div style={{ position: 'absolute', left: `${playerPosition}%`, top: '50%', transform: 'translate(-50%, -50%) scaleX(-1)', fontSize: '32px', transition: 'left 0.3s ease-out', filter: 'drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2))', zIndex: 10, }} > {playerEmoji} </div> {/* AI racers */} {aiRacers.map((racer, index) => { const aiPosition = getPosition(racer.position) const activeBubble = state.activeSpeechBubbles.get(racer.id) return ( <div key={racer.id} style={{ position: 'absolute', left: `${aiPosition}%`, top: `${35 + index * 15}%`, transform: 'translate(-50%, -50%) scaleX(-1)', fontSize: '28px', transition: 'left 0.2s linear', filter: 'drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2))', zIndex: 5, }} > {racer.icon} {activeBubble && ( <div style={{ position: 'absolute', bottom: '100%', // Position above the AI racer left: '50%', transform: 'translate(-50%, -15px) scaleX(-1)', // Offset 15px above, counter-flip bubble zIndex: 20, // Above player (10) and AI racers (5) }} > <SpeechBubble message={activeBubble} onHide={() => dispatch({ type: 'CLEAR_AI_COMMENT', racerId: racer.id })} /> </div> )} </div> ) })} {/* Progress indicator */} <div style={{ position: 'absolute', bottom: '10px', left: '10px', background: 'rgba(255, 255, 255, 0.9)', padding: '6px 12px', borderRadius: '8px', fontSize: '14px', fontWeight: 'bold', color: '#1f2937', boxShadow: '0 2px 6px rgba(0, 0, 0, 0.1)', }} > {playerProgress} / {raceGoal} </div> </div> ) } |