I have already submitted 2 PRs to Chatcraft and WrenAI. This blog post is about my 3rd PR, which I made to ZTM-Quest, a fun 2D top-down RPG where you can explore the world of Zero-to-Mastery (ZTM). I came across ZTM through their Data Structures and Algorithms (DSA) cheat sheet, which has been incredibly helpful in solving LeetCode problems.
The Issue I Worked On
The issue I worked on was to increase the player’s speed based on their current energy level. I started by forking the repo and setting up my local development environment. After exploring the codebase, I located the code that controls the player’s speed:
const speed =
pressed.size === 1
? player.speed
: // Dot product for diagonal movement 45%
player.speed * 0.707106781188095; // 1 / sqrt(2)
Implementing the Speed-Energy Mechanism
The challenge was to adjust the player’s speed according to their energy level. By debugging, I found that the player’s energy level is stored in player.state.energy
. With this information, I updated the code to increase the player’s speed based on their energy level. If the energy is greater than or equal to 50%, the speed increases by 25%. Otherwise, the speed increases by 10%. Here's the updated code:
const speed =
pressed.size === 1
? player.state.energy > 50
? player.speed * 1.25
: player.speed * 1.1
: player.state.energy > 50
? player.speed * 0.707106781188095 * 1.25
: player.speed * 0.707106781188095 * 1.1;
After implementing this, I reached out to the issue author to confirm the logic, and they approved it. With everything set, I submitted a PR for review.
Reflections on the Contribution
Working on ZTM-Quest was a great experience, and I learned a lot about working with game mechanics, especially in handling dynamic properties like player speed. Contributing to an open-source project like this is always rewarding, especially when you see your changes improve the gameplay.
I’m continuing to work on open-source projects and am excited about what’s next! If you're interested in exploring the code or contributing, check out ZTM-Quest.
Top comments (0)