Skip to content

Conversation

shashwat030900
Copy link

No description provided.

google-labs-jules bot and others added 30 commits August 16, 2025 10:15
This commit introduces the basic structure for the Level module.

- Creates header files for LevelModel, LevelView, LevelController, LevelService, LevelNumber, and LevelData.
- Creates source files for LevelModel, LevelView, LevelController, and LevelService.
- Adds empty class definitions and lifecycle methods (initialize, update, render) to the relevant files.
- All new code is within the 'Level' namespace.
This commit builds upon the initial Level module structure.

- Implements the LevelService to manage a LevelController instance, including its creation, lifecycle method delegation, and destruction.
- Adds a `createLevel` method to LevelService to set the current level.
- Integrates LevelService into the main ServiceLocator.
- The LevelService is now initialized and cleared along with other services.
- Its `update` and `render` methods are called conditionally based on the `GameState`, ensuring it only runs during active gameplay.
This commit adds a background to the LevelView.

- Adds a `RectangleShapeView` to the `LevelView` to serve as the background.
- The background is initialized to the full size of the game window.
- The background color is set to a light green.
- The `LevelView` now manages the lifecycle of the background rectangle.
This commit enhances the LevelView by adding a border and the logic to calculate the playable grid area.

- Adds a `border_rectangle` to LevelView, which is a transparent rectangle with a black outline.
- Implements `calculateGridExtents` to determine the playable grid's width and height based on border offsets.
- Adds public getters for the grid width and height.
- The lifecycle of the border rectangle is now managed by the LevelView.
This commit introduces the level selection screen, allowing players to choose between different levels before starting the game.

- Adds a new `LevelSelectionUIController` to manage the UI for the level selection screen.
- The screen includes buttons for "Level One", "Level Two", and a "Menu" button to return to the main menu.
- Integrates the new UI controller into the `UIService` to be displayed at the correct game state.
- Updates the main menu's "Play" button to navigate to the new level selection screen.
This commit introduces the complete feature set for Levels and Players.

- Adds a full `Level` module (Model, View, Controller, Service) with logic for grid and view management.
- Adds a full `Player` module (`PlayerService`, `SnakeController`) to handle player logic.
- Integrates both `LevelService` and `PlayerService` into the `ServiceLocator`, with updates conditional on the `GAMEPLAY` state.
- Adds a `LevelSelectionUIController` to provide a UI screen for choosing levels.
- Integrates the new UI screen into `UIService` and updates the Main Menu to navigate to it.
- Connects the `LevelService` to the `PlayerService` to spawn a player when a level is created.
The game was crashing when a level was selected from the menu because there was no implementation for loading level data. This change introduces the necessary logic to define, load, and render game levels.

- Defined a data structure for level layouts in `LevelData.h`.
- Populated `LevelModel` with data for two levels.
- Implemented level loading logic in `LevelModel` and `LevelController`.
- Updated `LevelService` to trigger level loading when a level is selected.
- Updated `LevelView` to render the level layout, including obstacles.
The game was crashing when a level was selected from the menu because there was no implementation for loading level data. This change introduces the necessary logic to define, load, and render game levels.

- Defined a data structure for level layouts in `LevelData.h`.
- Populated `LevelModel` with data for two levels.
- Implemented level loading logic in `LevelModel` and `LevelController`.
- Updated `LevelService` to trigger level loading when a level is selected.
- Updated `LevelView` to render the level layout, including obstacles.
- Added a defensive check in `LevelView` to prevent a crash if the obstacle texture fails to load.
The game was crashing when a level was selected from the menu. This was caused by two issues:
1. A missing implementation for loading and rendering level data.
2. Functions in `Player/BodyPart.cpp` not returning a value on all control paths, leading to undefined behavior when the player is spawned.

This change introduces the necessary logic to define, load, and render game levels, and it fixes the critical warnings in the player logic.

- Defined a data structure for level layouts in `LevelData.h`.
- Populated `LevelModel` with data for two levels.
- Implemented level loading logic in `LevelModel` and `LevelController`.
- Updated `LevelService` to trigger level loading when a level is selected.
- Updated `LevelView` to render the level layout, including obstacles.
- Added a defensive check in `LevelView` to prevent a crash if the obstacle texture fails to load.
- Fixed functions in `Player/BodyPart.cpp` to ensure they return a value on all control paths.
- Addressed various C4244 conversion warnings with explicit `static_cast`s.
The game was crashing on level selection due to multiple issues, including a missing level loading implementation and an uninitialized pointer in the `BodyPart` class.

This commit addresses these issues by:
1.  Implementing the full pipeline for loading and rendering level data, including obstacles.
2.  Ensuring the `level_view` pointer in `BodyPart` is correctly initialized by passing it down from `LevelService`.
3.  Fixing critical build warnings, including functions that did not return a value on all control paths.

Detailed changes:
- Defined a data structure for level layouts in `LevelData.h`.
- Populated `LevelModel` with data for two levels.
- Implemented level loading and rendering logic in the `Level` module.
- Modified `LevelService` and `LevelController` to provide access to the `LevelView`.
- Updated `PlayerService` and `SnakeController` to propagate the `LevelView` pointer during initialization.
- `SingleLinkedList` now accepts the `LevelView` pointer and assigns it to the created `BodyPart`.
- Fixed functions in `Player/BodyPart.cpp` to ensure they return a value on all control paths.
- Addressed various C4244 conversion warnings with explicit `static_cast`s.
This commit resolves a persistent runtime crash that occurred when a level was selected. The crash was caused by a null pointer dereference in the `BodyPart` class, which was attempting to use an uninitialized `level_view` pointer.

The fix involves a significant refactoring of how dependencies are managed:
- The `BodyPart` class now retrieves the `LevelView` directly from the `ServiceLocator` when needed, rather than relying on a pointer passed through multiple layers of the application.
- The previous pointer-passing mechanism has been removed, simplifying the code and making it more robust.

Additionally, this commit includes the full implementation for loading and rendering level layouts, which was missing and was the initial focus of the debugging effort. It also fixes several critical build warnings, including functions that did not return a value on all control paths.

This comprehensive fix should ensure the game is stable and that levels load and render correctly.
Updates the default starting position of the snake to be in the center of the 50x28 grid.
Adjusts the default starting position of the snake to be `{24, 13}` for better visual centering on the 50x28 grid.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant