A terminal-based game engine focused on creating visually stunning games using advanced ASCII art rendering techniques. PyTermGame pushes the boundaries of terminal graphics with sophisticated visual effects and animations.
PyTermGame provides a comprehensive set of tools for creating rich ASCII art games in the terminal, including:
- Advanced Sprite Editor - Create and edit multi-layered ASCII sprites with drawing tools
- Animation System - Frame-based animation with onion skinning support
- Layered Rendering - Composite multiple layers with transparency and blend modes
- Particle Effects - Dynamic ASCII particle systems with physics
- Dynamic Lighting - Real-time lighting with shadows and ambient occlusion
- Sprite Compression - Efficient storage for large ASCII artworks
# Install with pip
pip install -e .
# Install development dependencies
pip install -e ".[dev]"from pytermgame.sprites import SpriteEditor, Color
# Create a new sprite editor
editor = SpriteEditor()
# Set drawing color
editor.set_primary_color(Color(r=255, g=0, b=0))
# Draw with various tools
editor.set_tool("rectangle")
editor.draw_with_tool(5, 5, 15, 15)
editor.set_tool("circle")
editor.draw_with_tool(10, 10, 15, 15)
# Add layers
editor.add_layer("Foreground")
editor.set_active_layer(1)
# Export sprite
sprite_data = editor.export_sprite()from pytermgame.animation import Animator
# Create animator
animator = Animator()
animation = animator.create_animation("Walk", width=32, height=32)
# Add frames
for i in range(8):
if i > 0:
animator.add_frame()
# Edit current frame
editor = animator.sprite_editor
if editor:
editor.draw_pixel(10 + i, 10, '*')
# Enable onion skinning
animator.state.onion_skin.enabled = True
# Play preview
animator.play_preview()from pytermgame.rendering import Renderer, RenderLayer
from pytermgame.sprites import Pixel, Color
# Create renderer
renderer = Renderer(width=80, height=25)
# Create layers
background = RenderLayer(name="bg", width=80, height=25, z_order=0)
sprites = RenderLayer(name="sprites", width=80, height=25, z_order=10)
# Add content to layers
for x in range(80):
background.set_pixel(x, 20, Pixel(char='-', color=Color(r=100, g=100, b=100)))
# Add layers to renderer
renderer.add_layer(background)
renderer.add_layer(sprites)
# Render to ANSI string
output = renderer.render_to_string()
print(output)from pytermgame.particles import ParticleSystem, Vector2D
# Create particle system
particles = ParticleSystem(width=100, height=50)
# Create explosion effect
particles.create_explosion(Vector2D(x=50.0, y=25.0))
# Create fire effect
particles.create_fire(Vector2D(x=30.0, y=40.0))
# Update particles
particles.update(0.016) # 60 FPS
# Render particles
particle_layer = particles.render_to_layer()from pytermgame.lighting import LightingProcessor, LightSource, LightType
from pytermgame.particles import Vector2D
# Create lighting processor
lighting = LightingProcessor(width=100, height=50)
# Add light sources
torch = lighting.create_torch_light(Vector2D(x=20.0, y=25.0))
# Set time of day
lighting.set_time_of_day(20.0) # 8 PM
# Calculate lighting
lighting.calculate_lighting()
# Apply to render layer
lit_layer = lighting.apply_lighting_to_layer(sprite_layer)from pytermgame.compression import SpriteCompressor
# Create compressor
compressor = SpriteCompressor()
# Compress sprite
compressed = compressor.compress(sprite)
print(f"Compression ratio: {compressed.compression_stats.compression_ratio:.2f}")
# Save to file
compressor.compress_to_file(sprite, "sprite.ptz")
# Load from file
loaded_sprite = compressor.decompress_from_file("sprite.ptz")- Multiple drawing tools (pencil, brush, line, rectangle, circle, fill)
- Layer support with opacity and blend modes
- Color palette management
- Undo/redo functionality
- Import/export capabilities
- Frame-based animation sequencing
- Onion skinning for smooth animation creation
- Variable frame durations
- Animation sets for organizing multiple animations
- Real-time preview playback
- Efficient layer compositing
- Multiple blend modes (normal, add, multiply, screen)
- Viewport scrolling and clipping
- Effects system (blur, glow)
- ANSI color output
- Physics-based particle movement
- Multiple emitter shapes (point, line, circle, rectangle)
- Predefined effects (explosion, fire, sparkle)
- Particle pooling for performance
- Collision detection
- Multiple light types (point, directional, spot, ambient)
- Real-time shadow casting
- Ambient occlusion approximation
- Day/night cycle simulation
- Light color and intensity control
- Pattern recognition for repeated elements
- Run-length encoding
- Color palette optimization
- Lossless compression
- File I/O support
PyTermGame is designed to meet the following performance targets:
- Render 30+ layers at 30 FPS
- Animate 100+ sprites simultaneously
- Support 500+ particles
- Compress sprites by 70%+
- Maintain smooth scrolling
Run the test suite with:
# Run all tests
pytest
# Run with coverage
pytest --cov=pytermgame
# Run specific test file
pytest tests/test_sprites.py
# Generate JSON report (required)
pytest --json-report --json-report-file=pytest_results.jsonPyTermGame is organized into modular components:
sprites/- Core sprite data structures and editoranimation/- Animation sequencing and frame managementrendering/- Layer compositing and output generationparticles/- Particle physics and effectslighting/- Dynamic lighting calculationscompression/- Sprite data compression
Each module is designed to work independently while integrating seamlessly with the others.
See the examples/ directory for more detailed usage examples:
sprite_editor_demo.py- Interactive sprite creationanimation_demo.py- Creating smooth animationsparticle_demo.py- Particle effects showcaselighting_demo.py- Dynamic lighting examplesgame_scene_demo.py- Complete game scene
Contributions are welcome! Please ensure:
- All tests pass
- Code follows PEP 8 style guidelines
- Type hints are included
- New features include tests
- Documentation is updated
MIT License - see LICENSE file for details
Built with ❤️ for ASCII art enthusiasts and terminal game developers.