Skip to content

Refactor movement#124

Merged
Davidek523 merged 42 commits intomainfrom
Grid-overlay-(103)-numpy
May 29, 2025
Merged

Refactor movement#124
Davidek523 merged 42 commits intomainfrom
Grid-overlay-(103)-numpy

Conversation

@ultimateownsz
Copy link
Collaborator

Pull Request Template

Type of Pull Request

Only check one box per pull request.

  • 🛠️ Code - Changes to the codebase.
  • 🔄 Revert - Reverts a previously merged commit or PR.
  • 📄 Documentation - Updates to documentation files.
  • 🎵 Audio - Changes to audio files.
  • 🎨 Asset - Updates to design or visual assets.

Summary

This PR refactors and improves various components:

  1. GridManager:
  • Overview: The GridManager class has been introduced to handle grid-related operations, such as grid creation, manipulation, and rendering.
  • Functionality: It provides methods to initialize the grid, update grid cells, and manage grid properties. The grid is now more modular, allowing for easier customization and scalability.
  • Documentation: Detailed documentation has been added in GridManagerGuide.md, explaining the class methods, properties, and usage examples.
  1. Pathfinding:
  • Overview: A new PathFinder class has been implemented to handle pathfinding logic using the A* algorithm.
  • Functionality: The PathFinder class includes methods to find the shortest path between two points on the grid, considering obstacles and weights.
  • Documentation: The PathFindingAStar.md file provides an in-depth look at the algorithm, how to set up pathfinding, and examples of usage within the game.
  1. Pixel to Grid Conversion:
  • Overview: Conversion from pixel coordinates to grid coordinates has been streamlined to ensure accurate and efficient transformations.
  • Functionality: Several methods in the GridManager class handle these conversions, taking into account the grid cell size (tile size for now) and offset, and scale.
  • Documentation: The conversion process is detailed in CoordinateConversionsGuide.md, including mathematical formulas and practical examples.
  1. Camera Integration:
  • Overview: The camera now uses offset and scale to provide a cohesive visualization of the grid and game elements.
  • Functionality: The Camera class has been updated to work seamlessly with the GridManager, applying the necessary transformations to ensure the grid and objects are rendered correctly.
  • Documentation: CameraGuide.md explains how the camera offset and scale are calculated, and how they interact with the grid to provide a smooth visual experience.
  1. Extra:
  • Adds two new dependencies in requirements.txt: numpy & pathfinding
  • Adds one new dependency in requirements_dev.txt: hypothesis (property-based unit testing)
  • Changed FPS constant from 60 to 30.
  • Adds fps counter in display.set_caption in game_manager.py.

Related Issues

This PR addresses ongoing movement and grid-related improvements, facilitating better interaction and debugging functionality.
Fixes #90
Closes #103, #104


✅ Checklist:

  • Tested the changes locally.
  • Verified that no breaking changes are introduced.
  • Updated documentation (if applicable).

… over the grid, that the camera moves with it.
…er moves over the grid, that the camera moves with it."

This reverts commit c0315fb.
… over the grid, that the camera moves with it.
…rld coordinates

- Draw the grid and pathfinding visualization correctly aligned with the camera view
- Scale the grid and path visualization according to the camera zoom level
… the player's position (player_center) and the mouse position (mouse_pos) to the grid.draw method. This ensures that the pathfinding algorithm starts from the player's position and updates dynamically based on the mouse click position.

- Grid Rendering: The grid.draw method is called with the player's position and the mouse position, allowing the GridManager class to calculate and render the path from the player's position to the mouse click position.
…ng position

- Removed old code test_grid.py since it was old code made with different use cases.
- Removed deprecated file tile.py, no longer in use, was made to use as a base abstract class to edit tiles, but is no longer needed.

- Added an option to see where your next position will be on with the click of the mouse key.
- Grid is now always shown for the use case of debugging functionality.
- Simplified grid text rendering by caching text surfaces and optimized visible grid calculation based on camera bounds.
- Added dynamic FPS display to the game window title. Minor cleanup and improved grid snapping logic in game state initialization.
…x and add visible radius to grid draw method
…function signatures to include camera parameters
Simplified and modularized the grid rendering code by introducing private helper methods for better readability and maintainability. These methods handle coordinate conversions, grid drawing, pathfinding visualization, and mouse indicator rendering.
Renamed the import path for `PlayerCamera` to reflect the updated file name and removed outdated commented code in the player camera class to improve code clarity and maintainability. No functional changes were made.
Introduced a new `PathFinder` class to encapsulate A* pathfinding functionality. Refactored `grid_manager.py` to use `PathFinder`, improving code structure and removing redundancy. Removed unused pathfinding-related code from `player.py` and streamlined logic for calculating paths.
…properly test the logic of pathfinding. Also removed old code from grid_manager.py related pathfinding.py logic.
Adjust method parameter indentation for consistency and readability. Replaced `assert` statements with exceptions to standardize error handling and improve robustness.
Tests the grid_manager calculations with unit tests

BREAKING CHANGE: Refactor the GridManager to support initialization with either a tmx_map or a grid_matrix, improving flexibility and testability.
commit f183c95
Merge: ef6692f 68b393c
Author: Davidek523 <davidov520@wp.pl>
Date:   Wed May 28 11:07:36 2025 +0200

    Refactor unittest framework (#118)

    # Pull Request Template

    ## Type of Pull Request
    Only check one box per pull request.
    - [x] 🛠️ Code - Changes to the codebase.
    - [ ] 🔄 Revert - Reverts a previously merged commit or PR.
    - [ ] 📄 Documentation - Updates to documentation files.
    - [ ] 🎵 Audio - Changes to audio files.
    - [ ] 🎨 Asset - Updates to design or visual assets.

    ## Summary

    <!--
    INSTRUCTIONS:
    - Briefly describe the purpose of this pull request.
    -->

    This PR <!-- adds|modifies|updates|fixes|reverts --> ... <!-- Briefly
    explain what the PR changes. --> refactors the `unit test` framework
    back to `pytest`, as specified in `requirements_dev.txt`. This change is
    useful as it simplified the creation of unit tests easier and adds
    additional support showing errors during testing.

    The update is also needed, to integrate the
    [Hypothesis](https://hypothesis.readthedocs.io/en/latest/index.html)
    library, which employs property based testing. Useful for testing edge
    cases you haven't thought of. Given the ongoing movement rework,
    associated with issues #103 & #104 which involved libraries such as
    NumPy and Pathfinding, it could be very useful.

    The unit test for the inventory was made by @AnSiChen, I integrated the
    `get_message` module in the unit test as well, this change could be
    better in the future if the inventory gets an overhaul, with mock
    testing for example, or with the use of Hypothesis to handle specific
    edge cases.

    ## Related Issues
    <!--
    INSTRUCTIONS:
    - Mention related issue numbers here.
    - Example: "Fixes #123, Closes #456."
    -->

    This PR <!-- fixes|closes|addresses|reverts --> issue(s) <!-- (e.g.,
    Fixes #123, Closes #456) -->

    ---

    ## ✅ Checklist:

    - [x] Tested the changes locally.
    - [x] Verified that no breaking changes are introduced.
    - [ ] Updated documentation (if applicable).

    ## 🏷️ Labels:
    `type: ...`, `area: ...`, `game-...`, ... <!-- Fill and expand on this
    line as needed. See
    https://github.com/PyCeas/Pyceas/wiki/Guide-to-using-labels for more
    information. -->

commit 68b393c
Author: ultimateownsz <saiutechnologies@outlook.com>
Date:   Mon May 26 00:42:51 2025 +0200

    fix ruff import check

    A long error in the terminal when you ran ruff, has now been fixed:

    `include I` keyword was not found in terminal

    ruff check --select I --fix .

commit dac598d
Author: ultimateownsz <saiutechnologies@outlook.com>
Date:   Thu May 22 22:41:04 2025 +0200

    fix ruff issues

    fix unit test assert

commit c910ef1
Author: ultimateownsz <saiutechnologies@outlook.com>
Date:   Thu May 22 22:31:10 2025 +0200

    Create .gitattributes

    Developers on different OSes won’t accidentally introduce line ending changes, keeping the repository history clean.

commit 2955dc5
Author: ultimateownsz <saiutechnologies@outlook.com>
Date:   Thu May 22 22:24:45 2025 +0200

    Refactor inventory unit tests

    Refactor inventory tests: migrate from unit test to `pytest` and update test structure

    Co-Authored-By: Anthony Em <139152052+AnSiChen@users.noreply.github.com>
This commit introduces three new documentation guides:
- Coordinate Conversions Guide
- Camera Guide
- Grid Manager Guide.
- PathfindingAStar Guide

These guides cover essential concepts like coordinate systems, camera offsets/scales, grid rendering, and interaction handling, providing detailed examples and use cases for game development. proper conversion processes, controls, and edge case handling are also documented.
This fixes some imports, mypy issues.

BREAKING CHANGE: Mypy can complain for some reasons, For Python 3.10+ you need to do this like seen below:

  # PEP 604 syntax, requires Python 3.10+ or `from __future__ import annotations`
  def good(x: int | None = None):
      ...

  https://github.com/hauntsaninja/no_implicit_optional
This change adds the Hypothesis library to `requirements_dev.txt` to support property-based testing. Existing dependencies remain unchanged, ensuring compatibility and functionality.
@ultimateownsz ultimateownsz added type:enhancement For adding new functionality or improving existing code type:bug fix For resolving bugs or issues area:gameplay For mechanics, interactions, or player experience labels May 28, 2025
Copy link
Collaborator

@Davidek523 Davidek523 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The movement is a huge upgrade! It works well! Nice addition in form of a debug button for the grid. The unittest for the grid also works fine. No errors, no crashes nor bugs, approved!

@Davidek523 Davidek523 merged commit 5dbb0c8 into main May 29, 2025
1 check passed
@ultimateownsz ultimateownsz deleted the Grid-overlay-(103)-numpy branch May 29, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gameplay For mechanics, interactions, or player experience type:bug fix For resolving bugs or issues type:enhancement For adding new functionality or improving existing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task 1: [Add a Grid overlay] camera broke ship movement

2 participants

Comments