DEV Community

Harshil Patel
Harshil Patel

Posted on

Hacktoberfest 3/4. Contributing to ZTM-Quest

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)
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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.

Screenshot

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay