juceGameTools
December 5, 2025 ยท View on GitHub
A collection of C++ classes for building 2D games using the JUCE framework. This toolkit provides fundamental building blocks for managing game objects, creating game worlds with physics and levels, and implementing a flexible camera system.
Core Classes
The project is built around three main classes: GameObject, GameWorld, and CameraDisplay.
GameObject
Header: GameObject.h
The GameObject class is the base element for everything that exists in the game world. It's a versatile class that can represent players, enemies, projectiles, platforms, or trigger zones.
Key Features:
- Physics & Position: Manages properties like position (
x,y), velocity (vx,vy), mass, and acceleration. It supports static objects that are immovable (isStatic) and solid objects that block others (isSolid). - Collision: Provides a bounding box (
getPhysicalBounds()) for collision detection. You can define its shape as aRectangleorEllipse. - Visuals: Can be rendered as a solid
colour, a textdisplayLabel, or a graphicalsprite. The sprite rendering can be configured to stretch or be centered. - Identification: Uses a
tagstring for easy categorization (e.g., "player", "enemy") and acanonicalNamefor a persistent identifier.
GameWorld
Header: GameWorld.h
GameWorld is an abstract class that manages the entire game state, logic, and object interactions. You are expected to create a subclass of GameWorld to define the specific rules and content for your game.
Key Features:
- Object Management: Holds and manages the lifecycle of all
GameObjectinstances in ajuce::OwnedArray. - Game Loop: Features a central
update()method that drives physics calculations and collision detection for all objects. - Level Management: Provides a system for defining and switching between levels via the abstract
setupLevel(int levelIndex)method. It includes helpers for loading, restarting, and advancing levels. - Collision Events: Offers virtual callback methods (
onCollisionEnter,onCollision,onCollisionExit) that you can override in your subclass to implement game logic when objects interact. - Event System: A
Listenerinterface allows other parts of your application (like the UI) to be notified when objects are added or removed from the world. - JUCE Integration: Can be linked to a
juce::AudioProcessorValueTreeStateto synchronize game parameters.
CameraDisplay
Header: CameraDisplay.h
This juce::Component acts as the player's window into the GameWorld. It is responsible for rendering the state of the world to the screen and handles all coordinate transformations.
Key Features:
- World Rendering: Iterates through the
GameObjects in a givenGameWorldand draws them at their correct on-screen positions. - Camera Control: The camera's view can be controlled by setting its position (
cameraX,cameraY) and zoom level (cameraWidth). - Target Following: Can be set to automatically follow a
GameObjector any dynamic point. - Smooth Motion: Implements camera smoothing (
cameraSmoothSpeed) for a more fluid and cinematic feel. - Dead Zone: A configurable "dead zone" prevents minor, jittery camera movements when the target is near the center of the screen.
- Parallax Background: Supports multi-layered scrolling by applying a
parallaxFactorto the background image, creating a sense of depth.
How They Work Together
- You create a concrete class that inherits from
GameWorldand implement its pure virtual methods likesetupLevel()to populate it withGameObjectinstances. - You create an instance of your custom
GameWorld. - You create an instance of
CameraDisplay, passing it a reference to yourGameWorld. - The
CameraDisplaycomponent is added to your UI. - In your main application loop (e.g., a
juce::Timercallback), you callgameWorld.update()to process game logic andcameraDisplay.update()to move the camera and trigger a repaint. - The
CameraDisplay::paint()method then renders all the objects from theGameWorldfrom the camera's perspective.