Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Code Review
This pull request introduces a new web-based game called "Dolphin Butter Splash," including its core logic in JavaScript, HTML structure, and CSS styling. It also updates the main games page to include a link to the new game. Feedback focuses on fixing HTML syntax errors and accessibility attributes in the game card, as well as optimizing the game's rendering and logic by reducing redundant canvas state changes and streamlining array iterations for item updates and collision detection.
| <p>Alge-Blast</p> | ||
| </a> | ||
| <a class="game-card" href="https://houselearning.org/home/assets/dolphingame/index.html"> | ||
| <img src="assets/dolphingame/fishygame.png" alt="Alge-Blast"> |
| </a> | ||
| <a class="game-card" href="https://houselearning.org/home/assets/dolphingame/index.html"> | ||
| <img src="assets/dolphingame/fishygame.png" alt="Alge-Blast"> | ||
| <p>Dolphin Butter</p></p> |
| for (let i = 0; i < 6; i++) { | ||
| ctx.beginPath(); | ||
| ctx.fillStyle = 'rgba(255, 255, 255, 0.35)'; | ||
| const waveY = 30 + i * 90 + Math.sin((state.frame + i * 50) / 30) * 12; | ||
| ctx.ellipse(450, waveY, 260, 22, 0, 0, Math.PI * 2); | ||
| ctx.fill(); | ||
| } |
There was a problem hiding this comment.
The ctx.fillStyle is set to the same value in every iteration of the loop. Moving it outside the loop improves performance by reducing redundant state changes in the canvas context.
| for (let i = 0; i < 6; i++) { | |
| ctx.beginPath(); | |
| ctx.fillStyle = 'rgba(255, 255, 255, 0.35)'; | |
| const waveY = 30 + i * 90 + Math.sin((state.frame + i * 50) / 30) * 12; | |
| ctx.ellipse(450, waveY, 260, 22, 0, 0, Math.PI * 2); | |
| ctx.fill(); | |
| } | |
| ctx.fillStyle = 'rgba(255, 255, 255, 0.35)'; | |
| for (let i = 0; i < 6; i++) { | |
| ctx.beginPath(); | |
| const waveY = 30 + i * 90 + Math.sin((state.frame + i * 50) / 30) * 12; | |
| ctx.ellipse(450, waveY, 260, 22, 0, 0, Math.PI * 2); | |
| ctx.fill(); | |
| } |
| state.rocks.forEach((rock) => { | ||
| const overlap = rock.x < hitbox.x + hitbox.w && rock.x + rock.size > hitbox.x && rock.y < hitbox.y + hitbox.h && rock.y + rock.size > hitbox.y; | ||
| if (overlap) { | ||
| state.gameOver = true; | ||
| } | ||
| }); |
There was a problem hiding this comment.
The collision check for rocks continues even after a collision is detected. Using Array.prototype.some() is more efficient as it will stop iterating as soon as a collision is found.
const collision = state.rocks.some((rock) =>
rock.x < hitbox.x + hitbox.w && rock.x + rock.size > hitbox.x && rock.y < hitbox.y + hitbox.h && rock.y + rock.size > hitbox.y
);
if (collision) state.gameOver = true;| state.butter.forEach((butter) => (butter.x -= butter.speed)); | ||
| state.rocks.forEach((rock) => (rock.x -= rock.speed)); | ||
| state.butter = state.butter.filter((butter) => butter.x + butter.size > -20); | ||
| state.rocks = state.rocks.filter((rock) => rock.x + rock.size > -20); |
There was a problem hiding this comment.
The updateItems function iterates over the butter and rocks arrays twice. These operations can be combined into a single filter pass for each array to improve performance.
| state.butter.forEach((butter) => (butter.x -= butter.speed)); | |
| state.rocks.forEach((rock) => (rock.x -= rock.speed)); | |
| state.butter = state.butter.filter((butter) => butter.x + butter.size > -20); | |
| state.rocks = state.rocks.filter((rock) => rock.x + rock.size > -20); | |
| state.butter = state.butter.filter((butter) => { | |
| butter.x -= butter.speed; | |
| return butter.x + butter.size > -20; | |
| }); | |
| state.rocks = state.rocks.filter((rock) => { | |
| rock.x -= rock.speed; | |
| return rock.x + rock.size > -20; | |
| }); |
Pull Request
Make sure to see the Contributing Guidelines here.
Description
Please include a summary of the changes and the related issue.
Fixes #(issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
Checklist
Additional notes
Add any other context about the pull request here.