Skip to content

unitycoder/3D-Doom-in-Terminal-Game-

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

3D-Doom-in-Terminal-Game-

A Python Game in Terminal with All Deep Research log's and formulas

Screen.Recording.2025-05-27.150625.mp4

A lightweight raycasting engine that runs directly in your terminal!

Inspired by classic games like Doom and Wolfenstein 3D, this project simulates 3D environments using ASCII characters and basic trigonometry.


Game Logic Breakdown (Math-Based)

This project uses fundamental raycasting techniques to simulate a 3D world from a 2D map.

Player

  • Position: P = (px, py)
  • View angle (facing direction): θ in radians

Raycasting Per Column

For each column i on the terminal screen:

1. Field of View

FOV = π / 3 # e.g. 60 degrees field of view ray_angle = θ - (FOV / 2) + (i / screen_width) * FOV

2. Ray Angle

ray_angle = θ - (FOV / 2) + (i / screen_width) * FOV

3. Ray Direction Vector

https://github.com/user-attachments/assets/4cd98917-8033-4464-a7ce-5cff0fca05cc


ray_dir_x = cos(ray_angle)
ray_dir_y = sin(ray_angle)
  • Iterate along the ray in small steps until a wall is hit.

image

4. Ray Marching (DDA Algorithm)

Iteratively step through the map until a wall is hit:

(x, y) = (px, py)

loop:
    x += ray_dir_x * step
    y += ray_dir_y * step
    if map[⌊y⌋][⌊x⌋] == wall:
        break

5. Distance to Wall

distance = sqrt((x - px)² + (y - py)²)

6. Wall Height on Terminal

wall_height = screen_height / distance

7. Shading by Distance

if distance < close:        char = ''
elif distance < medium:     char = ''
elif distance < far:        char = ''
else:                       char = '.'

8. Rotation (Left/Right)

θ += Δθ # positive for right, negative for left

9. Movement (W/S or Up/Down)

px += cos(θ) * move_speed # forward py += sin(θ) * move_speed px -= cos(θ) * move_speed # backward py -= sin(θ) * move_speed

Controls

Key Action
← / → Rotate view (left/right)
↑ / ↓ Move forward/backward
W / S Optional movement keys

Map

The world is a 2D grid:

map = [
    [1,1,1,1,1,1,1],
    [1,0,0,0,0,0,1],
    [1,0,1,0,1,0,1],
    [1,0,1,0,1,0,1],
    [1,0,0,0,0,0,1],
    [1,1,1,1,1,1,1]
]

Where:

  • 1 = Wall
  • 0 = Walkable space

Dependencies

  • Python 3
  • curses (comes with Python for Unix/macOS)
    • Windows: use windows-curses via pip install windows-curses

Credits

Built with ❤️ using:

  • ASCII art rendering
  • Basic trigonometry
  • Classic game engine inspiration

Future Ideas

  • Add monsters or objects
  • Map editor using text input
  • Minimap overlay
  • Save/load map feature

About

A Python Game in Terminal with All Deep Research log's and formulas

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%