A real-time raycasting engine (Wolfenstein 3D style) built entirely in Kotlin using Jetpack Compose for Android. Think classic FPS rendered on a modern Android device.

What is Raycasting? Link to heading

Raycasting is a rendering technique used in early 3D games like Wolfenstein 3D, Doom, and Duke Nukem 3D. Instead of full 3D polygons, it casts rays from the player’s view into a 2D grid map to determine wall heights. This creates a pseudo-3D effect that runs efficiently on limited hardware.

The core idea is simple: for each vertical column of pixels on screen, cast a ray from the player’s position. The ray travels until it hits a wall, then draw the wall slice at the appropriate height based on distance. Closer walls are taller, farther walls are shorter.

Technical Stack Link to heading

  • Kotlin - 93.5% of the codebase
  • Jetpack Compose - Full UI framework (no traditional Views)
  • Coroutines - For async rendering and parallel processing
  • Multi-threaded rendering - CPU-optimized with available processor cores

Key Components Link to heading

Raycaster Engine (Raytracer.kt) Link to heading

The heart of the engine. It handles:

  • Cast rays from player position into the map grid
  • Depth buffer for proper sprite rendering
  • Wall textures with distance-based shading
  • Floor and ceiling textures for atmosphere

Sprite System Link to heading

Sprites are 2D images that always face the player (like enemies, weapons). They’re sorted by distance and rendered back-to-front using the depth buffer.

AI Controller Link to heading

The enemy AI uses:

  • Pathfinding - Navigation through the map
  • Line of sight - Detection of player
  • State machine - Patrol, chase, attack behaviors

Map System Link to heading

Maps are defined as 2D arrays where each cell represents a wall type. The engine includes map parsing and A* pathfinding for enemies.

Rendering Pipeline Link to heading

  1. Cast rays for each screen column
  2. Calculate wall height based on distance
  3. Apply texture with distance-based shading
  4. Render floor and ceiling textures
  5. Sort and render sprites back-to-front
  6. Apply post-processing effects (optional)

Performance Link to heading

The engine leverages all available CPU cores for parallel ray calculation. On modern devices, it easily maintains 60 FPS while rendering at device resolution.

Source Code Link to heading

Repository: https://github.com/eziosoft/Raytracer_android_demo

This is a complete game engine demonstrating that classic rendering techniques still work beautifully on modern mobile hardware.