agenda-shaper / Devast-Server

Attempt to recreate Devast.io server engine
MIT License
3 stars 2 forks source link

in index.js rewrite player movement and collision methods #1

Open agenda-shaper opened 1 year ago

agenda-shaper commented 1 year ago

currently the function is very bad. the player is actually a circle with a radius. rewrite so the collision and other checking is better and a lot faster.

sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/agenda-shaper/Devast-Server/pull/4.

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 3 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal.To get Sweep to recreate this ticket, leave a comment prefixed with "sweep:" or edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/agenda-shaper/Devast-Server/blob/4a334432c6b5cdb3a26963792645521f63392daf/index.js#L1-L1123 https://github.com/agenda-shaper/Devast-Server/blob/4a334432c6b5cdb3a26963792645521f63392daf/arraybuffers/case 9 - crtplayer/uint8array.txt#L1-L149

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
index.js In the movement method of the Player class, remove the code that checks five points for collision. Instead, calculate the new position of the player based on the player's speed and direction, and then check if this new position would result in a collision using the checkCollision method of the GameEngine class. If a collision is detected, set the player's new position to the last valid position before the collision was detected.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Fix player movement and collision detection sweep/fix-player-movement

Description

This PR fixes the player movement and collision detection logic in the game engine. The current implementation checks five points for collision, which is incorrect as the player is represented as a circle. The collision detection has been modified to check only the center point of the player's circle and calculate collisions based on the radius of the circle.

Summary

  • Modified the movement method in the Player class to calculate the new position of the player based on speed and direction.
  • Removed the code that checks five points for collision and replaced it with a single point collision check using the checkCollision method of the GameEngine class.
  • If a collision is detected, the player's new position is set to the last valid position before the collision was detected.

Step 4: ⌨️ Coding

File Instructions Progress
index.js In the movement method of the Player class, remove the code that checks five points for collision. Instead, calculate the new position of the player based on the player's speed and direction, and then check if this new position would result in a collision using the checkCollision method of the GameEngine class. If a collision is detected, set the player's new position to the last valid position before the collision was detected. ✅ Commit 9c76bd9 I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are the my self-reviews of my changes at sweep/fix-player-movement.

Here is the 1st review

Hi there,

Thanks for your contribution. I've reviewed the changes and have some feedback.

The changes made in the index.js file simplify the collision detection logic in the Player class. However, this simplification might lead to inaccurate collision detection if the player's size is larger than a single point.

Here are the specific changes that need to be addressed:

  • In lines 154-186 and 188-220, the collision detection now only checks at the center of the player, rather than at five points (the center and the four corners of a 50x50 box around the player). This could potentially miss some collisions. I would recommend reverting back to the previous logic or finding a different approach that ensures accurate collision detection.

Please let me know if you have any questions or need further clarification.

I finished incorporating these changes.


To recreate the pull request, leave a comment prefixed with "sweep:" or edit the issue. Join Our Discord

agenda-shaper commented 1 year ago

sweep: no idiot i said player IS a CIRCLE not A SQUARE. SO WHEN ITS A CIRCLE THE COLLISION CHECKING SHOULD ONLY BE FROM A SINGLE POINT AND THEN CALCULATE COLLISIONS. CURRENTLY ITS CEHCKING 5 POINTS. THE PLAYER IS A CIRCLE!