A learning project built with LibGDX to practice the Entity Component System (ECS) architecture utilizing the Ashley framework
The project simulates the classic bouncing DVD logo screen, incorporating a "health" system that penalizes the logo when it impacts screen boundaries, and dynamically updates a UI health bar.
To keep data separated from logic, this project splits the implementation into pure data buckets (Components) and iterative processors (Systems).
PositionComponent/VelocityComponent: Tracks the 2D coordinates and speed vectors of moving elements.LogoComponent: Holds the texture reference and physical dimensions for rendering the DVD logo.HealthComponent/HealthBarComponent: Monitors the structural health state and maps out the dimensional boundaries for the UI health rendering.
Ashley executes systems sequentially based on registration order. The layout ensures physics and rules process before visual output:
BounceSystem: Evaluates boundary collisions againstWORLD_WIDTHandWORLD_HEIGHT, handling the directional deflection logic.DamageSystem: Checks collision states and decrements health attributes upon boundary contact.DeathSystem: Resolves zero-health states, acting as a reset mechanism that repositions the entity and penalizes its velocity.RenderSystem: Draws the foundational game world layers (the DVD logo texture).HealthBarRenderSystem: Renders user interface elements on top of the world layer, preventing the game world textures from overlapping UI components.
Unlike basic implementations that flag draw states per-entity, the render systems override the core engine update cycle:
- Batch Flushing Minimization:
SpriteBatch.begin()andend()are triggered exactly once per system cycle rather than per-entity. This packages all drawing operations into single draw calls, drastically lowering CPU-to-GPU overhead. - Memory Management: UI assets (like health bar background/foreground panels) utilize low-overhead single-pixel
Pixmaptextures generated and cached natively at startup to eliminate real-time I/O lag.
This project uses Gradle to manage dependencies. The Gradle wrapper is included, so you can run Gradle tasks using gradlew.bat or ./gradlew commands.
- Run the Desktop Application:
./gradlew lwjgl3:run- Build an Executable JAR: (Outputs to lwjgl3/build/libs)
./gradlew lwjgl3:jar- Clean Build Directories:
./gradlew clean