-
Couldn't load subscription status.
- Fork 64
feat: add draggable minimap and enhance score display with improved score #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,52 @@ function saveDarkMode(isDarkMode) { | |||||||||||||||||||||||||||||||||||||
| localStorage.setItem('darkMode', isDarkMode); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| function initMinimapDrag() { | ||||||||||||||||||||||||||||||||||||||
| const minimap = document.getElementById('minimap'); | ||||||||||||||||||||||||||||||||||||||
| let isDragging = false; | ||||||||||||||||||||||||||||||||||||||
| let currentX; | ||||||||||||||||||||||||||||||||||||||
| let currentY; | ||||||||||||||||||||||||||||||||||||||
| let initialX; | ||||||||||||||||||||||||||||||||||||||
| let initialY; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| minimap.addEventListener('mousedown', (e) => { | ||||||||||||||||||||||||||||||||||||||
| isDragging = true; | ||||||||||||||||||||||||||||||||||||||
| initialX = e.clientX - currentX; | ||||||||||||||||||||||||||||||||||||||
| initialY = e.clientY - currentY; | ||||||||||||||||||||||||||||||||||||||
| minimap.style.cursor = 'grabbing'; | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mousedown event handler uses
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| document.addEventListener('mousemove', (e) => { | ||||||||||||||||||||||||||||||||||||||
| if (!isDragging) return; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||||||
| currentX = e.clientX - initialX; | ||||||||||||||||||||||||||||||||||||||
| currentY = e.clientY - initialY; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Keep minimap within viewport bounds | ||||||||||||||||||||||||||||||||||||||
| const minimapRect = minimap.getBoundingClientRect(); | ||||||||||||||||||||||||||||||||||||||
| const viewportWidth = window.innerWidth; | ||||||||||||||||||||||||||||||||||||||
| const viewportHeight = window.innerHeight; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| currentX = Math.max(0, Math.min(currentX, viewportWidth - minimapRect.width)); | ||||||||||||||||||||||||||||||||||||||
| currentY = Math.max(0, Math.min(currentY, viewportHeight - minimapRect.height)); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| minimap.style.left = `${currentX}px`; | ||||||||||||||||||||||||||||||||||||||
| minimap.style.bottom = `${viewportHeight - currentY - minimapRect.height}px`; | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| document.addEventListener('mouseup', () => { | ||||||||||||||||||||||||||||||||||||||
| isDragging = false; | ||||||||||||||||||||||||||||||||||||||
| minimap.style.cursor = 'grab'; | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Initialize position and cursor | ||||||||||||||||||||||||||||||||||||||
| const minimapRect = minimap.getBoundingClientRect(); | ||||||||||||||||||||||||||||||||||||||
| currentX = minimapRect.left; | ||||||||||||||||||||||||||||||||||||||
| currentY = minimapRect.top; | ||||||||||||||||||||||||||||||||||||||
| minimap.style.cursor = 'grab'; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export function initUI() { | ||||||||||||||||||||||||||||||||||||||
| const settingsIcon = document.getElementById('settings-icon'); | ||||||||||||||||||||||||||||||||||||||
| const settingsPanel = document.getElementById('settings-panel'); | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -18,6 +64,9 @@ export function initUI() { | |||||||||||||||||||||||||||||||||||||
| // Load dark mode preference | ||||||||||||||||||||||||||||||||||||||
| loadDarkMode(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Initialize minimap dragging | ||||||||||||||||||||||||||||||||||||||
| initMinimapDrag(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Toggle settings panel | ||||||||||||||||||||||||||||||||||||||
| settingsIcon.addEventListener('click', (e) => { | ||||||||||||||||||||||||||||||||||||||
| e.stopPropagation(); // Prevent click from propagating to document | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||
| <!DOCTYPE html> | ||||||||||
| <html> | ||||||||||
| <html lang="en"> | ||||||||||
| <head> | ||||||||||
| <title>Windsurf vs All</title> | ||||||||||
| <style> | ||||||||||
|
|
@@ -25,16 +25,36 @@ | |||||||||
| } | ||||||||||
| #score { | ||||||||||
| position: absolute; | ||||||||||
| top: 10px; | ||||||||||
| left: 10px; | ||||||||||
| font-family: Arial, sans-serif; | ||||||||||
| font-size: 20px; | ||||||||||
| color: #333; | ||||||||||
| text-shadow: 0 0 3px rgba(255, 255, 255, 0.5); | ||||||||||
| top: 20px; | ||||||||||
| left: 20px; | ||||||||||
| font-family: 'Arial', sans-serif; | ||||||||||
| background: linear-gradient(135deg, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.6)); | ||||||||||
| padding: 12px 20px; | ||||||||||
| border-radius: 15px; | ||||||||||
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | ||||||||||
| backdrop-filter: blur(5px); | ||||||||||
| border: 1px solid rgba(255, 255, 255, 0.1); | ||||||||||
| transition: all 0.3s ease; | ||||||||||
| } | ||||||||||
| #score .label { | ||||||||||
| font-size: 14px; | ||||||||||
| color: rgba(255, 255, 255, 0.7); | ||||||||||
| text-transform: uppercase; | ||||||||||
| letter-spacing: 1px; | ||||||||||
| margin-bottom: 4px; | ||||||||||
| } | ||||||||||
| #score .value { | ||||||||||
| font-size: 24px; | ||||||||||
| font-weight: bold; | ||||||||||
| color: #fff; | ||||||||||
| text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); | ||||||||||
| } | ||||||||||
| #score:hover { | ||||||||||
| transform: translateY(-2px); | ||||||||||
| box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15); | ||||||||||
| } | ||||||||||
| :root[data-theme="dark"] #score { | ||||||||||
| color: #fff; | ||||||||||
| text-shadow: 0 0 3px rgba(0, 0, 0, 0.5); | ||||||||||
| background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05)); | ||||||||||
| } | ||||||||||
| #leaderboard { | ||||||||||
| position: absolute; | ||||||||||
|
|
@@ -206,7 +226,10 @@ | |||||||||
| </head> | ||||||||||
| <body> | ||||||||||
| <canvas id="gameCanvas"></canvas> | ||||||||||
| <div id="score">Score: 0</div> | ||||||||||
| <div id="score"> | ||||||||||
| <div class="label">Score</div> | ||||||||||
| <div class="value">0</div> | ||||||||||
| </div> | ||||||||||
| <div id="leaderboard"> | ||||||||||
| <h3>Leaderboard</h3> | ||||||||||
| <div id="leaderboard-content"></div> | ||||||||||
|
|
@@ -236,9 +259,9 @@ <h3>Actions</h3> | |||||||||
| <div class="control-group"> | ||||||||||
| <h3>Display</h3> | ||||||||||
| <div class="control-item"> | ||||||||||
| <span>Dark Mode</span> | ||||||||||
| <label class="toggle-switch"> | ||||||||||
| <input type="checkbox" id="dark-mode-toggle" onclick="toggleDarkMode()"> | ||||||||||
| <label class="toggle-switch" for="dark-mode-toggle"> | ||||||||||
| <span>Dark Mode</span> | ||||||||||
| <input type="checkbox" id="dark-mode-toggle" onKeyPress="handleDarkModeKeyPress(event)"> | ||||||||||
|
Comment on lines
+263
to
+264
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dark mode toggle checkbox is missing the onclick handler. You've added keyboard support with onKeyPress but removed the click functionality. Consider adding the onclick handler back:
Suggested change
|
||||||||||
| <span class="toggle-slider"></span> | ||||||||||
| </label> | ||||||||||
| </div> | ||||||||||
|
|
@@ -252,9 +275,19 @@ <h3>General</h3> | |||||||||
| </div> | ||||||||||
| </div> | ||||||||||
| <script> | ||||||||||
| function toggleDarkMode() { | ||||||||||
| document.documentElement.setAttribute('data-theme', document.documentElement.getAttribute('data-theme') === 'dark' ? '' : 'dark'); | ||||||||||
| } | ||||||||||
| function handleDarkModeKeyPress(event) { | ||||||||||
| if (event.key === 'Enter' || event.key === ' ') { | ||||||||||
| event.preventDefault(); | ||||||||||
| const checkbox = document.getElementById('dark-mode-toggle'); | ||||||||||
| checkbox.checked = !checkbox.checked; | ||||||||||
| document.documentElement.setAttribute('data-theme', checkbox.checked ? 'dark' : ''); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function toggleDarkMode() { | ||||||||||
| document.documentElement.setAttribute('data-theme', document.documentElement.getAttribute('data-theme') ? '' : 'dark'); | ||||||||||
| } | ||||||||||
| toggleDarkMode(); | ||||||||||
| </script> | ||||||||||
| <script type="module" src="{{ url_for('static', filename='js/game.js') }}"></script> | ||||||||||
| </body> | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minimap dragging implementation only handles mouse events (
mousedown,mousemove,mouseup) but doesn't support touch events. This means the feature won't work on mobile devices. Consider adding touch event support (touchstart,touchmove,touchend) for better cross-platform compatibility.