Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Jade 2D Game Engine

A custom 2D game engine built from scratch in Java, featuring a complete Entity Component System (ECS), batch rendering with OpenGL, an integrated Dear ImGui editor interface with docking, JBox2D physics, and scene serialization โ€” developed as a Semester 4 Object-Oriented Programming (OOPS) project at UPES.


โœจ Features

๐Ÿ—๏ธ Engine Core

  • Entity Component System (ECS) โ€” Modular GameObject / Component / Transform architecture
  • Scene Management โ€” LevelEditorScene and LevelScene with hot-swapping support
  • Delta-Time Game Loop โ€” Consistent updates independent of frame rate
  • Singleton Window Management โ€” GLFW-based window with input callbacks

๐ŸŽจ Rendering

  • OpenGL 3.3 Core โ€” Vertex-array based batch rendering pipeline
  • Custom GLSL Shaders โ€” Vertex + Fragment shader with a single-file #type parser
  • Sprite Rendering โ€” Color-based quads with dirty-flag optimization for GPU re-upload
  • Framebuffer Object (FBO) โ€” Off-screen rendering to texture at 1920ร—1080, displayed inside the editor viewport
  • Camera System โ€” Orthographic projection with position-based scrolling

๐Ÿ–ฅ๏ธ Editor (Dear ImGui)

  • Docking Layout โ€” Full-window ImGui dockspace (drag, resize, rearrange panels)
  • Game Viewport โ€” Live FBO texture display with 16:9 aspect ratio preservation
  • Scene Hierarchy โ€” Clickable tree-node list of all GameObjects in the active scene
  • Inspector / Properties Panel โ€” Edit Transform (position, scale, rotation) and SpriteRenderer (color picker, z-index) in real-time
  • Engine Info Panel โ€” Live FPS, frame time, and GameObject count
  • Menu Bar โ€” File (Save/Load Scene, Exit) and GameObject (Create Empty)

โš™๏ธ Physics

  • JBox2D Integration โ€” 2D rigid-body physics world stepping
  • Collider Components โ€” Box2DCollider and CircleCollider
  • RigidBody2D โ€” Dynamic, Static, and Kinematic body types

๐Ÿ’พ Serialization

  • GSON-based save/load of scene data to level.json

๐Ÿ“ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   Main.java                        โ”‚
โ”‚                  (Entry Point)                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚
                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               jade.Window (Singleton)              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚   GLFW   โ”‚  โ”‚  OpenGL  โ”‚  โ”‚   ImGuiLayer     โ”‚ โ”‚
โ”‚  โ”‚  Context  โ”‚  โ”‚ Renderer โ”‚  โ”‚  (Editor UI)     โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ–ผ                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Scene (Active)  โ”‚   โ”‚   Framebuffer    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚   โ”‚   (Off-screen)   โ”‚
โ”‚  โ”‚ GameObject โ”‚  โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚  โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚  โ”‚
โ”‚  โ”‚ โ”‚Compnentโ”‚ โ”‚  โ”‚
โ”‚  โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  Renderer  โ”‚  โ”‚
โ”‚  โ”‚ (Batching) โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ—‚๏ธ Project Structure

Game Engine In Java/
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ images/               # Spritesheets and textures
โ”‚   โ”œโ”€โ”€ shaders/
โ”‚   โ”‚   โ””โ”€โ”€ default.glsl      # Vertex + Fragment shader
โ”‚   โ””โ”€โ”€ sounds/               # Audio assets
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ main/java/
โ”‚       โ”œโ”€โ”€ Main.java              # Entry point
โ”‚       โ”œโ”€โ”€ jade/                  # Core engine package
โ”‚       โ”‚   โ”œโ”€โ”€ Window.java        # GLFW window + game loop
โ”‚       โ”‚   โ”œโ”€โ”€ Camera.java        # Orthographic camera
โ”‚       โ”‚   โ”œโ”€โ”€ GameObject.java    # Entity container
โ”‚       โ”‚   โ”œโ”€โ”€ Component.java     # Base component class
โ”‚       โ”‚   โ”œโ”€โ”€ Transform.java     # Position, scale, rotation
โ”‚       โ”‚   โ”œโ”€โ”€ KeyListener.java   # Keyboard input
โ”‚       โ”‚   โ”œโ”€โ”€ MouseListener.java # Mouse input
โ”‚       โ”‚   โ”œโ”€โ”€ Prefabs.java       # Factory methods
โ”‚       โ”‚   โ””โ”€โ”€ scenes/
โ”‚       โ”‚       โ”œโ”€โ”€ Scene.java              # Abstract scene base
โ”‚       โ”‚       โ”œโ”€โ”€ LevelEditorScene.java   # Editor workspace
โ”‚       โ”‚       โ””โ”€โ”€ LevelScene.java         # Runtime scene
โ”‚       โ”œโ”€โ”€ renderer/              # OpenGL rendering
โ”‚       โ”‚   โ”œโ”€โ”€ Shader.java        # GLSL compiler & uploader
โ”‚       โ”‚   โ”œโ”€โ”€ RenderBatch.java   # Batched sprite renderer
โ”‚       โ”‚   โ”œโ”€โ”€ Renderer.java      # Batch manager
โ”‚       โ”‚   โ”œโ”€โ”€ Framebuffer.java   # FBO for editor viewport
โ”‚       โ”‚   โ””โ”€โ”€ Texture.java       # Texture wrapper
โ”‚       โ”œโ”€โ”€ editor/                # Dear ImGui editor panels
โ”‚       โ”‚   โ”œโ”€โ”€ ImGuiLayer.java         # ImGui lifecycle + dockspace
โ”‚       โ”‚   โ”œโ”€โ”€ GameViewWindow.java     # FBO viewport display
โ”‚       โ”‚   โ”œโ”€โ”€ SceneHierarchyWindow.java # GameObject tree
โ”‚       โ”‚   โ””โ”€โ”€ PropertiesWindow.java   # Inspector panel
โ”‚       โ”œโ”€โ”€ components/            # Game components
โ”‚       โ”‚   โ”œโ”€โ”€ SpriteRenderer.java     # Color quad rendering
โ”‚       โ”‚   โ”œโ”€โ”€ Spritesheet.java        # Sprite atlas parsing
โ”‚       โ”‚   โ”œโ”€โ”€ StateMachine.java       # Animation states
โ”‚       โ”‚   โ”œโ”€โ”€ PlayerController.java   # Player input handler
โ”‚       โ”‚   โ”œโ”€โ”€ Blocks.java             # Block behaviors
โ”‚       โ”‚   โ”œโ”€โ”€ GoombaAI.java           # Enemy AI
โ”‚       โ”‚   โ”œโ”€โ”€ TurtleAI.java           # Enemy AI
โ”‚       โ”‚   โ””โ”€โ”€ ComponentDeserializer.java # GSON type adapter
โ”‚       โ”œโ”€โ”€ physics2d/             # Physics engine
โ”‚       โ”‚   โ”œโ”€โ”€ Physics2D.java          # JBox2D world wrapper
โ”‚       โ”‚   โ”œโ”€โ”€ RaycastInfo.java        # Raycast result data
โ”‚       โ”‚   โ””โ”€โ”€ components/
โ”‚       โ”‚       โ”œโ”€โ”€ RigidBody2D.java    # Physics body
โ”‚       โ”‚       โ”œโ”€โ”€ Box2DCollider.java  # AABB collider
โ”‚       โ”‚       โ””โ”€โ”€ CircleCollider.java # Circle collider
โ”‚       โ””โ”€โ”€ util/                  # Utilities
โ”‚           โ”œโ”€โ”€ Settings.java           # Engine constants
โ”‚           โ”œโ”€โ”€ Time.java               # Time utilities
โ”‚           โ””โ”€โ”€ AssetPool.java          # Resource caching
โ”œโ”€โ”€ pom.xml                    # Maven build config
โ”œโ”€โ”€ build.cmd                  # Build script
โ”œโ”€โ”€ run_jar.bat                # Run script
โ””โ”€โ”€ level.json                 # Saved scene data

๐Ÿš€ Getting Started

Prerequisites

Tool Version Purpose
JDK 17+ Compilation & runtime
Maven 3.9+ (bundled via mvnw.cmd) Dependency management
Windows 10/11 Native ImGui & LWJGL binaries

Build

# Clone the repository
git clone https://github.com/mayankmalik263/Game-Engine-In-Java.git
cd "Game Engine In Java"

# Build the fat JAR (includes all dependencies)
.\mvnw.cmd clean package -DskipTests

Run

# Option 1: Direct Java command
java --enable-native-access=ALL-UNNAMED -jar target\jade-engine-1.0.0-jar-with-dependencies.jar

# Option 2: Use the provided batch script
.\run_jar.bat

Note: The --enable-native-access=ALL-UNNAMED flag prevents JDK 17+ warnings related to LWJGL native library access.


๐Ÿ•น๏ธ Usage

Editor Controls

Action How
Select GameObject Click on a name in the Scene Hierarchy panel
Edit Transform Drag the Position / Scale / Rotation fields in the Inspector
Change Color Click the color swatch in the Inspector under SpriteRenderer
Create New Object Menu Bar โ†’ GameObject โ†’ Create Empty
Save Scene Menu Bar โ†’ File โ†’ Save Scene
Load Scene Menu Bar โ†’ File โ†’ Load Scene
Rearrange Panels Drag any panel tab to dock it anywhere

๐Ÿงฑ OOP Principles Demonstrated

This project serves as a practical demonstration of core Object-Oriented Programming concepts:

Principle Implementation
Encapsulation Window singleton hides GLFW internals; Framebuffer encapsulates OpenGL FBO state
Inheritance Scene โ†’ LevelEditorScene / LevelScene; Component โ†’ SpriteRenderer / RigidBody2D / PlayerController
Polymorphism scene.update(dt) dispatches to the correct scene subclass; component.update(dt) dispatches per-component
Abstraction Component defines a contract (start(), update()); Scene abstracts initialization via init()

๐Ÿ“ฆ Dependencies

Library Version Purpose
LWJGL 3.3.3 OpenGL, GLFW windowing, STB image loading
imgui-java 1.86.11 Dear ImGui bindings for Java (GLFW + GL3 backend)
JOML 1.10.8 Math library (matrices, vectors)
JBox2D 2.2.1.1 2D rigid-body physics simulation
GSON 2.11.0 JSON serialization for scene save/load
JUnit 5 5.11.0 Unit testing framework

๐Ÿงช Testing

# Run the unit test suite
.\mvnw.cmd test

Tests cover core systems including GameObject, Transform, Camera, and Physics2D.


๐Ÿ› ๏ธ Rendering Pipeline

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Game Loop                       โ”‚
โ”‚                                                  โ”‚
โ”‚  1. glfwPollEvents()                            โ”‚
โ”‚                                                  โ”‚
โ”‚  2. โ”Œโ”€โ”€โ”€ PASS 1: Scene โ†’ Framebuffer โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚     โ”‚  framebuffer.bind()                      โ”‚ โ”‚
โ”‚     โ”‚  glClear(COLOR | DEPTH)                  โ”‚ โ”‚
โ”‚     โ”‚  scene.update(dt)                        โ”‚ โ”‚
โ”‚     โ”‚    โ””โ”€ renderer.render(camera)            โ”‚ โ”‚
โ”‚     โ”‚        โ””โ”€ for each RenderBatch:          โ”‚ โ”‚
โ”‚     โ”‚            shader.use()                  โ”‚ โ”‚
โ”‚     โ”‚            upload projection & view      โ”‚ โ”‚
โ”‚     โ”‚            glDrawElements(...)           โ”‚ โ”‚
โ”‚     โ”‚  framebuffer.unbind()                    โ”‚ โ”‚
โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                                  โ”‚
โ”‚  3. โ”Œโ”€โ”€โ”€ PASS 2: ImGui โ†’ Screen โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚     โ”‚  glClear(COLOR)                          โ”‚ โ”‚
โ”‚     โ”‚  imGuiLayer.update(dt, scene, textureId) โ”‚ โ”‚
โ”‚     โ”‚    โ”œโ”€ dockSpaceOverViewport()            โ”‚ โ”‚
โ”‚     โ”‚    โ”œโ”€ GameViewWindow (FBO texture)       โ”‚ โ”‚
โ”‚     โ”‚    โ”œโ”€ SceneHierarchyWindow               โ”‚ โ”‚
โ”‚     โ”‚    โ”œโ”€ PropertiesWindow                   โ”‚ โ”‚
โ”‚     โ”‚    โ””โ”€ Engine Info                        โ”‚ โ”‚
โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                                  โ”‚
โ”‚  4. glfwSwapBuffers()                           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“„ License

This project is developed for educational purposes as part of a university course. Feel free to use it as a learning resource.


๐Ÿ™ Acknowledgments

  • GamesWithGabe โ€” The original tutorial series that inspired this engine's architecture
  • LWJGL โ€” Lightweight Java Game Library
  • Dear ImGui โ€” Immediate-mode GUI library by Omar Cornut
  • SpaiR/imgui-java โ€” Java bindings for Dear ImGui

Built with โ˜• Java | ๐ŸŽ“ UPES Semester 4 OOP Project

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages