How zunohoang/j2d-engine works
Main Components
a. Main Entry Point:
• Main.java in the src directory is the launcher that likely initializes the engine.
b. Core Engine (src/engine/core):
• Engine.java, GameLoop.java, GameThread.java – Responsible for orchestrating the game loop, threading, and high-level engine execution.
c. Input Handling:
• Classes such as KeyInput.java and MouseInput.java that capture user interactions.
d. Rendering & Graphics:
• Renderer.java and UILayoutParser.java in the graphics package along with classes in src/engine/components (e.g., SpriteRenderer.java, ColorRenderer.java) handling drawing and image layout.
e. Components & Game Objects:
• A rich set of components (Transform, Rigidbody, Collider classes, UI elements, etc.) under src/engine/components; these illustrate a component-based architecture.
• GameObject.java which is a base for in-game objects.
f. Physics & Collision:
• Physics, CollisionManager, PhysicsSystem in src/engine/physics, showing collision detection and physics simulation.
g. Scenes & Scene Management:
• Scene.java and SceneManager.java under src/engine/scenes, and the concrete scenes (GameScene, MenuScene, OfflineScene) under src/game/scenes.
h. Asset & Local Data Handling:
• Assets are stored in the assets directory (images, layouts, and repositories of JSON config data).
• RepositoryService and related classes for loading games’ settings, characters, and game-specific data.
i. Game-specific Logic:
• Under src/game, there are configurations and scripts that define game behavior like NormalAttack.java and PlayerController.java.
Relationships & Interactions
• The Main entry point initializes the Core Engine. The Engine instantiates the Game Loop, which continuously updates and renders the current Scene.
• Input systems (KeyInput/MouseInput) feed events into the Game Loop which interact with the GameObjects via their components.
• Assets (images, layouts) and Repository files (JSON configuration files) are loaded into memory through components in the engine (such as JsonManager and RepositoryService) to provide configuration data to scenes and objects.
• The Renderer interacts with various component renderers (e.g., SpriteRenderer, UI renderers) to organize how objects appear.
• The Physics system is hooked into the update loop, managing collisions (via CollisionManager) and responses (using components like Rigidbody, BoxCollider, and CircleCollider).
• The Scene Manager is responsible for switching between game states (like GameScene, MenuScene, OfflineScene), managing the lifecycle of scenes.
• Game-specific scripts in src/game/scripts are likely attached to game objects within the scenes to define behaviors like normal attacks or player control.
Architectural Patterns & Design Principles
• Component-based architecture: Notice how multiple component classes exist (Transform, SpriteRenderer, Collider types, etc.) to be attached to game objects to define behavior modularly.
• Separation of concerns: Distinct separation between the core engine, rendering subsystem, physics engine, and game-specific logic.
• Use of a game loop and scene management: Centralized update and render cycle that drives the game state.
• Event-driven interactions: Input handling (keyboard/mouse) feeding directly into state changes.
• Data-driven design: The use of JSON repository files and layouts (menu.xml) suggests a degree of dynamic configuration.
a. Main Entry (Main.java) at the top.
b. Layer the Core Engine components just below, showing the flow to and from the Game Loop and Game Thread.
c. Branch out the Engine’s sub-systems:
– Left branch: Rendering & Graphics System, linking to various Renderer and UI components.
– Right branch: Physics & Collision subsystem, depicting Physics, CollisionManager, and associated components.
– Lower branch: Input Handling feeding into both systems.
– Game Scenes (GameScene, MenuScene, OfflineScene)
– Although the engine handles core functions, game-specific behaviors are implemented through scripts and configurations.
e. Off to the side or at the base, show the Asset Management module connecting to the repository JSON files, layout XML file, and assets (images).
f. Finally, include overarching external interactions (if any, such as developer tools, logging via Logger) which feed back into the engine’s monitoring and debugging processes.