Skip to content

2D tile-based game engine with sprite animation and collision detection - Graphics programming project using MLX library

Notifications You must be signed in to change notification settings

cadenegr/so_long

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎮 So Long - Enhanced 2D Game Engine

42 School C MiniLibX

Professional Enhancement of 42 School's So Long Project
Transforming a basic curriculum requirement into a polished, production-ready game engine with advanced features, comprehensive statistics, and professional development tools.


📖 Table of Contents


🎯 Project Overview

So Long Enhanced is a sophisticated 2D tile-based game engine built with C and MiniLibX. Originally developed as part of the 42 School curriculum, this version has been extensively enhanced with professional features including real-time statistics, advanced movement validation, interactive help systems, and comprehensive development tools.

🎨 Game Concept

  • Genre: 2D Top-down Adventure/Puzzle
  • Objective: Navigate through levels, collect all treasures, and reach the exit
  • Graphics: Pixel-art sprites with smooth animations
  • Controls: WASD movement with enhanced feedback systems

✨ Enhanced Features

🎮 Core Gameplay Enhancements

  • Smart Movement Validation: Advanced boundary and collision detection
  • Real-time Statistics: Move counting, timing, and performance analysis
  • Achievement System: Performance ratings and strategic feedback
  • Interactive Help: In-game help system (Press H)
  • Status Display: Real-time game information (Press I or SPACE)

🔧 Technical Improvements

  • Enhanced Error Handling: Comprehensive validation and user feedback
  • Memory Management: Robust cleanup and leak prevention
  • Professional Logging: Detailed debug output and game state tracking
  • Modular Architecture: Clean separation of concerns and maintainable code

🎯 User Experience Features

  • Contextual Hints: Strategic movement suggestions
  • Visual Feedback: Enhanced sprites and smooth rendering
  • Progress Tracking: Collectible counter and efficiency metrics
  • Professional Exit Handling: Graceful shutdown on window close or ESC

🎮 Gameplay

🕹️ Controls

Key Action
W A S D Move player (Up/Left/Down/Right)
H Show interactive help
I / SPACE Display game status
ESC Exit game
X (Window) Close game

🎯 Game Rules

  1. Collect All Items: Gather every collectible (💎) on the map
  2. Reach the Exit: Navigate to the exit (🚪) after collecting all items
  3. Avoid Obstacles: Navigate around walls and barriers
  4. Optimize Performance: Minimize moves for better efficiency ratings

🏆 Performance Metrics

  • Move Counter: Track total moves taken
  • Efficiency Rating: Collectibles per move ratio
  • Time Tracking: Game duration monitoring
  • Achievement Levels: Performance-based ratings (Excellent, Good, Average)

🛠️ Technical Architecture

🏗️ Core Components

Game Engine (src/)

  • main.c: Application entry point and main game loop
  • game_start.c: Game initialization and setup
  • variable_init.c: Game state and structure initialization

Enhanced Movement System (src/movement_helpers.c)

  • Advanced Validation: Boundary checking and collision detection
  • Smart Feedback: Contextual hints and strategic suggestions
  • Performance Tracking: Move counting and efficiency analysis
  • Visual Updates: Smooth sprite rendering and position updates

Statistics Engine (src/game_stats.c)

  • Real-time Metrics: Live performance tracking
  • Achievement System: Performance-based ratings
  • Progress Display: Comprehensive game state information
  • Final Reports: Detailed end-game statistics

Graphics System (src/image_*.c)

  • Sprite Management: Texture loading and rendering
  • Visual Effects: Smooth movement and feedback
  • Memory Optimization: Efficient resource management

🎨 Graphics Pipeline

Map Loading → Sprite Initialization → Game Loop → Real-time Rendering → Cleanup
     ↓              ↓                    ↓              ↓              ↓
Map Validation → Texture Loading → Input Handling → Visual Updates → Memory Free

🧠 Game Logic Flow

Input Detection → Movement Validation → Collectible Check → Map Update → 
Statistics Update → Visual Rendering → Victory Condition → Game End

🚀 Quick Start

📋 Prerequisites

  • GCC Compiler: C compiler with C99 support
  • MiniLibX: Graphics library for 42 projects
  • X11 Development Libraries: For Linux graphics support
  • Make: Build automation tool

Installation

# Clone the repository
git clone https://github.com/cadenegr/so_long.git
cd so_long

# Build the project
make

# Run the game
./so_long_game map11.ber

🗺️ Map Format

Maps are stored in .ber format with the following components:

  • 1: Walls (impassable)
  • 0: Empty space (walkable)
  • P: Player starting position
  • C: Collectibles
  • E: Exit

Example Map Structure:

111111111111
1P0C00000001
100000111001
1C0000000001
111111111E11

🎯 Usage Examples

🎮 Basic Gameplay

# Start game with default map
./so_long_game map11.ber

# During gameplay:
# - Use WASD to move
# - Press H for help
# - Press I for status
# - Collect all items before reaching exit

📊 Development Mode

# Build with debug information
make debug

# Run comprehensive tests
make test

# Launch demo mode
make demo

# View all available commands
make help

🛠️ Development Workflow

# Clean build
make fclean

# Full rebuild
make re

# Development cycle
make && ./so_long_game map11.ber

📊 Development Tools

🔨 Enhanced Makefile Features

The project includes a professional build system with multiple targets:

make help    # Display all available commands with descriptions
make test    # Run comprehensive tests and validation
make demo    # Launch demonstration mode
make debug   # Build with debug symbols and verbose output
make clean   # Remove object files
make fclean  # Complete cleanup (objects + executable)
make re      # Full rebuild (fclean + all)

🎯 Build Targets Overview

Target Description Use Case
all Standard build Production builds
debug Debug build with symbols Development and debugging
test Run test suite Quality assurance
demo Demo mode Presentations and showcases
help Show all commands Quick reference

🔧 Build System

🏗️ Professional Makefile Features

  • Automatic Dependency Detection: Wildcard source file inclusion
  • Modular Compilation: Separate object file generation
  • Library Management: Automatic libft and MiniLibX compilation
  • Cross-platform Support: Linux X11 library linking
  • Development Tools: Comprehensive build targets and help system

📦 Dependencies

  • libft: Custom C library with enhanced functions
  • MiniLibX: Graphics library for sprite rendering
  • X11 Libraries: System graphics support

⚙️ Compilation Flags

  • -Wall -Wextra -Werror: Strict error checking
  • Library Linking: -lft_printf -lmlx -lXext -lX11
  • Include Paths: Custom headers and library includes

📁 Project Structure

so_long/
├── 📁 src/                 # Source code
│   ├── 🎮 main.c           # Application entry point
│   ├── 🎯 game_start.c     # Game initialization
│   ├── 📊 game_stats.c     # Statistics engine
│   ├── 🚀 movement_helpers.c # Enhanced movement system
│   ├── ⌨️ key_press.c       # Input handling
│   ├── 🖼️ image_*.c        # Graphics management
│   ├── 🗺️ map_*.c          # Map processing
│   └── 🔧 utility files    # Support functions
├── 📁 include/             # Header files
│   └── 📋 so_long.h        # Main header with documentation
├── 📁 assets/              # Game assets
│   └── 📁 sprities/        # Sprite textures (XPM format)
├── 📁 libft/               # Custom C library
├── 📁 minilibx-linux/      # Graphics library
├── 📁 obj/                 # Compiled object files
├── 🗺️ map11.ber           # Sample game map
├── 🔨 Makefile             # Enhanced build system
└── 📖 README.md            # This documentation

🧩 Additional Tools

🗺️ Map Generator (my_map_gen.c)

Note: This file is included but not currently integrated into the main build.

Features:

  • Algorithmic Map Generation: Uses recursive pathfinding (similar to Mr. C algorithm)
  • Validation System: Ensures generated maps have valid solutions
  • Customizable Parameters: Configurable obstacles and collectibles
  • Path Verification: Flood-fill algorithm to verify map solvability

Usage Concept:

# Theoretical usage (if integrated):
./map_generator <width> <height> <collectibles> <obstacles>
# Generates: Random map with guaranteed valid path from start to finish

Algorithm Overview:

  1. Grid Generation: Creates bordered map with walls
  2. Random Placement: Adds obstacles and collectibles randomly
  3. Path Validation: Uses recursive flood-fill to verify connectivity
  4. Solution Guarantee: Ensures all collectibles are reachable from start to exit

🏆 Key Achievements

💪 Technical Accomplishments

  • Enhanced Movement System: Advanced validation with user feedback
  • Real-time Statistics: Comprehensive performance tracking
  • Professional Build System: Multiple targets and development tools
  • Robust Error Handling: Graceful failure management
  • Memory Management: Leak-free resource handling
  • Modular Architecture: Clean, maintainable code structure

🎮 Game Design Improvements

  • Interactive Help System: In-game assistance and tutorials
  • Achievement Ratings: Performance-based feedback
  • Strategic Hints: Contextual gameplay suggestions
  • Visual Enhancements: Smooth rendering and feedback
  • Professional UX: Intuitive controls and clear objectives

🔧 Development Tools

  • Comprehensive Makefile: Professional build automation
  • Debug Support: Development-friendly error output
  • Test Integration: Quality assurance workflows
  • Documentation: Thorough code comments and README

📚 Learning Outcomes

🧠 Technical Skills Developed

  • C Programming: Advanced memory management and data structures
  • Graphics Programming: Sprite rendering and game loops
  • Build Systems: Professional Makefile development
  • Software Architecture: Modular design and separation of concerns
  • Performance Optimization: Efficient algorithms and resource management

🎯 Game Development Concepts

  • Game State Management: Complex state tracking and updates
  • Input Handling: Responsive control systems
  • Collision Detection: Boundary checking and validation
  • User Experience Design: Intuitive interfaces and feedback systems
  • Performance Metrics: Analytics and progress tracking

🏗️ Software Engineering Practices

  • Version Control: Git workflow and project management
  • Documentation: Comprehensive README and code comments
  • Testing: Validation and quality assurance
  • Refactoring: Code improvement and optimization
  • Professional Standards: Production-ready code practices

🎉 Conclusion

So Long Enhanced demonstrates the transformation of a basic academic project into a professional-grade game engine. Through systematic enhancement of gameplay mechanics, implementation of comprehensive development tools, and adoption of software engineering best practices, this project showcases advanced C programming skills and game development expertise.

The project serves as both a functional game and a portfolio piece, highlighting capabilities in systems programming, graphics development, and software architecture design.


🎮 Ready to Play? Let's Go!

make && ./so_long_game map11.ber

Built with passion and precision at 42 School 🚀

About

2D tile-based game engine with sprite animation and collision detection - Graphics programming project using MLX library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published