# 🎮 DODOTRIS - Musical Tetris Game

A musical tetris game where dropping tetrominos creates melodies! Each of the 7 tetromino shapes represents a different musical note (C-D-E-F-G-A-B). When a piece locks into place, it plays that note. Create beautiful songs by completing melodies or experiment in random mode with full tetris mechanics including rotation!

**Part of the Suno Music Adventure RPG** - Accessible from the Arcade (🕹️) button. Rewards 100 Suno Credits on completion.

## Features

### 🎮 Game Modes
- **Random Mode**: Endless mode with randomly generated notes
- **Melody Mode**: Play along to predefined songs (Stone, Cat, Twinkle Star, etc.)

### 🎵 Musical Features
- **7 Tetromino Shapes = 7 Notes**:
  - I-piece (line) = C (red)
  - O-piece (square) = D (cyan)
  - T-piece = E (blue)
  - S-piece = F (orange)
  - Z-piece = G (green)
  - J-piece = A (yellow)
  - L-piece = B (purple)
- Notes play when pieces lock into place
- 4 instrument options: Piano, Guitar, Synth, Brass
- Record your performance for playback
- Generate AI covers with Suno integration

### 🎯 Difficulty Levels
- **Easy**: Slower drop speed (1000ms)
- **Medium**: Medium drop speed (700ms)
- **Hard**: Faster drop speed (500ms)

### ✨ Gameplay Features
- **Classic Tetris Mechanics**:
  - 7 tetromino shapes (I, O, T, S, Z, J, L)
  - Rotation with wall kicks (↑/X for clockwise, Z/Ctrl for counterclockwise)
  - Line clearing for score
  - Ghost piece preview (shows where piece will land)
  - Lock delay (300ms grace period)
- Smooth key repeat with DAS (Delayed Auto Shift)
- Real-time HUD with score, pieces placed, and melody progress

## File Structure

```
DODOTRIS/
├── DODOTRIS.js              # Main game orchestrator (520 lines)
├── DODOTRIS.css             # Styling
├── index.js                 # Export
├── README.md                # This file
│
├── components/
│   ├── TetrisCanvas.js      # Game board rendering
│   ├── Block.js             # Individual block with note label
│   ├── HUD.js               # Score and progress display
│   └── CoverDisplay.js      # Suno cover results (copied from FlappyDODO)
│
├── hooks/
│   ├── useGameLoop.js       # 60fps game loop (copied from FlappyDODO)
│   ├── useGameState.js      # State management
│   ├── useTetrisInput.js    # Arrow key controls with DAS
│   └── useAudioRecording.js # Audio capture (copied from FlappyDODO)
│
└── utils/
    ├── constants.js         # Grid config, notes, colors
    ├── gridManager.js       # 2D grid operations
    ├── tetrisPhysics.js     # Piece movement and collision
    ├── melodyMapper.js      # Convert songs to pieces
    ├── audioSynthesis.js    # Note playback (copied from FlappyDODO)
    ├── songLoader.js        # Load melodies (copied from FlappyDODO)
    └── sunoApi.js           # Suno integration (copied from FlappyDODO)
```

## How to Play

### Controls
- **← →** Arrow keys: Move tetromino left and right
- **↑** Arrow key or **X**: Rotate clockwise
- **Z** or **Ctrl**: Rotate counterclockwise
- **↓** Arrow key: Fast drop (10x faster)
- **SPACE**: Hard drop (instant)

### Gameplay
1. Select a melody mode (Random or a song)
2. Choose your instrument sound
3. Pick a difficulty level
4. Use arrow keys to move tetrominos and ↑/X/Z to rotate
5. Each tetromino plays its note when it locks (I=C, O=D, T=E, S=F, Z=G, J=A, L=B)
6. Complete the melody to win (or play endlessly in Random mode)
7. Clear lines for bonus score!

### Melody Mode
- Blocks spawn in sequence according to the song
- Complete all notes to win the game
- Progress bar shows how far along you are

### Random Mode
- Blocks spawn with random notes
- No win condition - play for high score
- Good for experimentation and practice

## Game Physics

- **Drop Speed**: Determined by difficulty (500-1000ms)
- **Lock Delay**: 300ms grace period when piece touches ground
- **DAS**: 170ms initial delay before key repeat starts
- **ARR**: 50ms between key repeats (30ms for down key)

## Scoring

- **Pieces Placed**: Counter for total blocks placed
- **Lines Cleared**: Standard tetris line clearing
- **Melody Progress**: Shows X/Y notes completed (melody mode only)

## Code Reuse from FlappyDODO

DODOTRIS reuses approximately 60% of FlappyDODO's infrastructure:

### Direct Copies
- `utils/audioSynthesis.js` - SYNTH_TYPES, playNote(), etc.
- `utils/songLoader.js` - AVAILABLE_SONGS
- `utils/sunoApi.js` - Suno API integration
- `hooks/useGameLoop.js` - 60fps game loop
- `hooks/useAudioRecording.js` - Recording system
- `components/CoverDisplay.js` - Cover results UI

### New for DODOTRIS
- Grid-based rendering system
- Tetris physics (gravity, collision, locking)
- Keyboard input with DAS/ARR
- Block components with note labels
- Simpler game loop (no continuous scrolling)

## Performance

- Optimized for 60fps gameplay
- Grid-based collision (faster than pixel-perfect)
- Minimal re-renders using React hooks
- Smooth animations with CSS transitions

## Future Enhancements

- [x] Full tetrominos (I, O, T, S, Z, J, L shapes) ✅
- [x] Rotation mechanics with wall kicks ✅
- [ ] Combo system for cascading line clears
- [ ] Background music during gameplay
- [ ] Particle effects on line clear
- [ ] Mobile/touch controls
- [ ] Leaderboards
- [ ] More songs and melodies
- [ ] T-spin detection and scoring

## Differences from FlappyDODO

| Aspect | FlappyDODO | DODOTRIS |
|--------|------------|----------|
| **Gameplay** | Continuous scrolling | Grid-based, turn-based |
| **Input** | Spacebar (timing-based) | Arrow keys (positioning) |
| **Music** | Jump timing → melody | Drop position → melody |
| **Complexity** | 1655 lines | ~520 lines |
| **Win Condition** | Survive time limit | Complete melody |

## Credits

Built with ❤️ for Tony's Dev Tunes hackathon!
Based on FlappyDODO's musical infrastructure.
Inspired by Tetris and musical rhythm games.
