PythonAtSea / topdown

topdown
0 stars 0 forks source link

Sweep: Add a prompt toset the world seed before the game starts using pygame-textinput #11

Closed PythonAtSea closed 1 year ago

PythonAtSea commented 1 year ago

Details

Draw and accept input using pygame.

Checklist - [X] `main.py` > • At the top of the file, add an import statement for the pygame_textinput module. > • In the "Start" menu section, create a new pygame_textinput.TextInput object for the seed input field. > • In the game loop, check for pygame events related to the seed input field and update the input field accordingly. > • Pass the inputted seed to the PerlinNoise function when generating the world.
sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/PythonAtSea/topdown/pull/13.

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 4 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal. To retrigger Sweep 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/PythonAtSea/topdown/blob/4cc334c03602c723a713ecaabcba14657a069063/main.py#L132-L323 https://github.com/PythonAtSea/topdown/blob/4cc334c03602c723a713ecaabcba14657a069063/main.py#L398-L904 https://github.com/PythonAtSea/topdown/blob/4cc334c03602c723a713ecaabcba14657a069063/main.py#L900-L1075 https://github.com/PythonAtSea/topdown/blob/4cc334c03602c723a713ecaabcba14657a069063/main.py#L1-L159 https://github.com/PythonAtSea/topdown/blob/4cc334c03602c723a713ecaabcba14657a069063/main.py#L671-L834

Step 2: 🧐 Snippet Analysis

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

File Path Proposed Changes
main.py Modify main.py with contents:
• At the top of the file, add an import statement for the pygame_textinput module.
• In the "Start" menu section, create a new pygame_textinput.TextInput object for the seed input field.
• In the game loop, check for pygame events related to the seed input field and update the input field accordingly.
• Pass the inputted seed to the PerlinNoise function when generating the world.

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:

Add prompt to set world seed using pygame-textinput sweep/add-seed-prompt

Description

This PR adds a prompt to set the world seed before the game starts using the pygame-textinput module. It allows the user to input a seed value, which will be used for world generation using the PerlinNoise function.

Summary

  • Imported the pygame_textinput module to handle text input in pygame.
  • Created a new input field in the start menu using pygame_textinput.TextInput.
  • Handled user input events and updated the input field accordingly in the game loop.
  • Passed the inputted seed to the PerlinNoise function for world generation.

Please review and merge this PR. Thank you!


Step 4: ⌨️ Coding

File Instructions Progress
main.py Modify main.py with contents:
• At the top of the file, add an import statement for the pygame_textinput module.
• In the "Start" menu section, create a new pygame_textinput.TextInput object for the seed input field.
• In the game loop, check for pygame events related to the seed input field and update the input field accordingly.
• Pass the inputted seed to the PerlinNoise function when generating the world.
✅ Commit 943409d I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/add-seed-prompt.

Here is the 1st review

Hi @PythonAtSea,

Great job on implementing the feature to allow the user to input a seed value for the world generation. However, there is a small issue that needs to be addressed.

In main.py, the SEED value is fetched before the game loop starts, which means the user won't have a chance to input a seed value. The SEED value should be fetched inside the game loop after the user input has been processed.

Here's the change that needs to be made:

  • In main.py, move the lines 848-855 inside the game loop after the user input has been processed.

Keep up the good work!

I finished incorporating these changes.


To recreate the pull request edit the issue title or description. Join Our Discord

PythonAtSea commented 1 year ago

Use pygame-textinput for the rendering of text. Also, if the user inputs a seed less then 0, chose a random seed.